Installing and Running EOS on WindowssteemCreated with Sketch.

in eos •  7 years ago  (edited)

If you are a Windows C++ developer and MS Visual Studio is your favorite IDE, you might wonder if it's possible to have the EOS code compiled directly on Windows.

We have made several attempts with Windows C++ compilers, but to no avail. The main problem is that, while the EOS code is branched with the WIN32 flag, unfortunately it's been done inconsistently. Also, Windows Clang compiler behaves differently than its Unix counterpart - it seems to be more restrictive. For example expressions like std::move(u8"env") are invalid in Windows.

However, we've come up with an alternative solution: Windows Subsystem for Linux combined with Visual Studio Code IDE. As you'll see this approach works even better than having the code compiled directly in Windows.

windows10-ubuntu.png

Prerequisites

You need to be running Windows 10, version 1703, also known as the Creators Update. To verify your Windows version open the Settings Panel and then navigate to System > About.

If you have an earlier version of Windows 10 and for some reasons don't want to upgrade to version 1703, you might still be able to give it a try, provided you manage to upgrade your Windows Subsystem for Linux from Ubuntu 14 to Ubuntu 16.

Windows Subsystem for Linux can be only installed on the system drive. If you're running low on your disk space (extra 3-4 GB will be needed), you might want to expand your system partition using tools available here.

Tooling up

First we will enable Windows Subsystem for Linux and then we will access the Bash command line interface from within Visual Studio.

Windows Subsystem for Linux

The official Windows Subsystem for Linux installation guide is to be found here. However, for your convenience, we provide the following simplified procedure:

  1. Open PowerShell in the administrator mode (right-click and choose Run as Administrator) and execute this command:
    Enable-WindowsOptionalFeature -Online -FeatureName Microsoft-Windows-Subsystem-Linux

  2. Restart your computer when prompted.

  3. Turn on the Developer Mode:
    -- Open the Settings Panel and navigate to Update & Security > For developers.
    -- Select the Developer Mode radio button.
    -- If prompted, restart your computer again.

  4. Open Windows command prompt and type bash. After you have accepted the license agreement, a Ubuntu user-mode image will be downloaded and extracted to %localappdata%\lxss\. You will be prompted for setting up a Linux user name and password. When the process is finished, a shortcut named Bash on Ubuntu on Windows will be added to your Start Menu.

  5. Launch a new Ubuntu shell by either:
    -- Typing bash in the command prompt, or
    -- Using the Bash on Ubuntu on Windows shortcut available from the Start Menu.

  6. Once you are inside the Linux shell, make sure you are running Ubuntu 16:
    lsb_release -a

  7. And finally update & upgrade Ubuntu:
    sudo apt update
    sudo apt full-upgrade

Redoing the Ubuntu installation

The following step is optional. Use it only if, for some reasons, you need to start over and redo the Ubuntu installation.

  1. Open Windows command prompt and run:
    lxrun /uninstall /full to uninstall
    lxrun /install to reinstall

  2. Run bash to launch a new Ubuntu shell and inside it run update & upgrade:
    sudo apt update
    sudo apt full-upgrade

Visual Studio Code

Download and install Visual Studio Code from the official website. To enable Ubuntu bash console inside Visual Studio Code you need to modify the User Settings:
-- Navigate to File > Preferences > User Settings.
-- Add the following entry in the right-hand side panel to overwrite the default settings: "terminal.integrated.shell.windows": "C:\\Windows\\sysnative\\bash.exe".
-- After saving the changes, you should be able to toggle the Ubuntu console with Ctrl + ' or View > Integrated Terminal.

Optionally, consider adding C++ extensions to Visual Studio Code, as they can be useful for C++ development. Use Ctrl + Shift + X to open the Extensions Panel and then you might want to add the following extensions:
-- C/C++
-- C++ Intelisense
-- CMakeTools
-- CMake Tools Helper
-- Code Runner

Compile the Source Code

Create a workspace location for EOS on the Windows file system. In this guide we will be using X:\Workspaces\EOS but obviously it's up to you to choose your own location.

On the Linux file system, the above location will be mapped as /mnt/x/Workspaces/EOS. The location you have chosen will be mapped accordingly.

NOTE: use lower case for the name of the drive, in our case it's /mnt/x/.

At this stage you can start using the Ubuntu shell available in Visual Studio Code (View > Integrated Terminal). The main advantage is its support for an easy way to copy-paste commands.

