g++ library search failure

Posted by Frederick on Stack Overflow See other posts from Stack Overflow or by Frederick
Published on 2012-03-24T11:11:28Z Indexed on 2012/03/24 11:29 UTC
Read the original article Hit count: 135

Filed under:
|
|

I have a directory structure as below:

/
|
+--- /lib
|      libsomething.a
|      libsomething.so
|
+----/obj
       anObjFile.o

When I run the following command from within the obj directory:

g++ -L../lib -lsomething anObjFile.o

I get undefined reference errors. Apparently gcc is failing to locate libsomething.a.

But now if I delete libsomething.so and then rerun the command, linking succeeds.

As per gcc documentation -lsomething should expand to libsomething.a. Then why is presence of libsomething.so causing the library search to fail? Also, how can I resolve this problem?

I'm on Linux Mint 12 with gcc version 4.6.1.

© Stack Overflow or respective owner

Related posts about gcc

Related posts about linker