View Full Version : linking error with g++

Aug 25, 2008, 11:00 PM

I am having difficulty linking using make created by Eclipse CDT.

My setup is the following:

- Mac Intel Code 2 Duo
- OS X 10.5.4 (fully patched)
- XCode 3.1
- Eclipse 3.4 (Ganymede) CDT
- Darwin ports 1.6.0
- cppunit 1.12.1

So cppunit libraries are located in /opt/local/lib/
and the header files are located in /opt/local/include

here is the result on the make session

**** Build of configuration Debug for project mycpptest ****

make all
Building file: ../src/main.cpp
Invoking: GCC C++ Compiler
g++ -I/opt/local/include -O0 -g3 -Wall -c -fmessage-length=0 -MMD -MP -MF"src/main.d" -MT"src/main.d" -o"src/main.o" "../src/main.cpp"
Finished building: ../src/main.cpp

Building target: mycpptest
Invoking: MacOS X C++ Linker
g++ -L/opt/local/lib -o "mycpptest" ./src/main.o -llibcppunit.a
ld: library not found for -llibcppunit.a
collect2: ld returned 1 exit status
make: *** [mycpptest] Error 1

The file libcppunit.a is really located in /opt/local/lib, I have verified.

I have tried multiple combinasons with the -L and -l parameters
with no success

For some reasons, the linker does not seems to like the library ???

Any suggestions ...



PS: To validate the code and library I have created a project using XCode
and the file compile, link and run correctly.

Aug 26, 2008, 12:37 AM
First, try just -lcppunit. The linker usually adds the 'lib' prefix and any suffixes itself and is confused since you're giving it the entire library name.

If that doesn't work, IIRC, .a static libraries can simply be passed in as another linking unit. So, instead of using -l, just add /opt/local/lib/libcppunit.a as one of the parameters.

Aug 26, 2008, 09:54 PM
thank you kpua

specifying -lcppunit worked.

Thanks again! :)

Jun 23, 2010, 04:42 AM
For me the second option works:
specifying with -L and -l flags did not work.

just adding /usr/local/lib/foo.a as parameter worked:
g++ test.cpp /usr/local/lib/foo.a