All the following commands are to be run in an Ubuntu shell.

  1. Define the following system variables:
    export WORKSPACE_DIR=/mnt/x/Workspaces/EOS
    export EOSIO_INSTALL_DIR=${WORKSPACE_DIR}/eos
    export EOS_PROGRAMS=${EOSIO_INSTALL_DIR}/build/programs
    export TEMP_DIR=/tmp
    NOTE: make sure to replace x/Workspaces/EOS with the appropriate path that matches the workspace location you have chosen on your computer.

  2. Save the above system variables to the ~/.bashrc file:
    echo "export WORKSPACE_DIR=${WORKSPACE_DIR}" >> ~/.bashrc
    echo "export EOSIO_INSTALL_DIR=${EOSIO_INSTALL_DIR}" >> ~/.bashrc
    echo "export EOS_PROGRAMS=${EOS_PROGRAMS}" >> ~/.bashrc

  3. Install cmake and git:
    sudo apt install cmake
    sudo apt install git

  4. Clone the source code from the EOS repository:
    cd ${WORKSPACE_DIR}
    git clone https://github.com/eosio/eos --recursive

  5. Now you are ready to proceed with the actual compilation of the source code. This step can take several hours, depending on your computer's power, and will require you to intermittently confirm some actions and also to supply the sudo password.
    cd ${EOSIO_INSTALL_DIR}
    ./build.sh ubuntu full
    NOTE: As this process requires downloading a lot of files from various sources, it might fail. In this case just try running this step again.

Run the Executables

If no errors have occurred, you should have the EOS code on your Windows system compiled, resulting with multiple libraries and executables. Executables are placed in the $EOS_PROGRAMS folder:

  • eosd - a server-side blockchain node component,
  • eosc - a command line interface to interact with the blockchain,
  • eos-walletd - an EOS wallet,
  • launcher - an application for network composing and deployment, more information is available here.

At this stage you should be able to run tests described in eos/README.md.

For completeness, let's try if EOS can be started:
cd ${EOS_PROGRAMS}/eosd && ./eosd

At this stage it should exit with an error complaining about the genesis.json file not being defined. In case it does not exit with this error, you can always close it with ctrl + C.

Produce Blocks

Figure out the path for your genesis.json file. In our case it's /mnt/x/Workspaces/EOS/eos/build/genesis.json, yours will probably be different, depending on the workspace location you have chosen.

Edit the config.ini file (in our case it's located here: X:\Workspaces\EOS\eos\build\programs\eosd\data-dir\config.ini) using WordPad (or other text editor of your choice), locate the enable-stale-production entry and make it enable-stale-production = true.

Then append the following content in config.ini:

genesis-json = /mnt/x/Workspaces/EOS/eos/build/genesis.json

producer-name = inita
producer-name = initb
producer-name = initc
producer-name = initd
producer-name = inite
producer-name = initf
producer-name = initg
producer-name = inith
producer-name = initi
producer-name = initj
producer-name = initk
producer-name = initl
producer-name = initm
producer-name = initn
producer-name = initq
producer-name = initr
producer-name = inits
producer-name = initt
producer-name = initu

plugin = eos::producer_plugin
plugin = eos::chain_api_plugin
plugin = eos::wallet_api_plugin
plugin = eos::account_history_api_plugin
plugin = eos::http_plugin 

NOTE: Make sure to set the proper value for the genesis.json path - most probably your path will be different than the one quoted above.

At this stage, when you run eosd again, it should start block production:
cd ${EOS_PROGRAMS}/eosd && ./eosd

This is what you should see in your console if everything works OK:

232901ms thread-0   chain_plugin.cpp:80           plugin_initialize    ] initializing chain plugin
232902ms thread-0   producer_plugin.cpp:159       plugin_initialize    ] Public Key: EOS6MRyAjQq8ud7hVNYcfnVPJqcVpscN5So8BhtHuGYqET5GDW5CV
232903ms thread-0   http_plugin.cpp:132           plugin_initialize    ] host: 127.0.0.1 port: 8888
232905ms thread-0   http_plugin.cpp:135           plugin_initialize    ] configured http to listen on 127.0.0.1:8888
...
232998ms thread-0   producer_plugin.cpp:170       plugin_startup       ] producer plugin:  plugin_startup() begin
232999ms thread-0   producer_plugin.cpp:175       plugin_startup       ] Launching block production for 19 producers.

*******************************
*                             *
*   ------ NEW CHAIN ------   *
*   -   Welcome to EOS!   -   *
*   -----------------------   *
*                             *
*******************************

Your genesis seems to have an old timestamp
Please consider using the --genesis-timestamp option to give your genesis a recent timestamp

