Author Topic: undefined reference to fuctions in my library  (Read 3983 times)

Offline lirong

  • Single posting newcomer
  • *
  • Posts: 8
undefined reference to fuctions in my library
« 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,

Offline MortenMacFly

  • Administrator
  • Lives here!
  • *****
  • Posts: 9604
Re: undefined reference to fuctions in my library
« Reply #1 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.
Compiler logging: Settings->Compiler & Debugger->tab "Other"->Compiler logging="Full command line"
C::B Manual: http://www.codeblocks.org/docs/main_codeblocks_en.html
C::B FAQ: http://wiki.codeblocks.org/index.php?title=FAQ

Offline lirong

  • Single posting newcomer
  • *
  • Posts: 8
Re: undefined reference to fuctions in my library
« Reply #2 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".

Offline dje

  • Lives here!
  • ****
  • Posts: 683
Re: undefined reference to fuctions in my library
« Reply #3 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

Offline lirong

  • Single posting newcomer
  • *
  • Posts: 8
Re: undefined reference to fuctions in my library
« Reply #4 on: August 16, 2007, 09:40:27 am »
The output is something like "foo.so"

Offline lirong

  • Single posting newcomer
  • *
  • Posts: 8
Re: undefined reference to fuctions in my library
« Reply #5 on: August 16, 2007, 10:15:09 am »
Hi,
How can I show the command line of the compile/link?

Thanks

Offline lirong

  • Single posting newcomer
  • *
  • Posts: 8
Re: undefined reference to fuctions in my library
« Reply #6 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?

Offline jsibarani

  • Multiple posting newcomer
  • *
  • Posts: 31
Re: undefined reference to fuctions in my library
« Reply #7 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

Offline dje

  • Lives here!
  • ****
  • Posts: 683
Re: undefined reference to fuctions in my library
« Reply #8 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