News:

Accounts with zero posts and zero activity during the last months will be deleted periodically to fight SPAM!

Main Menu

undefined reference to fuctions in my library

Started by lirong, August 16, 2007, 05:34:39 AM

Previous topic - Next topic

lirong

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,

MortenMacFly

Quote from: lirong on August 16, 2007, 05:34: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.
Compiler logging: Settings->Compiler & Debugger->tab "Other"->Compiler logging="Full command line"
C::B Manual: [url="https://www.codeblocks.org/docs/main_codeblocks_en.html"]https://www.codeblocks.org/docs/main_codeblocks_en.html[/url]
C::B FAQ: [url="https://wiki.codeblocks.org/index.php?title=FAQ"]https://wiki.codeblocks.org/index.php?title=FAQ[/url]

lirong

I tried add "../bin/Debug" to linker search path, and added "project" to "Link Library".  Now I get "/usr/bin/ld: connot find -lproject".

dje

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

lirong


lirong

Hi,
How can I show the command line of the compile/link?

Thanks

lirong

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?

jsibarani

Quote from: 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

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

dje

*.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