233012ms thread-0   producer_plugin.cpp:185       plugin_startup       ] producer plugin:  plugin_startup() end
233012ms thread-0   http_plugin.cpp:147           plugin_startup       ] start processing http thread
...
233059ms thread-0   http_plugin.cpp:224           add_handler          ] add api url: /v1/account_history/get_transaction
233060ms thread-0   http_plugin.cpp:224           add_handler          ] add api url: /v1/account_history/get_transactions
237003ms thread-0   chain_controller.cpp:235      _push_block          ] initq #1 @2017-09-29T16:03:57  | 0 trx, 0 pending, exectime_ms=0
237005ms thread-0   producer_plugin.cpp:233       block_production_loo ] initq generated block #1 @ 2017-09-29T16:03:57 with 0 trxs  0 pending
240003ms thread-0   chain_controller.cpp:235      _push_block          ] initc #2 @2017-09-29T16:04:00  | 0 trx, 0 pending, exectime_ms=0
240004ms thread-0   producer_plugin.cpp:233       block_production_loo ] initc generated block #2 @ 2017-09-29T16:04:00 with 0 trxs  0 pending
243003ms thread-0   chain_controller.cpp:235      _push_block          ] initd #3 @2017-09-29T16:04:03  | 0 trx, 0 pending, exectime_ms=0

NOTE: It might happen that eosd hangs and fails to produce blocks at the first attempt. In this case just exit the process using ctrl + C, then wait a bit and try again.

Update the Source Code

In order to update the source code from the official repository and recompile it, run the following commands:

cd ${EOSIO_INSTALL_DIR}
git pull
rm -r build && mkdir build && cd build
export BOOST_ROOT=${HOME}/opt/boost_1_64_0
cmake -DCMAKE_BUILD_TYPE=Debug \
    -DCMAKE_C_COMPILER=clang-4.0 \
    -DCMAKE_CXX_COMPILER=clang++-4.0 \
    -DWASM_LLVM_CONFIG=${HOME}/opt/wasm/bin/llvm-config \
    -DBINARYEN_BIN=${HOME}/opt/binaryen/bin \
    -DOPENSSL_ROOT_DIR=/usr/local/opt/openssl \
    -DOPENSSL_LIBRARIES=/usr/local/opt/openssl/lib \
    ../ && make

Please refer to the official build guide and/or this list if you need EOS build guides for operating systems other than Windows (i.e. MacOS and Linux).

Authors get paid when people like you upvote their post.
If you enjoyed what you read here, create your account today and start earning FREE STEEM!
Sort Order:  

Very informative, thanks

Thank you for posting @tokenika.

It seems information regarding the EOS project is hard to come by....this is very good news.

Appreciate hearing of it at Steemit first.

Welcome to Steemit.

  ·  7 years ago Reveal Comment

Is there a c# version also? Otherwise time to polish my c++

As far as we know there are no plans to port EOS to C#.

However if you just want to write smart-contracts, in the future you will be able to do it in C# or Java, as Web Assembly (i.e. EOS virtual machine for smart-contracts) will eventually support those higher-level languages. For now it's just C/C++ and soon Rust.

Thanks for your help

TIL the Windows Subsystem for Linux is a Linux subsystem for Windows.

Wow, I thought it would be much easier

Wow, this is really nice, thanks. And there I was doing everything in VirtualBox ...

Excellent work! you deserve appreciation. Very interesting!

Does ubuntu need to be installed before doing this?

Ubuntu VM is part of Windows 10 and both systems share the same resources (e.g. the file system). You access your Ubuntu on Windows via a command prompt, pretty much similar to DOS command prompt.

And to answer your question: you need to activate this feature on Windows and then run a quick installation procedure to set it up - the whole thing takes less than 5 minutes.

Thanks very much! Setting this up today! Your post has saved me a bunch of hassle setting up dual booting ubuntu, thank you!!!

your efforts to make the world more advanced, you deserve appreciation from the world, thank you for the knowledge and the ease you share hopefully useful for all.

Is it fast on windows?

It works as smoothly as on Linux.

Please note that it actually runs on a Linux VM which is embedded in Windows 10. The point is you can work with the code (e.g. debug it) as if it was running natively on Windows.

Hi! I am a Shakel. I just upvoted you!
Found your post interesting to read. I cant wait to see your post soon. Good Luck for the upcoming update.This article is really very interesting and effective.

Congratulations! Great job.
EOS team should think more about dev community, because the competition doesn't sleep (see NEM road show across Europe to look for developers). The blockchain that attracts more developers and have more applications will become more popular and eventually - will win.

I agree. Perhaps they could consider creating a support program or fund to help developers get there apps rolling. Advisor, mentors, funding etc. They have raised enough money to do it.

