Code::Blocks Forums

User forums => Using Code::Blocks => Topic started by: lirong on August 16, 2007, 05:34:39 am

Title: undefined reference to fuctions in my library
Post by: lirong on August 16, 2007, 05:34:39 am
Hi,
I have two project in one workspace.  One is a shared library libproject.  Another is a program using the library project-test.  I have set the project dependency so that project-test depends on libproject.  However, when I tried to build project-test, I got errors about undefined reference to functions of libproject.  How can I solve this problem?

Regards,
Title: Re: undefined reference to fuctions in my library
Post by: MortenMacFly on August 16, 2007, 07:48:39 am
I got errors about undefined reference to functions of libproject.  How can I solve this problem?
You not only need the reference but you also (and most important) need to *link* against this library. Project dependencies is for the build order - that way the lib is built before the executable if it's sources are modified.
With regards, Morten.
Title: Re: undefined reference to fuctions in my library
Post by: lirong on August 16, 2007, 09:29:31 am
I tried add "../bin/Debug" to linker search path, and added "project" to "Link Library".  Now I get "/usr/bin/ld: connot find -lproject".
Title: Re: undefined reference to fuctions in my library
Post by: dje on August 16, 2007, 09:33:19 am
if your output is libfoo.a, you have to put foo in your linker libraries.
It has nothing to do with your project name, as your project name is not necessary used in output file.

Dje
Title: Re: undefined reference to fuctions in my library
Post by: lirong on August 16, 2007, 09:40:27 am
The output is something like "foo.so"
Title: Re: undefined reference to fuctions in my library
Post by: lirong on August 16, 2007, 10:15:09 am
Hi,
How can I show the command line of the compile/link?

Thanks
Title: Re: undefined reference to fuctions in my library
Post by: lirong on August 16, 2007, 10:25:23 am
The project of the library is call libodlm. It's output is ../bin/Debug/odlm.so
The test project is called odlm-test.  It's output is ../bin/Debug/odlm-test

Here is the full command line linking odlm-test:
g++ -L../bin/Debug -L/usr/lib -o ../bin/Debug/odlm-test ../obj/Debug/main.o -lodlm

And odlm.so is indeed in the folder ../bin/Debug

So... What's the problem?
Title: Re: undefined reference to fuctions in my library
Post by: jsibarani on August 16, 2007, 12:40:15 pm
The project of the library is call libodlm. It's output is ../bin/Debug/odlm.so
The test project is called odlm-test.  It's output is ../bin/Debug/odlm-test

Hi,
Did you also create the import library?
if you did, then you can try to link with it(something like libodlm.a)

Good luck
Title: Re: undefined reference to fuctions in my library
Post by: dje on August 16, 2007, 01:55:03 pm
*.so on Linux = *.dll on windows
import libraries are Windows specific and are one way to export symbols that can be used outside the dll.
Don't try to use import libraries on Linux.

Dje