PDA

View Full Version : undefined references-- different requirements for static and dynamic libraries?



stair314
June 27th, 2009, 02:22 AM
Say that I want to link foo.cpp against a library bar. I've found that if I declare a function myFunc() in bar but don't define it, I can use bar.a as long as foo.cpp doesn't call myFunc(), but if I try to use bar.so I will get an undefined reference error.
Is this because there is a requirement that dynamic libraries define all the functions they declare and no such requirement for static libraries, or have I botched something else up?
The reason I am doing this is that some of the functions in bar are based on CUDA and I want it to be possible to compile on the cpp part of bar on machines that don't have CUDA.

wojox
June 27th, 2009, 02:29 AM
Undefined references occur in programs when a program tries to access a variable that has not previously been declared.

stair314
June 27th, 2009, 02:34 AM
That's neither an answer to my question nor, technically, true.

monraaf
June 27th, 2009, 02:43 AM
The reason I am doing this is that some of the functions in bar are based on CUDA and I want it to be possible to compile on the cpp part of bar on machines that don't have CUDA.

Use dlopen and dlsym for that.

stair314
June 27th, 2009, 02:56 AM
Thanks for the advice. I'm hoping to keep it cross-platform though. Unfortunately, other people who use the library are silly enough to use Windows.