What is the benefit of this?

The main benefit is that C++ developers using Windows can participate in EOS development without going into the trouble of switching back and forth between two operating systems.

Thanks

Hi tokenika, fantastic post thanks for sharing, will try defiantly try this setup. I've been meaning to try running Ubuntu on Windows 10, since watching this video last year.

amazing, do you think that EOS is better than linux ?

When I add the following entry in the right-hand side panel to overwrite the default settings: "terminal.integrated.shell.windows": "C:\Windows\sysnative\bash.exe" it says Code language not supported or defined.
what do?

awesome

This is just awesome.
Thanks for sharing such an informative post.
It was really helpful.

Thanks for the guide. But at the point when i want to run eosiod it can't produce blocks. Instead i get this error over and over:

3504000ms thread-0 producer_plugin.cpp:227 block_production_loo ] Not producing block because it isn't my turn, its eosio

Any idea how to fix this?

Got it working. At the time of my writing the master branch was in heavy development and should not be used for experimentation. Changing the branch with

Git checkout dawn-2.x

Before building solved the problem. And also check the correct executable is run. Eosd was renamed to eosiod.

nice post

Welcome development is there version for android operating system

I've always been a fan of operating systems other than windoze.... I have tried many is bootable systems, it's fun to experiment

nice tuto :) thanks

This all seemed to me like latin because am not so into programming,,,but it certainly looks good,,, keep the good work up

jajajajaja... this is great!!.. go my vote

Wow!! Very informative post.
I think I'll give it a try :)

Now I'm wishing that I had followed in my older brothers footsteps and became a professional programmer!

Congratulations, your post received one of the top 10 most powerful upvotes in the last 12 hours. You received an upvote from @dan valued at 230.01 SBD, based on the pending payout at the time the data was extracted.

If you do not wish to receive these messages in future, reply with the word "stop".

Awesome tutorial.
Thank you for sharing, now is time to do the homework :)

Hey! Thanks for this post! I used the first part of the instruction in order to run EOS software on Windows. Now I want to create an image with the Docker but I can't connect. Any ideas?

Muy buena aportación sobre linux

Great post. I'm Following. Please follow me..

This article is really inetesting. Will look into it right away.

cool ..

How are you friends steemit hopefully still given the security and health.
And hopefully your days are fun, with your latest posts, which give a lot of inspiration and benefit to the loyal readers of Steemit.

@tokenika your many great posts. This is a very interesting and useful post, so it is my heart's intention to read and see in detail the posts you share. I voted and followed you.

Congratulations @tokenika! You have completed some achievement on Steemit and have been rewarded with new badge(s) :

Award for the number of upvotes received

Click on any badge to view your own Board of Honor on SteemitBoard.
For more information about SteemitBoard, click here

If you no longer want to receive notifications, reply to this comment with the word STOP

By upvoting this notification, you can help all Steemit users. Learn how here!

It is new experience for the steemit.i appreciate you.

Does ubunto is difficult to install ?

If you are on Windows 10 and want to take advantage of Windows Subsystem for Linux, it's very easy: it takes less than 5 minutes and it's just a matter of running one command in the command-line interface.

this great

Congratulations @tokenika!
Your post was mentioned in the hit parade in the following category:

  • Pending payout - Ranked 2 with $ 307,71

Very good

The eosd folder has now been renamed nodeos so instead of running this command:

cd ${EOS_PROGRAMS}/eosd && ./eosd

If you run this one: cd ${EOS_PROGRAMS}/nodeos && ./nodeos -e -p eosio --plugin eosio::wallet_api_plugin --plugin eosio::chain_api_plugin --plugin eosio::account_history_api_plugin

It will run and create the block producers too.

I am a C# developer and MS Visual Studio is my favorite IDE.. I like your posts and helpful too..

im thinking about how to install windows if your using ubuntu. thats the hardest part i know for sure.

looks like the opposite you can install Ubuntu to windows OS your tutorial is you can install Windows 10 into Ubuntu OS wow thats great @tokenika great job like it

Great to see linux powered windows for nobel cause. Thanks @tokenika

I am glad to heard that only from steemit first...i see the future is here

my favorite OS is windows cause i think it's very easy to used hehe @tokenika

Very good ;)

Follow me

Check this new solution, it works in Visual Studio/Windows, to devellop EOS dapps:
https://steemit.com/eos/@mmcs/building-eos-with-visual-studio-2017-for-windows-10

Thanks for the great article! @tokenika

Great post upvoted by @gregwarma22 :)

i got bann friend i dont know why :((

all information needed for us.