Eclipse CDT can't add .h files to path automatically - eclipse

I use Eclipse CDT develop a C project in Windows.When i build the project, it throws some errors said the c file invoke .h files these file can't find. But actually, these files are available, it looks like the Eclipse CDT can't add them path? why not CDT add them to path automatically, like java? The make file is generated by Eclipse, i'm just begin to use Eclipse CDT, who can help me?

No, you need to add the paths as follows (covering a little bit more than what was asked) :
See gcc man page :
-L : Add a directory to the list of directories to be searched for -l
-l : The name of the library to be searched (without lib* prefix and extension)
For example: libmylib.a would be linked using linker option -lmylib
and :
-I : Add a directory to the list of directories to be searched for header files.
Each of those options can be repeated several times when passed to the compiler.
In CDT :
To configure includes : "Project > Properties > C/C++ Build > Settings > GCC Compiler > Includes"
To configure libraries : "Project > Properties > C/C++ Build > Settings > GCC Linker > Libraries"
Those configurations are also available in "Project > Properties > C/C++ General > Paths and Symbols > Includes/Libraries". Same rules as above.

Related

How to link to pistache in Eclipse C++

I fail to link the pistache library in Eclipse C++ on my Ubuntu machine. I already make this reference:
Properties > C/C++ Build > Settings > Tool Settings
Under GCC C++ Linker > Libraries > Library search path
Under GCC C++ Compiler > Includes > Include paths
Add /usr/local/include/pistache to each
It throws a bunch of errors like this:
.... undefined reference to `Pistache::Ipv4::any()'
Why does this fail? The autocomplete is able to see the reference when I try rewrite the whole line, but it still errors out.
You have to let the linker use shared libraries and pass the -fpic option to the compiler:
a. First step -shared, see this image
b. Last Step Position Independent Code -fPic, see this image
Update
Another way to solve this is:
a. Add support for pthread to the linker
b.Add pistache to libraries in the linker

STM32 Eclipse + ARM GNU toolchain error linker

I use Eclipse + ARM plugin to build my projects. When I needed to use in my project the StemWin library, I configured my IDE to use external library.
I set
Preferences -> C/C++ General -> Paths and Symbols
I added in "Library Paths" the link to my folder includes library.
I also added the name of my library in tab "Library".
I checked the settings in the compiler tab and I ascertained all should be good.
When I tried to build my project I got an error from linker:
cannot find -lMyLib.a Hello C/C++ Problem
I double checked the name of my library and link, all are correct. This is the output of my linker:
arm-none-eabi-gcc -mcpu=cortex-m4 -mthumb -mfloat-abi=hard -L"C:\lib"
-T"C:\arm_toolchain\stm32_workspace\Hello\LinkerScript.ld" -Wl,
-Map=output.map -Wl,--gc-sections -o "Hello.elf" #"objects.list" -lMyLib.a
What should I do from here?
I faced the same problem before.
-l:STemWin526_CM4_GCC.a
-L"C:\Edu_Workspace\STM32F4\stm32f4_bsp_template\Drivers\Middlewares\ST\STemWin\Lib"
Above are my working settings.
With -l:<archive file name> the colon : is important for archive file linking.
And -L will contain library path.
Also for stemwin make sure to compile with hardware floating point
-mfloat-abi=hard -mfpu=fpv4-sp-d16
the convention for the -l option of the linker (say you give -lMyLib.a as a linker option) is to search for a library file with "lib" prepended to the given name and .a (or .so) appended, i.e. your command line searches for a file libMyLib.a.{a,so} which is probably not how it's named.
Either you rename your library according to this convention or give it to the linker command line omitting -l (provided your IDE allows you to do so).
Looks like the problem is in -lMyLib.a which means you're trying to link a static library as a dynamic one.
To link a static lib you have to use its path as with ordinary .o files: ... /path/to/MyLib.a
and the resulting command line should look something like
arm-none-eabi-gcc -mcpu=cortex-m4 -mthumb -mfloat-abi=hard -L"C:\lib" -T"C:\arm_toolchain\stm32_workspace\Hello\LinkerScript.ld" -Wl,-Map=output.map -Wl,--gc-sections -o "Hello.elf" #"objects.list" /path/to/MyLib.a
UPDATE:
Although it might fix the issue, turns out it's not true:
-llibrary
-l library
...
Normally the files found this way are library files—archive files whose members are object files. The linker handles an archive file by scanning through it for members which define symbols that have so far been referenced but not defined. But if the file that is found is an ordinary object file, it is linked in the usual fashion. The only difference between using an -l option and specifying a file name is that -l surrounds library with ‘lib’ and ‘.a’ and searches several directories.
(https://gcc.gnu.org/onlinedocs/gcc/Link-Options.html)

Threads in Eclipse AND c++11

My goal has been to create multi-threading programs, and I can not even get a simple thread
to execute ON ECLIPSE CDT. my Tools:
ECLIPSE 3.8.1 CDT
Ubuntu 13.10
I have noticed very similar issues regarding mine. I have tried those other solutions but I could not get them to work for me.
When I type the code in Eclipse CDT, Eclipse does not 'resolve' the symbols 'thread', however, It can find the header file 'thread'. 'Mutex' also does not resolve. Furthermore, after building, I run the program, eclipse returns :
"terminate called after throwing an instance of 'std::system_error'
what(): Enable multithreading to use std::thread: Operation not permitted"
Some additional notes:
I can compile and execute the code in the terminal using:
'clang++ c.cpp -pthread -std=c++11'
but...
'g++ c.cpp -pthread -std=c++11' compiles and
produces the same error as quoted above. So it looks like it's a compiler issue. I did
start to write the code in a new project within Eclipse CDT with the clang++ compiler and now that gives the same non-resolved 'thread' and produces the error as quoted above. So now I think I have some wrong settings, paths or flags set in Eclipse.
include <iostream>
include <thread>
using namespace std;
void p1(){
cout<<"process 1 is processing"<<endl;
}
int main() {
thread t1(&p1);
cout<<"Hello from main()"<<endl;
t1.join();
return 0;
}
I have been struggling with the very same issue and I finally resolved it. Here is what I did:
1) Add -std=c++11 for c++ build. To do that right-click your project, select properties and then: C/C++ Build -> Settings -> GCC C++ Compiler -> Miscellaneous(last option)
In other flags append -std=c++11. My Other flags now looks like: -c -fmessage-length=0 -std=c++11 but yours may be a bit different.
2) Add some linker options. In the same view(C/C++ Build -> Settings) as above select the GCC C++ Linker option and from there go to Miscellaneous(second to last option). Add the following Linker flags(the field was empty for me): -Wl,--no-as-needed -pthread. Hit apply.
3) Add a macro. Again from the project properties menu(project->right click->properties). Navigate to C/C++ General -> Paths and symbols -> Symbols. Select GNU C++. Add a symbol with the name __GXX_EXPERIMENTAL_CXX0X__ and no value. Again hit apply.
4) Navigate to C/C++ General -> Preprocessor Include paths.. Select the providers tab. In this tab leave only the following two options checked: CDT GCC Built-in Compiler Settings and CDT Managed Build Setting Entries. Select CDT GCC Built-in Compiler Settings uncheck the checkbox Share setting entries between projects(global provider) and now the text box labeled Command to get compiler specs should be enabled. In this text box append the good old -std=c++11. The text now looks like this for me ${COMMAND} -E -P -v -dD ${INPUTS} -std=c++11. Hit apply one last time.
5) Rebuild the index for the project. To do that right click the project->Index->Rebuild
Following these steps I was able to compile a c++11 multithreaded program, execute it and also Eclipse CDT did not report any errors and was helpful with the autocompletion. Unfortunately this setting has to be done separately for Release and Debug(or at least I have not found a way to share it). Hope this helps.

Eclipse CDT can't find opencv 2 header files

I installed opencv 2.3.1 with macports and the newest Eclipse CDT. Now I'm trying to compile this code:
> #include <iostream.h>
> #include <cv.h> // or opencv.hpp, no difference
>
> int main(int argc, char **argv) {
>
>
> }
I have done all the steps of http://opencv.itseez.com/doc/tutorials/introduction/linux_eclipse/linux_eclipse.html but the output of the compiler is:
> make all Building file: ../main.cpp Invoking: GCC C++ Compiler g++
> -I/opt/local/include/opencv -I/opt/local/include/opencv2 -O0 -g3 -Wall -c -fmessage-length=0 -MMD -MP -MF"main.d" -MT"main.d" -o "main.o" "../main.cpp" In file included from
> /usr/include/c++/4.2.1/backward/iostream.h:31,
> from ../main.cpp:8: /usr/include/c++/4.2.1/backward/backward_warning.h:32:2: warning:
> #warning This file includes at least one deprecated or antiquated header. Please consider using one of the 32 headers found in section
> 17.4.1.2 of the C++ standard. Examples include substituting the <X> header for the <X.h> header for C++ includes, or <iostream> instead of
> the deprecated header <iostream.h>. To disable this warning use
> -Wno-deprecated. In file included from ../main.cpp:9: /opt/local/include/opencv2/opencv.hpp:46:33: error:
> opencv2/core/core_c.h: No such file or directory
> /opt/local/include/opencv2/opencv.hpp:47:33: error:
> opencv2/core/core.hpp: No such file or directory
> /opt/local/include/opencv2/opencv.hpp:48:39: error:
> opencv2/flann/miniflann.hpp: No such file or directory
> /opt/local/include/opencv2/opencv.hpp:49:39: error:
> opencv2/imgproc/imgproc_c.h: No such file or directory
> /opt/local/include/opencv2/opencv.hpp:50:39: error:
> opencv2/imgproc/imgproc.hpp: No such file or directory
> /opt/local/include/opencv2/opencv.hpp:51:35: error:
> opencv2/video/video.hpp: No such file or directory
> /opt/local/include/opencv2/opencv.hpp:52:45: error:
> opencv2/features2d/features2d.hpp: No such file or directory
> /opt/local/include/opencv2/opencv.hpp:53:43: error:
> opencv2/objdetect/objdetect.hpp: No such file or directory
> /opt/local/include/opencv2/opencv.hpp:54:39: error:
> opencv2/calib3d/calib3d.hpp: No such file or directory
> /opt/local/include/opencv2/opencv.hpp:55:29: error: opencv2/ml/ml.hpp:
> No such file or directory /opt/local/include/opencv2/opencv.hpp:56:39:
> error: opencv2/highgui/highgui_c.h: No such file or directory
> /opt/local/include/opencv2/opencv.hpp:57:39: error:
> opencv2/highgui/highgui.hpp: No such file or directory
> /opt/local/include/opencv2/opencv.hpp:58:39: error:
> opencv2/contrib/contrib.hpp: No such file or directory make: ***
> [main.o] Error 1
>
> **** Build Finished ****
What am I doing wrong?
okay.. I have had a lot of trouble in this myself.
You need to look int the opencv folder structure that you installed for these header files yourself. Sometimes they're not in the place the install guide tells you they are.
In my computer for example, most of the header files I needed are in:
[INSTALL DIRECTORY]/include/opencv
[INSTALL DIRECTORY]/include/opencv2
but SOME were in:
[INSTALL DIRECTORY]/modules/core/include/opencv2
[INSTALL DIRECTORY]/modules/highgui/include/opencv2 etc
you need to find those include files. Then go to your IDE (eclipse). In eclopse there should be a setting for the "include directories"
Set your IDE to look for include files in the directories where you know the include files are.
Then make sure you add the libraries. Ask if you need help with that.
The errors listed above shows that you have not specified the paths of include directories.first you search for the include directories in your installation folder.Generally they are in /home/usr/include/opencv and /home/usr/local/include/opencv
After locating these files you open project properties in Eclipse CDT. Select GCC C++ compiler -- directories and add the include directories there. Select GCC C++ Linker option and give the library path generally it is /usr/local/lib
Specify the libraries in quotes too e.g. "cv" , "highgui" etc.This will complete the configuration.
Hope it helps.

Eclipse Indigo CDT: Function could not be resolved

This feels silly, but its been 2 days...somewhere after upgrading from Ubuntu 10.04 to 10.11 and from Eclipse Helios to Eclipse Indigo, I got stuck with the following problem:
Problem Description:
I'm trying to use a function in math.h called isinf(), but the problem also occurs with things like isnan(). The program compiles fine on the command line using make and fine in eclipse using build. But if I open the program file in eclipse it reports that it cannot reolve the isinf() function call. If I just insert the program contents into a new project and new source file, the error appears immediately. This problem did not occur under 11.04 with Eclipse Helios CDT
Questions:
Why are these errors only reported when the program file is opened and not on when the program is compiled; why are the errors not detected make is run from the command line? Is there a solution/workaround available?
Version Info
Linux Ubuntu 10.11 64-bit
Eclipse CDT Indigo, Service Release 1, Build id: 20110916-0149
(Also using Eclipse EE Indigo – if that makes a difference)
GNU Make 3.81
gcc 4.6.1-9Ubuntu3
To Duplicate:
Please find the two files you'll need to replicate below:
Step 0. Verify that everything is fine outside of Eclipse
Copy the attached source file and make file
create a directory e.g. Mkdir FunTest
Save the source file a 'Test.cpp' and the makefile as 'makefile'
Open a command prompt and navigate to the directory e.g. FunTest
Enter 'make'
Enter ./TestOut
Program responds “is not infinite”
Step 1. Create the project in Eclipse
Open Eclipse
Select File|New|MakeFile Project with Existing Code
Click Browse – navigate to the directory (FunTest) and click ok
Select 'Linux GCC' from the Toolchain selector
Click Finish
Step 2. Find the Error
Click Build All (Ctrl-B) – project builds without errors
Open the project in the project explorer to display the file in the directory
Double click on the file “Test.cpp”
Note the error icon next to line testing for infinity
Note the 2 error messages:
Semantic error: Function _isinff could not be resolved
Semantic error: Function _isinfl could not be resolved
Test.cpp:
include <math.h>
int main(int argc, char **argv)
{
int TestNum = 10;
if (isinf(TestNum) == 0)
printf("Not infinite\n");
return 0;
}
makefile:
# Specify the compiler
CC = g++
# Specify the compiler flags
CFLAGS += -c
# Specify the files making up the application
SOURCES = Test.cpp
OBJECTS = $(SOURCES:.cpp=.o)
EXECUTABLE = TestOut
all: $(EXECUTABLE)
$(EXECUTABLE): $(OBJECTS)
$(CC) $(LDFLAGS) $(OBJECTS) $(LDLIBS) -o $#
.cpp.o:
$(CC) $(CPPFLAGS) $(CFLAGS) $< -o $#
install:
#echo "Build complete!"
I have experienced similar problems of the CDT reporting errors even though the code compiled fine within Eclipse Indigo.
Project > Properties > Settings > Binary Parsers > "GNU Elf Parser"
helped in my case. I had the "Elf Parser" checked.
That looks like a problem that many others have had with eclipse CDT before. Sometimes shutting eclipse down and then starting it back up again is enough to help. If that isn't the case, take a look at what I have below:
Compilation ok, but eclipse content assist having problems
Check your includes: if you're using include<math.h> change it to include<cmath>. The same for stdio.h and stdlib.h, you should replace by cstdio and cstdlib. Another option may be change you project to a C project instead of a C++.
You are missing -lm option in your build preferences.
Project->Properties->Settings->Miscleanous->Other (linker) flags[]
For me, it was solved by adding a specific ‘Source Location’ folder, and removing the default. In Luna, it is under:
Project > Properties > C/C++ General > Paths and Symbols > Source
Location