I'm running Ubuntu 16.04 and just opened my freshly installed Eclipse CDT Oxygen for the first time.
I imported an existing C++ project that builds fine using a CMake file that sets add_definitions(-std=c++11).
I used CMake with the command cmake -G"Eclipse CDT4 - Unix Makefiles" -D CMAKE_BUILD_TYPE=Debug ../src/ to generate Eclipse project files and then used those to import the project into Eclipse.
Now I'm looking at a source file in my newly imported project inside Eclipse and see a ton of issues. It's all types that cannot be resolved, for example std::default_random_engine.
My guess is that Eclipse doesn't have the right toolchain configured.
I have a few questions:
How can I see the toolchain for my project and how can I change it? I looked up this help article, but the sections in the project properties menu I see are not the same as in the help article. The project properties menu I see does not have a "C/C++ Build" section. How can that be?
The CMake file that I used to generate the Eclipse project files specifies that C++11 is supposed to be used, so why isn't this the case then?
Here is what my project properties menu looks like:
This is what my .project file looks like:
<?xml version="1.0" encoding="UTF-8"?>
<projectDescription>
<name>particle_filter</name>
<comment></comment>
<projects>
</projects>
<buildSpec>
<buildCommand>
<name>org.eclipse.cdt.managedbuilder.core.genmakebuilder</name>
<triggers>clean,full,incremental,</triggers>
<arguments>
</arguments>
</buildCommand>
<buildCommand>
<name>org.eclipse.cdt.managedbuilder.core.ScannerConfigBuilder</name>
<triggers>full,incremental,</triggers>
<arguments>
</arguments>
</buildCommand>
</buildSpec>
<natures>
<nature>org.eclipse.cdt.core.cnature</nature>
<nature>org.eclipse.cdt.core.ccnature</nature>
<nature>org.eclipse.cdt.managedbuilder.core.managedBuildNature</nature>
<nature>org.eclipse.cdt.managedbuilder.core.ScannerConfigNature</nature>
</natures>
</projectDescription>
Thanks a lot!
The missing C/C++ Build section can be caused by a broken .project, .cproject or .settings/language.settings.xml file:
Create a new project of the same type
In the Navigator view compare the .project, the .cproject and the .settings/language.settings.xml files with the corresponding files of the new project to find the problem (make sure to use same IDs in .cproject and in .settings/language.settings.xml, but different IDs than in other projects)
I think CMake's CDT project generator is fairly out of date and doesn't configure the generated project properly for C++11 support.
I recommend the following approach for configuring C++11 support:
Go to Project Properties | C/C++ General | Preprocessor Include Paths.
In the Providers tab, select CDT GCC Built-in Compiler Settings.
(If necessary, uncheck "Use global provider shared between projects".)
Add -std=c++11 to the "Command to get compiler specs".
Apply and rebuild the project's index.
After doing this, C++11 symbols should be resolved properly.
Related
I'm modifying a simple example project (blinky) from the nRF SDK. I added a header file and a .c file in a new folder inside the project directory then added that path ./lib to the common preprocessor user include directories. I then included the header to main.c.
I can compile the new library on its own but when I build the whole project, I get Build failed error with no stated reason to follow up.
Here is an image of that:
Does anyone here know how to beat this?
I haven't used Segger Studio specifically, but it seems to be the CrossWorks IDE underneath.
In CrossWorks, you have to do the following:
Download & install all relevant libs from inside the IDE, under Tools -> Packages -> Install packages. Grab your specific target MCU as well as any specific boards or libraries you'll be using. In case some needed lib is missing here, you will get very weird errors.
In the project, click on the project name itself in "project explorer". Then in the properties window, check settings (this is a bit different in different versions of CrossWorks, might have to right click and pick properties in older versions). Under "user include directories" you should have something like this:
$(DeviceIncludePath)
$(TargetsDir)/NameOfMCU/Include
$(PackagesDir)/CMSIS_4/CMSIS/Include
$(ProjectDir)/NameOfDirectory
Where "NameOfMCU" is the name of the MCU family used, CMSIS should be there in case you are using any ARM, "NameOfDirectory" is the name of your custom directory (you can add several).
Also, get the debug build working first, before switching to release build.
I would love to import a Makefile project from Eclipse, and have all the different includes path that the compiler uses to create correctly my Eclipse project.
Unfortunately, those path, specified on the command line by a "-I" don't show up in Project Explorer and I have to add them by hand.
I am currently importing the project using the standard "Import project from Makefile" built in Eclipse.
If I'm not wrong there was an autodiscovery option in older versions of Eclipse, but it's not there anymore.
How do you do for having all your include paths set up without too much hassle?
The trick is NOT to use
File->New->Makefile Project with Existing Code
but to use
File->New->C++ Project
and then to select
Makefile project->Empty project.
After you set up such a dummy project, you simply copy your existing source to that project directory, hit F5 (i.e. Refresh) and change the build command to use your Makefile.
I was able to get this to work using Luna. I imported using File->New->C++->Makefile Project with Existing Code.
Prior to launching eclipse, you have to be sure to source any files that set required environment variables.
I did have some build options which were not the standard all and clean, so I had to add those configurations individually.
source files to setup your environment.
Launch Eclipse
Import C++ Makefile project
Setup Build options.
Click the hammer.
Since I upgraded from Eclipse Indigo to Juno (on Ubuntu 12.04), I've been having the problem where it shows "unresolved inclusion" errors for standard libraries (e.g. next to #include <iostream> and #include <vector>, etc.), although the program builds and runs fine (using g++). This only occurs in new projects created with Juno, not old ones from Indigo in my workspace.
Thanks to several other SO questions (see below*), I was able to trace the source of the problem to the absence of the "built-in values" in a project's Properties > C/C++ General > Paths and Symbols > Includes tab:
/usr/include/c++/4.6
/usr/include/c++/4.6/x86_64-linux-gnu
/usr/include/c++/4.6/backward
/usr/lib/gcc/x86_64-linux-gnu/4.6/include
/usr/lib/gcc/x86_64-linux-gnu/4.6/include-fixed
/usr/include/x86_64-linux-gnu
/usr/include
are present when the "Show built-in values" checkbox is ticked in my old Indigo projects that didn't have this problem, but are absent in my new projects created with Juno. Sure enough, if I add these seven directories manually to the Includes tab in a project's settings, the problem disappears. But I don't want to have to do this manually for every new project I create. Is there a reason this is no longer the default in Juno, and is there a way to restore it?
*Other SO questions with similar issues I have consulted but did not solve my problem:
Eclipse 3.7.0 Indigo with CDT shows many false compilation errors: I thought Erzsébet Geréb's answer would be my solution -- in Juno, if I create a new C++ project with "Project type" as one of the categories under "GNU Autotools" instead of "Executable," the built-in directories are there. (In Indigo, there's no GNU Autotools category. If I created it in Indigo as an empty or Hello World project under "Executable," those directories are there, but they're not if I do it that way in Juno -- I have to pick an option under "GNU Autotools.") But then, with a "GNU Autotools" project, when I go to the project's Properties > C/C++ Build > Settings, the "Tool Settings" tab is no longer present and I am unable to add include paths for the GCC C++ Compiler and libraries for the GCC C++ Linker, which I need to do because many of my C++ projects use OpenCV libraries.
"Unresolved inclusion" error with Eclipse CDT for C standard library headers: Told me how to add the include paths manually, but not how to have the built-in ones added by default
error , Symbol 'vector' could not be resolved: Cleaning ~/.eclipse/ and rebuilding index didn't help.
Eclipse CDT Builtin Include Directories: Discovery Options are set the same as my projects that do work properly.
eclipse CDT 8.01 - default paths (libstdc,libstdc++) totally disappeared in 'includes' directory
Eclipse CDT indexer lost after system update: Doesn't solve the problem for all new projects.
Please
Open the Eclipse Preferences dialog (Windows | Preferences).
Open C++ | Build | Settings.
Open the Discovery tab.
Select the built-in compiler settings entry.
Press the Clear Entries button.
Afterwards eclipse should request the defaults again from the compiler.
On Arch Linux I had to do this after each GCC version change, because in that case the locations for the defaults changed as the version is encoded in the folder name, and eclipse does not notice this.
FWIW:
I found that after importing a project from another computer, I was not getting any thing showing up under the "Includes" section of my project in the Project Explorer. To fix this, I needed to delete the folder /workspace/project/.settings/. For me it only had one file (language.settings.xml).
Then everything was back to normal.
I'm a new C++ programmer using Eclipse. Eclipse seems to recognize C++: It let me create a new C++ project and understands the syntax. However, whenever I try to #include anything, I get an "Unresolved include" error.
I have CDT installed. I also just installed MinGW and MySys and set the path variables correctly.
It looks like something's still missing from Eclipse though -- when I right click on my project and go to "properties -> C/C++ build -> Settings" all I can access are the "binary parsers" and "error parsers" tabs. The window should look like this...
...but I can't see the tool settings, build steps or build artifact tabs.
That's all my research has turned up so far. What should I do next?
Settings on screenshot related to build process. For correct work editor (autocomlete, includes) you need to set same dirs in the C/C++ General/Paths and symbols, includes, GNU C++. Also, if path variable containt dir with g++ ecplise should to have prepared configuration if you choose mingw toolchain while creating project.
Update for comment
I'm trying to get the Boost library working in my C++ projects in Eclipse. I can successfully build when using header-only libraries in Boost such as the example simple program in the "Getting Started" guide using the lambda header.
I cannot get my project to successfully link to the regex Boost library as shown later in the guide. Under my project properties -> c/c++ build -> settings -> tool settings tab -> libraries, I have added "libboost_regex" to the Libraries box, and "C:\Program Files\boost\boost_1_42_0\bin.v2\libs" to the Library search path box since this is where all the .lib files are. I've even tried adding "libboost_regex-mgw34-mt-d-1_42.lib" to the libraries box instead of "libboost_regex" since that is the exact file name, but this did not work either.
I keep getting an error that says "cannot find -llibboost_regex" when I try to build my project. Any ideas as to how I can fix this?
Edit: on Windows XP, using mingw, and I have tried "boost_regex" as well..
I just went through the whole process of installing MinGW, compiling boost and installing Eclipse CDT and I'm able to compile simple programs using boost:regex. I'll write down all the steps. I hope that can be of help.
I've installed MinGW and MSYS in their default location.
Here are the step I took to build boost:
Download boost-jam-3.1.18-1-ntx86.zip from http://sourceforge.net/projects/boost/files/boost-jam
Put bjam.exe somewhere in your PATH
Unpack boost in C:\mingw\boost_1_42_0
Open an msys terminal window and cd /c/mingw/boost_1_42_0
In the boost directory run bjam --build-dir=build toolset=gcc stage
To configure Eclipse:
Add CDT to Eclipse 3.5 from the update site
Create a new C++ project
Under the Project menu select properties
Make sure the configuration is Debug [Active]
In "C/C++ General" > "Paths and Symbols"
Under the Includes tab select the GNU C++ language and add C:\MinGW\boost_1_42_0
Under the Library Paths tab add C:\MinGW\boost_1_42_0\stage\lib
In "C/C++ Build" > "Settings"
Select MinGW C++ Linker > Libraries
Click on the add button for Libraries (-l)
Type libboost_regex-mgw34-mt-d (without the .lib)
You can then go through the same steps for the Release configuration but use libboost_regex-mgw34-mt instead. Also make sure your source files include <boost/regex.hpp>
To link to boost library in eclipse you need to set both the eclipse's project library path(the one with the -L) and the name of the library(the one with the -l).
The prefix 'lib' and the extension of the library's name must be removed:-
eg: libboost_regex.a should be specified as boost_regex.
I believe your lib path is pointing to the wrong place. The libs will be installed to:
boost_install_dir\boost_1_42\lib
I think the default boost_install_dir is "C:\Program Files\Boost" (not sure because I don't use the default install directory).