I have a problem in building a c thread program. Program is giving error like
"undefined reference to pthread_creat".
I searched and found to use gcc options like
"gcc -lpthread -o ...."
But I not able to set it for eclipse. I tried to make change in makefile but every time it got replaced with default options. Please help me to set these gcc options and write about where and how to set gcc options in eclipse on fedora 10.
Thanks,
Lokesh
to add pthread library to your project flow these steps (in eclipse):
right cklick on the project in the project explorer -> properties -> c/c++ build -> Settings -> linker -> libraries -> add -> pthread -> ok -> rebuild
Check this 'tutorial' on about how to setup eclipse for developing posix threads.
Hope it helps.
To add pthread library to your non-makefile project, do following steps (in eclipse):
right click on the project in the project explorer. Select properties -> c/c++ general -> Paths and Symbols -> libraries -> add -> type 'pthread' in text box -> ok -> ok -> rebuild
Related
I'm new using Eclipse for programming in C.
I have several doubts and although I found a lot of questions related to it, by now I don't get to solve my problems.
I have a C project with several source files(.c), header files(.h), a Makefile and an archive library (.a). Until now, I have been editing my code with a editor (gedit) and I have been compiling it with the terminal. I run "make" on the terminal and several shared object libraries (.so) are generated and in addittion, an executable file.
Now, I want to use Eclipse with CDT to programme and compile the code. My first doubt is the type of project that I must choose:
Executable or Makefile project?
I selected the "Executable" type. Then I tried to build the project and I got a lot of errors due to "undefined references" and several error messages with "relocation x has invalid symbol index".
I did the following steps:
Properties -> C/C++ General -> Path and Symbols -> Includes -> GNU C -> Add -> Filesystem ->
I put the project folder, since the header files are in this folder (with absolute path). Then "Clean project" and "Build project". It didn't work, and I got the same errors
Later, I tried:
Properties -> C/C++ Build -> GCC C Linker -> Miscellaneous -> Other objects ->
I put the archive file (.a). Then "Clean project" and "Build project".
The previous problems didn't occur, but I got other "undefined references" with files related to the archive file and I can't access them.
I appreciate any help.
I'm sorry if someone already asked this question, but I searched a lot before I write it.
Thanks
I run "make" on the terminal and several shared object libraries (.so) are generated and in addittion, an executable file.
Each .so and each executable should be a separate project in your workspace.
I have been trying to find a way to install the iniparser library to write configuration files for C programs in eclipse, the whole day today. But I have not been able to find anything usefull. I am using Windows 7 (64 bit).
I have tried downloading the zip file and loading it into the 'lib' folders of eclipse. But when I try to include it into the C program it gives me a error saying 'iniparser.h' not found.
Can somebody PLEASE tell me how can I do this?? I would really be thankfull..
You can include path-
Try-
Project -> properties -> C/C++General -> Paths and Symbols -> Includes tab -> Assembly
while checking 'add to all languages'.
This one did not work for me- Project -> Properties -> C/C++General -> Paths and Symbols -> Includes tab -> GCC C
I am new to C programming.
I was trying to use the pthread API to write some concurrent program.
I downloaded eclipse IDE for C/C++ Developers, MinGW. I have put all the library, header files into the corresponding location of the MinGW file.
When I tried to build the project, there is always an error "cannot find -lpthread", what happened?
I have added the "-pthread" to the GCC compiler.
I have searched a lot in Google but seems no one have similar problem as me.
The answer to this question by someone who is also missing MinGW pthread library should help you out! Essentially the issue is that the MinGW installer script might not download the lpthread library upon installation. Quoted from link:
Just run and open MinGW Installation Manager, which should be pre-installed with MinGW, select "All Packages" on the left panel, and on the right panel, search for "mingw32-pthreads-w32" packages and install them.
I downloaded eclipse IDE for C/C++ Developers, MinGW.
MingGW uses the Windows API. The Windows API does not provide PThreads.
You need to install PThreads for Win32 to have PThreads available under Windows, and with this available under MinGW.
Eclipse is not configured to put the -pthread argument in the gcc compilation. To solve this, go to the Menu:
view sourceprint?
1.Project -> Properties
From the bar on the left:
view sourceprint?
1.c/c++ build -> GCC C Compiler -> Miscellaneous
Add the “-pthread” argument into the beginning of the “Other Flags” Also go to:
view sourceprint?
1.c/c++ build -> Settings -> GCC C Linker -> Libraries
And include the “pthread”library into the other libraries. Click Apply and rebuild the project. Pthreads must work now.
See the question on mingw.org. I ended up with adding 'C:/cygwin/lib' to the settings for the "Library search path (-L)" at properties >> c/c++ build >> settings >> MinGW C Linker >> Libraries.
I need to add a C library to C project in Eclipse indigo.
What I've done so far.
I've downloaded and installed the library.
All headers are in folder /usr/include, library.so files are in folder /usr/lib.
After having read a tutorial I tried to do it like this:
When in Eclipse -> Project -> C/C++ Build -> Settings -> GCC C Linker -> Libaries -> Add libary -> "ibxml2" ( library name is libxml2 )
But it still doesn't work.
I am a super newbie at Linux, so please could you give me some advise how to do that?
By the way one more thing. After creating a new C/C++ Project when I run an error occurs " Launch failed! Binary not found". I checked "Binary Parsers" in Project's Settings and "Elf Parser" is set ( I've read that it is OK for Linux ), so what is wrong? It is not so important, since it works when I first only build project and then run it, but maybe there is a way to solve that too?
In linker options, you should not add "libxml2", but just "xml2". All binary libraries in Linux (so files) have a "lib" prefix that is not a part of library name.
I have installed OpenCV C libraries from package management into my Kubuntu 9.10. I wrote a small image modification program that uses those libraries, but I can't compile it, because every time I try to compile I get the error message that the functions from OpenCV library cannot be found.
Those header files are in folder /usr/include/opencv/ but still the compiler says that functions cannot be found.
I have tried to include them by basic
#include <highgui.h>
#include <cv.h>
commands in netbeans (and I have set netbeans to search header files from that specific directory) and also tried to include them with full path.
#include </usr/include/opencv/highgui.h>
#include </usr/include/opencv/cv.h>
Also I tried to compile my source file in console (with full path includes), but again I got the same error message that the functions from those libraries cannot be found.
Edit:
The error message that I get is
undefined reference to 'function_name'
I get that error for every function that I try to use from that opencv library.
Any idea how to fix that problem?
Edit II:
in case someone else is using netbeans 6.7.1 and has the same problem, here's the solution copy pasted from another website:
Here I presume that you have succesfully installed the opencv library either manually or via package management.
Open Netbeans then do the following:
Select Tools -> Options -> C/C++ -> Code Assistance -> add Include Directories
(For me, /usr/local/include/opencv)
Create new project, then:
Right click on Project Name -> Properties ->Build -> C/C++ Compiler -> Include Directories
Include Directories : /usr/local/include/opencv
Right click on Project Name -> Properties -> Build -> linker ->
Include Directories : /usr/local/include/opencv
Additional Options : -I/usr/local/include/opencv -L/usr/local/lib -lcxcore -lcv -lhighgui -lcvaux -lml
Then writing program and compile!!
"undefined reference to" is a linker error. You forgot to link your application against the OpenCV libraries. Make sure you link against cv and highgui (-lcv -lhighgui) or use the pkg-config call that Tobu provided. I'd also second the request for more detailed error messages.
OpenCV uses pkg-config, the standard way to locate libraries and headers on unix. You can run (untested):
make CFLAGS="$(pkg-config --cflags --libs opencv)" your-program