{"id":327,"date":"2015-02-26T22:38:55","date_gmt":"2015-02-27T01:38:55","guid":{"rendered":"http:\/\/www.samontab.com\/web\/?p=327"},"modified":"2015-03-01T05:21:40","modified_gmt":"2015-03-01T08:21:40","slug":"cross-platform-development-for-intel-edison-using-cmake-and-qt-creator32-and-64-bits","status":"publish","type":"post","link":"https:\/\/www.samontab.com\/web\/2015\/02\/cross-platform-development-for-intel-edison-using-cmake-and-qt-creator32-and-64-bits\/","title":{"rendered":"Cross Platform Development for Intel Edison using CMake and Qt Creator(32 and 64 bits)"},"content":{"rendered":"<p>The Intel Edison is an amazing little device, but the current SDK only works out of the box with Eclipse, and creating new projects is not very easy.<br \/>\nIn this post, I will show you how to use <strong>CMake<\/strong> and <strong>Qt Creator<\/strong> to develop for the Intel Edison remotely. This allows you to use the power of CMake to create new projects, and the convenience of Qt Creator, a great cross platform IDE for C\/C++.<br \/>\nThis guide should work for all major platforms (Windows, Mac, Linux, 32 and 64 bits) with little or no changes at all.<\/p>\n<p>Here you can see a Windows machine running a debugging session with the Edison using Qt Creator:<\/p>\n<p><a href=\"http:\/\/www.samontab.com\/web\/2015\/02\/cross-platform-development-for-intel-edison-using-cmake-and-qt-creator32-and-64-bits\/debug\/\" rel=\"attachment wp-att-348\"><img loading=\"lazy\" decoding=\"async\" class=\"alignnone wp-image-348\" src=\"http:\/\/www.samontab.com\/web\/wp-content\/uploads\/2015\/02\/debug.png\" alt=\"debug\" width=\"500\" height=\"362\" srcset=\"https:\/\/www.samontab.com\/web\/wp-content\/uploads\/2015\/02\/debug.png 1030w, https:\/\/www.samontab.com\/web\/wp-content\/uploads\/2015\/02\/debug-300x217.png 300w, https:\/\/www.samontab.com\/web\/wp-content\/uploads\/2015\/02\/debug-1024x741.png 1024w\" sizes=\"auto, (max-width: 500px) 100vw, 500px\" \/><\/a><\/p>\n<h2>Required software<\/h2>\n<ul>\n<li>First of all, make sure that you have everything installed for your system to communicate with the Edison. The guys at SparkFun already covered this <a href=\"https:\/\/learn.sparkfun.com\/tutorials\/edison-getting-started-guide\">here<\/a>.<\/li>\n<li>Also, make sure that you have <a href=\"http:\/\/www.qt.io\/download-open-source\/\">Qt Creator<\/a> and <a href=\"http:\/\/www.cmake.org\/download\/\">CMake<\/a> installed as well. Note that we are only using the Qt Creator IDE, so you don&#8217;t need to install the entire Qt SDK if you are not going to use it in your application.<\/li>\n<\/ul>\n<h2>Cross compiling<\/h2>\n<p>We are going to cross compile for the Edison. This means that we are going to build an executable (or library) for a target OS that is different from the host OS. In this case, the target OS is the Edison&#8217;s Yocto Linux and the host OS is the OS that you are running (Windows, Linux, Mac, 32 or 64 bits). Cross compiling means that the host OS compiles something for the target OS. Easy. In order to do this, you will need to have a set of applications for your host OS that allow you to compile for the target OS, as well as the libraries and include files of the target system. These things as a whole are called a toolchain.<\/p>\n<h2>The toolchain<\/h2>\n<p>Intel provides this toolchain for all the major OS on the main downloads site. <a href=\"http:\/\/www.intel.com\/support\/edison\/sb\/CS-035180.htm\">Download<\/a> the one for your OS under the section <strong>SDK Cross compile tools<\/strong>.<\/p>\n<p>For Linux, just install it under the default directory:<\/p>\n<pre class=\"brush: plain; title: ; notranslate\" title=\"\">\/opt\/poky-edison\/1.6.1<\/pre>\n<p>For Windows, decompress the files (twice) and save them under <strong>C:\/Edison<\/strong>.<\/p>\n<p>You will end up with this directory structure for the 64 bits SDK:<\/p>\n<pre class=\"brush: plain; title: ; notranslate\" title=\"\">C:\/Edison\/poky-edison-eglibc-x86_64-edison-image-core2-32-toolchain-1.6.1<\/pre>\n<p>And this directory structure for the 32 bits SDK:<\/p>\n<pre class=\"brush: plain; title: ; notranslate\" title=\"\">C:\/Edison\/poky-edison-eglibc-i686-edison-image-core2-32-toolchain-1.6.1<\/pre>\n<p>Note that <strong>these locations are important<\/strong> because they will be referred to in the Qt Creator configuration and in the CMake script.<\/p>\n<h3>Make under Windows<\/h3>\n<p>There is a utility that was not included in the toolchain, a Make generator. The Eclipse version of the SDK uses an Eclipse internal tool to do the Make step. Since we are not using Eclipse, we will provide our own make generator tool. <strong>MinGW64<\/strong> will help us here. It is a &#8220;Minimalist GNU for Windows&#8221;. Just <a href=\"http:\/\/sourceforge.net\/projects\/mingw-w64\/\">download<\/a> and install it in the default directory. Take a note of the installation directory because it is referred to in the CMake script, and it will probably change in future releases of MinGW64.<\/p>\n<h2>Qt Creator configuration<\/h2>\n<p>We are going to define a new device for development on Qt.<br \/>\nOpen Qt Creator. Go to <strong>Tools-&gt;Options<\/strong>. On the left side, select <strong>Devices<\/strong>.<\/p>\n<p><a href=\"http:\/\/www.samontab.com\/web\/2015\/02\/cross-platform-development-for-intel-edison-using-cmake-and-qt-creator32-and-64-bits\/1_devices-2\/\" rel=\"attachment wp-att-332\"><img loading=\"lazy\" decoding=\"async\" class=\"alignnone wp-image-332\" src=\"http:\/\/www.samontab.com\/web\/wp-content\/uploads\/2015\/02\/1_devices1.png\" alt=\"1_devices\" width=\"500\" height=\"289\" srcset=\"https:\/\/www.samontab.com\/web\/wp-content\/uploads\/2015\/02\/1_devices1.png 1000w, https:\/\/www.samontab.com\/web\/wp-content\/uploads\/2015\/02\/1_devices1-300x173.png 300w\" sizes=\"auto, (max-width: 500px) 100vw, 500px\" \/><\/a><\/p>\n<p>Click on <strong>Add<\/strong>, and select <strong>Generic Linux Device<\/strong>. Click on <strong>Start Wizard<\/strong>.<\/p>\n<p><a href=\"http:\/\/www.samontab.com\/web\/2015\/02\/cross-platform-development-for-intel-edison-using-cmake-and-qt-creator32-and-64-bits\/2_startwizrd-2\/\" rel=\"attachment wp-att-333\"><img loading=\"lazy\" decoding=\"async\" class=\"alignnone size-full wp-image-333\" src=\"http:\/\/www.samontab.com\/web\/wp-content\/uploads\/2015\/02\/2_StartWizrd1.png\" alt=\"2_StartWizrd\" width=\"414\" height=\"359\" srcset=\"https:\/\/www.samontab.com\/web\/wp-content\/uploads\/2015\/02\/2_StartWizrd1.png 414w, https:\/\/www.samontab.com\/web\/wp-content\/uploads\/2015\/02\/2_StartWizrd1-300x260.png 300w\" sizes=\"auto, (max-width: 414px) 100vw, 414px\" \/><\/a><br \/>\nSet the name as Edison, or any name that you want here, the IP address of the Edison (something that may look like 192.168.1.42 for example), <strong>root<\/strong> as the username, and your current password. Click <strong>next<\/strong> when done.<\/p>\n<p><a href=\"http:\/\/www.samontab.com\/web\/2015\/02\/cross-platform-development-for-intel-edison-using-cmake-and-qt-creator32-and-64-bits\/3_newdevicewizard-2\/\" rel=\"attachment wp-att-334\"><img loading=\"lazy\" decoding=\"async\" class=\"alignnone wp-image-334\" src=\"http:\/\/www.samontab.com\/web\/wp-content\/uploads\/2015\/02\/3_newDeviceWizard1.png\" alt=\"3_newDeviceWizard\" width=\"501\" height=\"250\" srcset=\"https:\/\/www.samontab.com\/web\/wp-content\/uploads\/2015\/02\/3_newDeviceWizard1.png 777w, https:\/\/www.samontab.com\/web\/wp-content\/uploads\/2015\/02\/3_newDeviceWizard1-300x150.png 300w\" sizes=\"auto, (max-width: 501px) 100vw, 501px\" \/><\/a><\/p>\n<p>&nbsp;<\/p>\n<p>The device will then be tested for connectivity, and everything should be fine. If there is any problem, edit the settings and try again.<\/p>\n<p><a href=\"http:\/\/www.samontab.com\/web\/2015\/02\/cross-platform-development-for-intel-edison-using-cmake-and-qt-creator32-and-64-bits\/connectiontest\/\" rel=\"attachment wp-att-344\"><img loading=\"lazy\" decoding=\"async\" class=\"alignnone wp-image-344\" src=\"http:\/\/www.samontab.com\/web\/wp-content\/uploads\/2015\/02\/connectionTest.png\" alt=\"connectionTest\" width=\"500\" height=\"506\" srcset=\"https:\/\/www.samontab.com\/web\/wp-content\/uploads\/2015\/02\/connectionTest.png 629w, https:\/\/www.samontab.com\/web\/wp-content\/uploads\/2015\/02\/connectionTest-297x300.png 297w\" sizes=\"auto, (max-width: 500px) 100vw, 500px\" \/><\/a><\/p>\n<p>Now we are going to create a Qt kit to use with this device. Go to <strong>Build &amp; Run<\/strong> and select the <strong>Compilers<\/strong> tab.<\/p>\n<p><a href=\"http:\/\/www.samontab.com\/web\/2015\/02\/cross-platform-development-for-intel-edison-using-cmake-and-qt-creator32-and-64-bits\/5_compilers\/\" rel=\"attachment wp-att-335\"><img loading=\"lazy\" decoding=\"async\" class=\"alignnone wp-image-335\" src=\"http:\/\/www.samontab.com\/web\/wp-content\/uploads\/2015\/02\/5_compilers.png\" alt=\"5_compilers\" width=\"500\" height=\"289\" srcset=\"https:\/\/www.samontab.com\/web\/wp-content\/uploads\/2015\/02\/5_compilers.png 1000w, https:\/\/www.samontab.com\/web\/wp-content\/uploads\/2015\/02\/5_compilers-300x173.png 300w\" sizes=\"auto, (max-width: 500px) 100vw, 500px\" \/><\/a><\/p>\n<p>Once you are there, and select <strong>Add-&gt;GCC<\/strong>. Under <strong>Name<\/strong>, you can change it to anything you want. Under <strong>compiler path<\/strong>, you have to select the C++ compiler for your host OS. These are specified in the CMake script, but I will put them here as well for reference, but always make sure to double check your actual path:<\/p>\n<p>Windows hosts(64 bits):<\/p>\n<pre class=\"brush: plain; title: ; notranslate\" title=\"\">C:\/Edison\/poky-edison-eglibc-x86_64-edison-image-core2-32-toolchain-1.6.1\/sysroots\/x86_64-pokysdk-mingw32\/usr\/bin\/i586-poky-linux\/i586-poky-linux-g++.exe<\/pre>\n<p>Windows hosts(32 bits):<\/p>\n<pre class=\"brush: plain; title: ; notranslate\" title=\"\">C:\/Edison\/poky-edison-eglibc-i686-edison-image-core2-32-toolchain-1.6.1\/sysroots\/i686-pokysdk-mingw32\/usr\/bin\/i586-poky-linux\/i586-poky-linux-g++.exe<\/pre>\n<p>Linux hosts (64 bits):<\/p>\n<pre class=\"brush: plain; title: ; notranslate\" title=\"\">\/opt\/poky-edison\/1.6.1\/sysroots\/x86_64-pokysdk-linux\/usr\/bin\/i586-poky-linux\/i586-poky-linux-g++<\/pre>\n<p>Linux hosts (32 bits):<\/p>\n<pre class=\"brush: plain; title: ; notranslate\" title=\"\">\/opt\/poky-edison\/1.6.1\/sysroots\/i686-pokysdk-linux\/usr\/bin\/i586-poky-linux\/i586-poky-linux-g++<\/pre>\n<p>&nbsp;<\/p>\n<p><a href=\"http:\/\/www.samontab.com\/web\/2015\/02\/cross-platform-development-for-intel-edison-using-cmake-and-qt-creator32-and-64-bits\/6_compilerexecutable\/\" rel=\"attachment wp-att-336\"><img loading=\"lazy\" decoding=\"async\" class=\"alignnone wp-image-336\" src=\"http:\/\/www.samontab.com\/web\/wp-content\/uploads\/2015\/02\/6_compilerExecutable.png\" alt=\"6_compilerExecutable\" width=\"500\" height=\"289\" srcset=\"https:\/\/www.samontab.com\/web\/wp-content\/uploads\/2015\/02\/6_compilerExecutable.png 1000w, https:\/\/www.samontab.com\/web\/wp-content\/uploads\/2015\/02\/6_compilerExecutable-300x173.png 300w\" sizes=\"auto, (max-width: 500px) 100vw, 500px\" \/><\/a><\/p>\n<p>Now go to the <strong>cmake<\/strong> tab and make sure that you have the cmake executable listed there.<\/p>\n<p><a href=\"http:\/\/www.samontab.com\/web\/2015\/02\/cross-platform-development-for-intel-edison-using-cmake-and-qt-creator32-and-64-bits\/8_cmake\/\" rel=\"attachment wp-att-338\"><img loading=\"lazy\" decoding=\"async\" class=\"alignnone wp-image-338\" src=\"http:\/\/www.samontab.com\/web\/wp-content\/uploads\/2015\/02\/8_cmake.png\" alt=\"8_cmake\" width=\"500\" height=\"289\" srcset=\"https:\/\/www.samontab.com\/web\/wp-content\/uploads\/2015\/02\/8_cmake.png 1000w, https:\/\/www.samontab.com\/web\/wp-content\/uploads\/2015\/02\/8_cmake-300x173.png 300w\" sizes=\"auto, (max-width: 500px) 100vw, 500px\" \/><\/a><\/p>\n<p>Let&#8217;s add debugging capabilities. Go to the <strong>Debuggers<\/strong> tab and click on <strong>Add<\/strong>. Under <strong>Path<\/strong>, select the path to your <strong>gdb<\/strong> executable (This is part of the previously installed Mingw64 if you are on Windows, or just gdb if you are on Linux). You can change the name if you want.<\/p>\n<p><a href=\"http:\/\/www.samontab.com\/web\/2015\/02\/cross-platform-development-for-intel-edison-using-cmake-and-qt-creator32-and-64-bits\/debugconfig\/\" rel=\"attachment wp-att-346\"><img loading=\"lazy\" decoding=\"async\" class=\"alignnone wp-image-346\" src=\"http:\/\/www.samontab.com\/web\/wp-content\/uploads\/2015\/02\/debugConfig.png\" alt=\"debugConfig\" width=\"499\" height=\"296\" srcset=\"https:\/\/www.samontab.com\/web\/wp-content\/uploads\/2015\/02\/debugConfig.png 1022w, https:\/\/www.samontab.com\/web\/wp-content\/uploads\/2015\/02\/debugConfig-300x178.png 300w\" sizes=\"auto, (max-width: 499px) 100vw, 499px\" \/><\/a><\/p>\n<p>Now we are ready to define a Qt Kit. Click on the <strong>Kits<\/strong> tab and click on <strong>Add<\/strong>.<\/p>\n<p>Here you will set all the values that you created previously. Under <strong>Name<\/strong> you can put Edison or anything you want. Leave <strong>File system name<\/strong> blank. Under <strong>Device type<\/strong> select <strong>Generic Linux Device<\/strong>. This should automatically select <strong>Edison<\/strong> as your <strong>Device<\/strong>.\u00c2\u00a0Set your <strong>Sysroot<\/strong> to ({PATH_TO_SDK}\/sysroots\/core2-32-poky-linux), where PATH_TO_SDK depends on your OS as you saw earlier. Select <strong>GCC<\/strong> as your compiler (the one you previously defined). Under <strong>debugger<\/strong> set it to <strong>New Debugger<\/strong>, and finally under <strong>Qt version<\/strong> set it to <strong>None<\/strong> as well since we are not using the Qt SDK.<\/p>\n<p><a href=\"http:\/\/www.samontab.com\/web\/2015\/02\/cross-platform-development-for-intel-edison-using-cmake-and-qt-creator32-and-64-bits\/newdebugger\/\" rel=\"attachment wp-att-347\"><img loading=\"lazy\" decoding=\"async\" class=\"alignnone wp-image-347\" src=\"http:\/\/www.samontab.com\/web\/wp-content\/uploads\/2015\/02\/NewDebugger.png\" alt=\"NewDebugger\" width=\"500\" height=\"422\" srcset=\"https:\/\/www.samontab.com\/web\/wp-content\/uploads\/2015\/02\/NewDebugger.png 1026w, https:\/\/www.samontab.com\/web\/wp-content\/uploads\/2015\/02\/NewDebugger-300x253.png 300w, https:\/\/www.samontab.com\/web\/wp-content\/uploads\/2015\/02\/NewDebugger-1024x863.png 1024w\" sizes=\"auto, (max-width: 500px) 100vw, 500px\" \/><\/a><\/p>\n<p>Click OK and now Qt Creator is configured to build Edison projects.<\/p>\n<h2>The CMake script<\/h2>\n<p>This is what defines your project or application. This is going to be the script that describes what we want to do. In particular we will tell CMake that we want to do a cross compile for the Edison, and specify which libraries we want to use, as well as where our source files are, and what libraries we are going to use. There are two files, one that deals with all the details about cross compiling (<strong>Edison.cmake<\/strong>), and the other file that deals with your actual project (<strong>CMakeLists.txt<\/strong>).<\/p>\n<p>You can download the project files <a href=\"http:\/\/www.samontab.com\/web\/files\/edisonSDK.zip\"><strong>here<\/strong><\/a>. I added a simple mraa example as the main.cpp that reads ADC A0 analog input, provided by Brendan Le Foll. Note that some boards like the mini breakout do not have this ability built in so they will return an error. That&#8217;s expected. The key here is to make the program compile and run on the Edison, not what the program actually does.<\/p>\n<h3>Edison.cmake<\/h3>\n<p>This file defines everything you need to deploy your application into the Edison. You will only need to setup this once, and you will be able to use this file in other projects. I will go through each section of the file explaining what it does.<\/p>\n<p>The following code basically allows you to manually select which version of the SDK you are planning to use, 32 or 64 bits. Comment (add a # symbol) to the line you don&#8217;t want, and uncomment the line you want. Easy. By default it is set to use the 64 bits SDK.<\/p>\n<pre class=\"brush: plain; title: ; notranslate\" title=\"\">\r\n#Are you using the 32 or the 64 bits version of the SDK?.\r\nset(SDK_32bits FALSE) #Use this line for the 64 bits SDK\r\n#set(SDK_32bits TRUE) #Use this line for the 32 bits SDK\r\n<\/pre>\n<p>This is straight forward. Just define where you want your application to be copied to into the Edison (currently it will be copied to <strong>\/home\/root<\/strong>).<\/p>\n<pre class=\"brush: plain; title: ; notranslate\" title=\"\">\r\n#You can change this to any absolute folder in your Edison\r\n#This is the folder where the executable will be copied to.\r\nset(deploymentFolderAbsolutPath \/home\/root)\r\n<\/pre>\n<p>The following code defines the properties of the target OS. No need to change anything here.<\/p>\n<pre class=\"brush: plain; title: ; notranslate\" title=\"\">\r\n#Set the target parameters\r\nset(CMAKE_SYSTEM_NAME Linux)\r\nset(CMAKE_SYSTEM_VERSION 3.10.17-poky-edison+)\r\nset(CMAKE_SYSTEM_PROCESSOR i686)\r\n<\/pre>\n<p>This is where all the paths to the SDK are set. Your OS is identified by cmake, and the version of the SDK (32 or 64 bits) was manually defined earlier. You may only need to change the paths to your specific installations but it may just work as it is.<\/p>\n<pre class=\"brush: plain; title: ; notranslate\" title=\"\">\r\n#Set the host parameters\r\nif(WIN32)\r\n    #Windows host\r\n\tif(${SDK_32bits})\r\n\t\t#32 bit SDK\r\n\t\tset(edison_sdk_root D:\/Edison\/poky-edison-eglibc-i686-edison-image-core2-32-toolchain-1.6.1)\r\n\t\tset(cross_compiler_sysroot ${edison_sdk_root}\/sysroots\/i686-pokysdk-mingw32)\r\n\t\t#MinGW make\r\n\t\tset(CMAKE_MAKE_PROGRAM &quot;C:\/Program Files\/mingw-w64\/i686-4.9.2-posix-dwarf-rt_v3-rev1\/mingw32\/bin\/mingw32-make.exe&quot;)\r\n\telse()\r\n\t\t#64 bit SDK\r\n\t\tset(edison_sdk_root C:\/Edison\/poky-edison-eglibc-x86_64-edison-image-core2-32-toolchain-1.6.1)\r\n\t\tset(cross_compiler_sysroot ${edison_sdk_root}\/sysroots\/x86_64-pokysdk-mingw32)\r\n\t\t#MinGW make\r\n\t\tset(CMAKE_MAKE_PROGRAM &quot;C:\/Program Files (x86)\/mingw-w64\/i686-4.9.2-posix-dwarf-rt_v3-rev1\/mingw32\/bin\/mingw32-make.exe&quot;)\r\n\tendif()\r\n\tset(CMAKE_C_COMPILER ${cross_compiler_sysroot}\/usr\/bin\/i586-poky-linux\/i586-poky-linux-gcc.exe)\r\n\tset(CMAKE_CXX_COMPILER ${cross_compiler_sysroot}\/usr\/bin\/i586-poky-linux\/i586-poky-linux-g++.exe)\r\nelse()\r\n\t#Linux host\r\n\tif(${SDK_32bits})\r\n\t\t#32 bit SDK\r\n\t\tset(edison_sdk_root \/opt\/poky-edison\/1.6.1)\r\n\t\tset(cross_compiler_sysroot ${edison_sdk_root}\/sysroots\/i686-pokysdk-linux)\r\n\telse()\r\n\t\t#64 bit SDK\r\n\t\tset(edison_sdk_root \/opt\/poky-edison\/1.6.1)\r\n\t\tset(cross_compiler_sysroot ${edison_sdk_root}\/sysroots\/x86_64-pokysdk-linux)\r\n\tendif()\r\n\tset(CMAKE_C_COMPILER ${cross_compiler_sysroot}\/usr\/bin\/i586-poky-linux\/i586-poky-linux-gcc)\r\n\tset(CMAKE_CXX_COMPILER ${cross_compiler_sysroot}\/usr\/bin\/i586-poky-linux\/i586-poky-linux-g++)\r\nENDIF(WIN32)\r\n<\/pre>\n<p>The following defines the rest of the cross platform configuration for the Edison, include folders, compiler flags, etc. No need to make changes here unless you know what you are doing.<\/p>\n<pre class=\"brush: plain; title: ; notranslate\" title=\"\">\r\nset(CMAKE_SYSROOT ${edison_sdk_root}\/sysroots\/core2-32-poky-linux)\r\nset(CMAKE_FIND_ROOT_PATH ${CMAKE_SYSROOT})\r\nset(CMAKE_FIND_ROOT_PATH_MODE_PROGRAM NEVER)\r\nset(CMAKE_FIND_ROOT_PATH_MODE_LIBRARY ONLY)\r\nset(CMAKE_FIND_ROOT_PATH_MODE_INCLUDE ONLY)\r\nset(CMAKE_FIND_ROOT_PATH_MODE_PACKAGE ONLY)\r\n\r\nSET(CMAKE_C_FLAGS &quot;-Os -g3 -Wall --sysroot=${CMAKE_SYSROOT} -m32 -march=i586 -ffunction-sections -fdata-sections&quot;  CACHE STRING &quot;&quot; FORCE)\r\nSET(CMAKE_CXX_FLAGS &quot;-Os -g3 -Wall --sysroot=${CMAKE_SYSROOT} -m32 -march=i586 -ffunction-sections -fdata-sections&quot;  CACHE STRING &quot;&quot; FORCE)\r\n\r\nINCLUDE_DIRECTORIES(${CMAKE_SYSROOT}\/usr\/include)\r\nINCLUDE_DIRECTORIES(${CMAKE_SYSROOT}\/usr\/include\/c++)\r\nINCLUDE_DIRECTORIES(${CMAKE_SYSROOT}\/usr\/include\/c++\/i586-poky-linux)\r\n<\/pre>\n<p>And finally this section defines a way to tell Qt to deploy a file<\/p>\n<pre class=\"brush: plain; title: ; notranslate\" title=\"\">\r\n#This is for telling Qt to deploy files\r\nfile(WRITE &quot;${CMAKE_SOURCE_DIR}\/QtCreatorDeployment.txt&quot; &quot;\/\\n&quot;)\r\nmacro(add_deployment_file SRC DEST)\r\n\tfile(RELATIVE_PATH path ${CMAKE_SOURCE_DIR} ${CMAKE_CURRENT_SOURCE_DIR})\r\n\tfile(APPEND &quot;${CMAKE_SOURCE_DIR}\/QtCreatorDeployment.txt&quot; &quot;${path}\/${SRC}:${DEST}\\n&quot;)\r\nendmacro()\r\nmacro(add_deployment_directory SRC DEST)\r\n\tfile(GLOB_RECURSE files RELATIVE &quot;${CMAKE_CURRENT_SOURCE_DIR}&quot; &quot;${SRC}\/*&quot;)\r\n\tforeach(filename ${files})\r\n\t\tget_filename_component(path ${filename} PATH)\r\n\t\tadd_deployment_file(&quot;${filename}&quot; &quot;${DEST}\/${path}&quot;)\r\n\tendforeach(filename)\r\nendmacro()\r\n<\/pre>\n<h3>CMakeLists.txt<\/h3>\n<p>This is the main file for your project. Every cmake project has at least one of these files.<\/p>\n<p>First, I start defining the minimum version of cmake required for this project, and include the Edison.cmake file that I just described.<\/p>\n<pre class=\"brush: plain; title: ; notranslate\" title=\"\">\r\ncmake_minimum_required(VERSION 2.6)\r\n\r\n#This is where all the settings to compile for the Edison are stored.\r\nINCLUDE(${CMAKE_SOURCE_DIR}\/Edison.cmake)\r\n<\/pre>\n<p>This is the actual definition of the project. The name of the project (not the executable) is set as EdisonCrossCompile, and the project is set to compile either C or C++ sources. You can set exe_name to define the name for your application (currently it is set as <strong>executableName<\/strong>). I also included a script to update the SDK to the latest libraries versions. It is disabled by default as it overwrites the files. If you want to add this feature (at your own risk), uncomment the line. If you do that, every time CMake is called, you will update your SDK. This is usually at the beginning of the project, and when you click on <strong>Build-&gt;Run CMake<\/strong>, not when you build your project.<\/p>\n<p>Also, any file that is put in this root directory with extension .cpp or .h will be included in the project. This is a simple way to start a new project. More complex projects can, of course, use the full cmake syntax to define their source structure. Also, I add <a href=\"http:\/\/iotdk.intel.com\/docs\/master\/mraa\/\">libmraa<\/a> as an example of how to use external libraries. The rest is to build and link the executable.<\/p>\n<pre class=\"brush: plain; title: ; notranslate\" title=\"\">\r\nPROJECT(EdisonCrossCompile C CXX)\r\n\r\n#This is for updating the local SDK to the latest version of mraa and upm\r\n#Uncomment this line to update your SDK every time you run CMake (not every time you build your project)\r\n#INCLUDE(${CMAKE_SOURCE_DIR}\/updateSDK.cmake)\r\n\r\n#This is the name of the compiled program. Change executableName to anything you want.\r\nset(exe_name executableName)\r\n\r\n\r\n#Here I am defining the source and header files of the project. You can just put .cpp and .h files into this folder and they will get compiled.\r\nfile(GLOB cpp_files *.cpp)\r\nfile(GLOB h_files *.h)\r\n\r\n#Here you can include extra libraries for your application, like libmraa (http:\/\/iotdk.intel.com\/docs\/master\/mraa\/) for example\r\nset(extra_libraries -lmraa)\r\n\r\n#The actual compilation and linkage\r\nadd_executable(${exe_name} ${cpp_files} ${h_files})\r\ntarget_link_libraries(${exe_name} ${extra_libraries})\r\n<\/pre>\n<p>Finally, this is used to copy the executable over to the Edison and execute it there.<\/p>\n<pre class=\"brush: plain; title: ; notranslate\" title=\"\">\r\n#This tells Qt which file to copy over to the Edison.\r\nfile(RELATIVE_PATH relativeDir ${PROJECT_SOURCE_DIR} ${PROJECT_BINARY_DIR}\/${exe_name})\r\nadd_deployment_file(${relativeDir} ${deploymentFolderAbsolutPath})\r\n<\/pre>\n<h2>Opening your project in Qt Creator<\/h2>\n<p>Once you have your project configured, you will be able to open it under Qt Creator. Click on <strong>File-&gt;Open File or Project<\/strong> and select your <strong>CMakeLists.txt<\/strong> file.<br \/>\nYou will see a windows asking you for the build location. This is where the build files are going to be created, and where by default your executable will be created. Usually this is a folder called build under the root of your project. Click <strong>Next<\/strong>.<br \/>\n<a href=\"http:\/\/www.samontab.com\/web\/2015\/02\/cross-platform-development-for-intel-edison-using-cmake-and-qt-creator32-and-64-bits\/7_buildpath\/\" rel=\"attachment wp-att-337\"><img loading=\"lazy\" decoding=\"async\" class=\"alignnone wp-image-337\" src=\"http:\/\/www.samontab.com\/web\/wp-content\/uploads\/2015\/02\/7_buildPath.png\" alt=\"7_buildPath\" width=\"500\" height=\"347\" srcset=\"https:\/\/www.samontab.com\/web\/wp-content\/uploads\/2015\/02\/7_buildPath.png 559w, https:\/\/www.samontab.com\/web\/wp-content\/uploads\/2015\/02\/7_buildPath-300x208.png 300w\" sizes=\"auto, (max-width: 500px) 100vw, 500px\" \/><\/a><br \/>\nNow under <strong>Generator<\/strong> select <strong>Unix Generator(Edison)<\/strong>. If you don&#8217;t see this option, go back to the section called <strong>Qt Creator configuration<\/strong> in this guide and do it properly.<br \/>\nClick on <strong>Run CMake <\/strong>and wait for a couple of seconds. Everything should work fine. Click on <strong>Finish<\/strong> when it is done.<br \/>\n<a href=\"http:\/\/www.samontab.com\/web\/2015\/02\/cross-platform-development-for-intel-edison-using-cmake-and-qt-creator32-and-64-bits\/8_runcmake\/\" rel=\"attachment wp-att-339\"><img loading=\"lazy\" decoding=\"async\" class=\"alignnone wp-image-339\" src=\"http:\/\/www.samontab.com\/web\/wp-content\/uploads\/2015\/02\/8_runCmake.png\" alt=\"8_runCmake\" width=\"499\" height=\"338\" srcset=\"https:\/\/www.samontab.com\/web\/wp-content\/uploads\/2015\/02\/8_runCmake.png 783w, https:\/\/www.samontab.com\/web\/wp-content\/uploads\/2015\/02\/8_runCmake-300x203.png 300w\" sizes=\"auto, (max-width: 499px) 100vw, 499px\" \/><\/a><br \/>\nYou should now see all your project files listed in the Qt Creator IDE.<br \/>\n<a href=\"http:\/\/www.samontab.com\/web\/2015\/02\/cross-platform-development-for-intel-edison-using-cmake-and-qt-creator32-and-64-bits\/9_ide\/\" rel=\"attachment wp-att-341\"><img loading=\"lazy\" decoding=\"async\" class=\"alignnone wp-image-341\" src=\"http:\/\/www.samontab.com\/web\/wp-content\/uploads\/2015\/02\/9_ide.png\" alt=\"9_ide\" width=\"500\" height=\"333\" srcset=\"https:\/\/www.samontab.com\/web\/wp-content\/uploads\/2015\/02\/9_ide.png 1008w, https:\/\/www.samontab.com\/web\/wp-content\/uploads\/2015\/02\/9_ide-300x200.png 300w\" sizes=\"auto, (max-width: 500px) 100vw, 500px\" \/><\/a><\/p>\n<p>Click on the build icon (the brown hammer icon in the lower left section), and your project should build fine. You can actually see the compiled executable file for the Edison ready to be used in the build folder that you selected before.<br \/>\n<a href=\"http:\/\/www.samontab.com\/web\/2015\/02\/cross-platform-development-for-intel-edison-using-cmake-and-qt-creator32-and-64-bits\/10_executable\/\" rel=\"attachment wp-att-342\"><img loading=\"lazy\" decoding=\"async\" class=\"alignnone wp-image-342\" src=\"http:\/\/www.samontab.com\/web\/wp-content\/uploads\/2015\/02\/10_executable.png\" alt=\"10_executable\" width=\"500\" height=\"302\" srcset=\"https:\/\/www.samontab.com\/web\/wp-content\/uploads\/2015\/02\/10_executable.png 775w, https:\/\/www.samontab.com\/web\/wp-content\/uploads\/2015\/02\/10_executable-300x181.png 300w\" sizes=\"auto, (max-width: 500px) 100vw, 500px\" \/><\/a><\/p>\n<p>You can now manually copy this file over to the Edison and it will run fine there. But we will add an extra setting that will allow us to execute it directly from the Qt Creator IDE.<br \/>\nClick on <strong>Projects<\/strong> and click on <strong>Run<\/strong> (there is a small Build | Run selection right below the name of the project, on the upper side of the window). Under the <strong>Run<\/strong> section, under Run configuration, click on <strong>Add<\/strong> and select <strong>executableName(on Remote Device)<\/strong>. Now you should be able to click on the build icon(Hammer symbol), or the build and run icon (green play symbol) and the application will get transferred to the Edison, executed remotely, and you will see the console output on the Qt Creator IDE.<br \/>\n<a href=\"http:\/\/www.samontab.com\/web\/2015\/02\/cross-platform-development-for-intel-edison-using-cmake-and-qt-creator32-and-64-bits\/11_externalrun\/\" rel=\"attachment wp-att-343\"><img loading=\"lazy\" decoding=\"async\" class=\"alignnone wp-image-343\" src=\"http:\/\/www.samontab.com\/web\/wp-content\/uploads\/2015\/02\/11_externalRun.png\" alt=\"11_externalRun\" width=\"500\" height=\"435\" srcset=\"https:\/\/www.samontab.com\/web\/wp-content\/uploads\/2015\/02\/11_externalRun.png 937w, https:\/\/www.samontab.com\/web\/wp-content\/uploads\/2015\/02\/11_externalRun-300x261.png 300w\" sizes=\"auto, (max-width: 500px) 100vw, 500px\" \/><\/a><\/p>\n<h2>Troubleshooting<\/h2>\n<p>Here I will list the most common problems and their solutions.<\/p>\n<h3>CMake issues<\/h3>\n<p>If anything goes wrong, check that all the paths are correctly set in the cmake script. This is probably where most of the issues will be. You can use <strong>message(varName values is: ${varName})<\/strong> to output the values of cmake variables for debugging.<br \/>\nAlso, if you are stuck with an error while changing parameters it is a good idea to delete the entire build directory and start again as sometimes cached variables may still persist with the old values.<\/p>\n<h3>Qt Creator issues<\/h3>\n<p>If you see this error when building on Qt Creator on Windows: <strong>Could not start process &#8220;make&#8221;<\/strong>, it means that the mingw64 executable was not correctly recognized. The solution here is to go to <strong>Projects-&gt;Build<\/strong>, and under <strong>Build Steps<\/strong> click on <strong>Details<\/strong>. Under <strong>override command<\/strong> (Available in newer Qt Creator versions) click on Browse and select your mingw32-make.exe file. If you don&#8217;t have an override command available, just remove the make step and add a new custom process step and select your mingw32-make.exe file as the command. Repeat the same for the make clean step.<\/p>\n","protected":false},"excerpt":{"rendered":"<p>The Intel Edison is an amazing little device, but the current SDK only works out of the box with Eclipse, and creating new projects is not very easy. In this post, I will show you how to use CMake and Qt Creator to develop for the Intel Edison remotely. This allows you to use the [&hellip;]<\/p>\n","protected":false},"author":2,"featured_media":0,"comment_status":"open","ping_status":"open","sticky":false,"template":"","format":"standard","meta":{"footnotes":""},"categories":[22,4],"tags":[],"class_list":["post-327","post","type-post","status-publish","format-standard","hentry","category-iot","category-programming"],"_links":{"self":[{"href":"https:\/\/www.samontab.com\/web\/wp-json\/wp\/v2\/posts\/327","targetHints":{"allow":["GET"]}}],"collection":[{"href":"https:\/\/www.samontab.com\/web\/wp-json\/wp\/v2\/posts"}],"about":[{"href":"https:\/\/www.samontab.com\/web\/wp-json\/wp\/v2\/types\/post"}],"author":[{"embeddable":true,"href":"https:\/\/www.samontab.com\/web\/wp-json\/wp\/v2\/users\/2"}],"replies":[{"embeddable":true,"href":"https:\/\/www.samontab.com\/web\/wp-json\/wp\/v2\/comments?post=327"}],"version-history":[{"count":0,"href":"https:\/\/www.samontab.com\/web\/wp-json\/wp\/v2\/posts\/327\/revisions"}],"wp:attachment":[{"href":"https:\/\/www.samontab.com\/web\/wp-json\/wp\/v2\/media?parent=327"}],"wp:term":[{"taxonomy":"category","embeddable":true,"href":"https:\/\/www.samontab.com\/web\/wp-json\/wp\/v2\/categories?post=327"},{"taxonomy":"post_tag","embeddable":true,"href":"https:\/\/www.samontab.com\/web\/wp-json\/wp\/v2\/tags?post=327"}],"curies":[{"name":"wp","href":"https:\/\/api.w.org\/{rel}","templated":true}]}}