views:

130

answers:

3

I'm writing a dylib in C++, but when I try to link it into my application, it gives me an error on execution:

dyld: lazy symbol binding failed: Symbol not found: __ZN8Vector2DC1Ev
  Referenced from: /Users/noahz/Desktop/Singularity/Singularity Test App/build/Debug/Singularity Test App
  Expected in: /Users/noahz/Desktop/Singularity/Singularity Test App/build/Debug/libSingularity.dylib

dyld: Symbol not found: __ZN8Vector2DC1Ev
  Referenced from: /Users/noahz/Desktop/Singularity/Singularity Test App/build/Debug/Singularity Test App
  Expected in: /Users/noahz/Desktop/Singularity/Singularity Test App/build/Debug/libSingularity.dylib

I made sure the symbol wasn't stripped, and

nm -g libSingularity.dylib  | grep "T" | grep __ZN8Vector

reports that the symbol is present in the library:

0000000000006df6 T __ZN8Vector2DC1Eff
0000000000006d98 T __ZN8Vector2DC1Ev
0000000000006dc2 T __ZN8Vector2DC2Eff
0000000000006d6e T __ZN8Vector2DC2Ev

I'm linking from inside XCode, so the link commands are kind of weird. Here's the linker command for the dylib:

Ld "/Users/noahz/Desktop/Singularity/Singularity Engine/build/Debug
    /libSingularity.dylib" normal x86_64
cd "/Users/noahz/Desktop/Singularity/Singularity Engine"
setenv MACOSX_DEPLOYMENT_TARGET 10.6
/Developer/usr/bin/g++-4.2 -arch x86_64 -dynamiclib -isysroot /Develope
    /SDKs/MacOSX10.6.sdk "-L/Users/noahz/Desktop/Singularity/Singularity Engine/build
    /Debug" "-F/Users/noahz/Desktop/Singularity/Singularity Engine/build/Debug"
    -filelist "/Users/noahz/Desktop/Singularity/Singularity Engine/build/Singularity 
    Engine.build/Debug/Singularity Engine.build/Objects-normal/x86_64
    /libSingularity.LinkFileList" -install_name libSingularity.dylib -mmacosx-version-
    min=10.6 -framework sfml-system-d -framework sfml-window-d -framework SFML 
    -framework OpenGL -framework OpenAL -framework sfml-graphics-d -single_module 
    -compatibility_version 1 -current_version 1 -o "/Users/noahz/Desktop/Singularity
    /Singularity Engine/build/Debug/libSingularity.dylib"

and here's the linker command for the test app:

cd "/Users/noahz/Desktop/Singularity/Singularity Test App"
setenv MACOSX_DEPLOYMENT_TARGET 10.6
/Developer/usr/bin/g++-4.2 -arch x86_64 -isysroot /Developer/SDKs/MacOSX10.6.sdk 
    "-L/Users/noahz/Desktop/Singularity/Singularity Test App/build/Debug" "-F/Users
    /noahz/Desktop/Singularity/Singularity Test App/build/Debug" -filelist "/Users/noahz
    /Desktop/Singularity/Singularity Test App/build/Singularity Test App.build/Debug
    /Singularity Test App.build/Objects-normal/x86_64/Singularity Test 
    App.LinkFileList" -mmacosx-version-min=10.6 "/Users/noahz/Desktop/Singularity
    /Singularity Engine/build/Debug/libSingularity.dylib" -o "/Users/noahz/Desktop
    /Singularity/Singularity Test App/build/Debug/Singularity Test App"

Any ideas on why this is happening and/or how to fix it?

A: 

If your application differs in architecture x86/64 from the library you are trying to load, that might explain the problem you're having.

Both must be compiled with the same architecture.

karlphillip
A: 

I don't see a line in your link stage

-lSingularity

apparently another way to load a dynamic library is to explicity load it from within the code.

gSystem->Load("libSingularity");

I'm just paraphrasing a blog article I found.

http://root.cern.ch/phpBB3//viewtopic.php?f=3&t=10380&start=0

bradgonesurfing
The libraries SEEM to link okay (another class can be instantiated and used fine) but when I create a Vector, it crashes.
computergeek6
try using ldd on the executable. ldd will tell you where all you dynamic libraries resolve to.
bradgonesurfing
apparently, ldd doesn't work on MacOS
computergeek6
A: 

I solved the problem by linking the library statically. It's not as elegant as dynamic linking was, but at least it doesn't crash repeatedly.

computergeek6