{"id":498,"date":"2020-02-14T13:48:00","date_gmt":"2020-02-14T12:48:00","guid":{"rendered":"https:\/\/bierkai.nl\/?page_id=498"},"modified":"2026-09-03T10:04:08","modified_gmt":"2026-09-03T09:04:08","slug":"c-development","status":"publish","type":"page","link":"https:\/\/bierkai.nl\/?page_id=498","title":{"rendered":"C++ development"},"content":{"rendered":"\n\n\n\n<p class=\"wp-block-paragraph\">The ev3dev platform exposes the robot&#8217;s devices through (files in the) <code>\/dev<\/code> filesystem, and devices are controlled by reading from and writing to these files. To save developers the hassle of this raw file access, ev3dev provides <a href=\"https:\/\/www.ev3dev.org\/docs\/programming-languages\/\">language bindings<\/a> that abstract the file operations into neat APIs. The bindings for some languages come pre-installed with ev3dev. Therefore, if you plan to develop applications using an interpreted language such as Python, you&#8217;ll often need little more than a connection between the brick and PC. Prepare your sources on the PC, drop them onto the brick, and execute the program from the brick&#8217;s command line or its on-screen File Browser.<\/p>\n\n\n\n<p class=\"wp-block-paragraph\">The use of compiled languages such as C++ require some more preparation. Denis Demidov&#8217;s <a href=\"https:\/\/github.com\/ddemidov\/ev3dev-lang-cpp\">C++ language bindings for ev3dev<\/a> provide an API to get you started developing C++ programs for your ev3dev-based robot. While the (e.g. GNU) toolchain can be installed onto the brick easily enough, the platform&#8217;s limited hardware makes compilation painfully slow. And the compiler may simply run out of memory once your program gets sufficiently <s>convoluted<\/s> elaborate. Instead you&#8217;ll want to cross compile from your PC, using the brick only to execute the precompiled binary. Demidov also provides instructions on <a href=\"https:\/\/github.com\/ddemidov\/ev3dev-lang-cpp#windows-10\">setting up cross compilation on Windows 10<\/a>. I set up my Windows box as follows:<\/p>\n\n\n\n<ul class=\"wp-block-list\">\n<li>Install the Windows Subsystem for Linux (WSL). I based mine on Ubuntu 22.04.<\/li>\n\n\n\n<li>From a WSL command prompt, using <code>sudo<\/code> or <code>su<\/code> to run with root privileges:\n<ul class=\"wp-block-list\">\n<li>Ensure the list of available packages is up to date by running <code>apt-get update<\/code>.<\/li>\n\n\n\n<li>Install the GNU C++ cross compiler for EV3 by running <code>apt-get install g++-arm-linux-gnueabi<\/code>.<\/li>\n<\/ul>\n<\/li>\n\n\n\n<li>Get the <a href=\"https:\/\/github.com\/ddemidov\/ev3dev-lang-cpp\">C++ language bindings for ev3dev<\/a>, either using <code>git clone<\/code>, or by downloading the sources. You&#8217;ll need at least the <code>ev3dev.h<\/code> and <code>ev3dev.cpp<\/code> files.<\/li>\n<\/ul>\n\n\n\n<p class=\"wp-block-paragraph\">Write a program to control your robot, for example to run one of <a href=\"https:\/\/www.lego.com\/biassets\/bi\/6124045.pdf\">Track3r<\/a>&#8216;s tank treads:<\/p>\n\n\n\n<pre class=\"wp-block-preformatted\">#include &lt;ev3dev.h&gt;\n\nint main()\n{\n  \/\/ Control the large motor connected to port B\n  ev3dev::large_motor m(ev3dev::OUTPUT_B);\n\n  \/\/ Set properties for the next command we'll issue\n  m.set_speed_sp(m.count_per_rot()); \/\/ Run at one rotation per second \n  m.set_time_sp(2000); \/\/ Run for two seconds\n  m.set_stop_action(ev3dev::motor::stop_action_brake); \/\/ Brake when done\n\n  \/\/ Run a command\n  m.set_command(ev3dev::motor::command_run_timed);\n}<\/pre>\n\n\n\n<p class=\"wp-block-paragraph\">When you (cross) compile your program with default settings and run it on the brick, it&#8217;ll (likely) terminate with an error because the binary was linked against a glibc version that&#8217;s newer than the one provided by ev3dev. In my case the program complained that <code>version `GLIBC_2.34' not found<\/code>, and execution of <code>\/lib\/arm-linux-gnueabi\/libc.so.6<\/code> told me that I have the <code>GNU C Library (Debian GLIBC 2.24-11+deb9u4) stable release version 2.24<\/code>. Some options to resolve this are<\/p>\n\n\n\n<ul class=\"wp-block-list\">\n<li><a href=\"https:\/\/stackoverflow.com\/a\/55051234\/5862042\">building against the older glibc version<\/a>, or<\/li>\n\n\n\n<li><a href=\"https:\/\/stackoverflow.com\/a\/14567763\/5862042\">statically linking the newer glibc version<\/a> into your binary, or<\/li>\n\n\n\n<li><a href=\"https:\/\/stackoverflow.com\/a\/5977518\/5862042\">linking specific symbols against older versions<\/a> of the library, or<\/li>\n\n\n\n<li><a href=\"https:\/\/unix.stackexchange.com\/a\/214754\">using a copied newer version<\/a> of the library when running the program on the brick.<\/li>\n<\/ul>\n\n\n\n<p class=\"wp-block-paragraph\">Even though some people on the Interwebs <a href=\"https:\/\/stackoverflow.com\/a\/57478728\">warn against it<\/a>, static linkage of the newer glibc is said to be the easiest, and got rid of the problem for me. So assuming your own source is named <code>main.cpp<\/code> and the language binding&#8217;s sources are in a (sub-)directory named <code>ev3dev-lang-cpp-master<\/code>, build the test program with<\/p>\n\n\n\n<pre class=\"wp-block-preformatted\">arm-linux-gnueabi-g++ -static -I ev3dev-lang-cpp-master ev3dev-lang-cpp-master\/ev3dev.cpp main.cpp -o track3r<\/pre>\n\n\n\n<p class=\"wp-block-paragraph\">The resulting <code>track3r<\/code> program is larger than without static linkage, but it can be executed on the brick. Also it works as intended, running the robot&#8217;s left tank tread for me. Note that the application terminates before the motor is done running.<\/p>\n\n\n\n<p class=\"wp-block-paragraph\"><\/p>\n","protected":false},"excerpt":{"rendered":"<p>The ev3dev platform exposes the robot&#8217;s devices through (files in the) \/dev filesystem, and devices are controlled by reading from&hellip;<\/p>\n","protected":false},"author":1,"featured_media":0,"parent":378,"menu_order":2,"comment_status":"closed","ping_status":"closed","template":"","meta":{"footnotes":""},"class_list":["post-498","page","type-page","status-publish","hentry"],"_links":{"self":[{"href":"https:\/\/bierkai.nl\/index.php?rest_route=\/wp\/v2\/pages\/498","targetHints":{"allow":["GET"]}}],"collection":[{"href":"https:\/\/bierkai.nl\/index.php?rest_route=\/wp\/v2\/pages"}],"about":[{"href":"https:\/\/bierkai.nl\/index.php?rest_route=\/wp\/v2\/types\/page"}],"author":[{"embeddable":true,"href":"https:\/\/bierkai.nl\/index.php?rest_route=\/wp\/v2\/users\/1"}],"replies":[{"embeddable":true,"href":"https:\/\/bierkai.nl\/index.php?rest_route=%2Fwp%2Fv2%2Fcomments&post=498"}],"version-history":[{"count":15,"href":"https:\/\/bierkai.nl\/index.php?rest_route=\/wp\/v2\/pages\/498\/revisions"}],"predecessor-version":[{"id":559,"href":"https:\/\/bierkai.nl\/index.php?rest_route=\/wp\/v2\/pages\/498\/revisions\/559"}],"up":[{"embeddable":true,"href":"https:\/\/bierkai.nl\/index.php?rest_route=\/wp\/v2\/pages\/378"}],"wp:attachment":[{"href":"https:\/\/bierkai.nl\/index.php?rest_route=%2Fwp%2Fv2%2Fmedia&parent=498"}],"curies":[{"name":"wp","href":"https:\/\/api.w.org\/{rel}","templated":true}]}}