MacOSX 10.7Undefined symbols for architecture x86_64

[Edit: Solution at the end]

Hi all,

For the past few days, I have been getting a weird problem with my ROOT library: “Undefined symbols for architecture x86_64:”. I used this configure:

./configure macosx64 --enable-shared --enable-rpath --enable-soversion --enable-table --enable-opengl --enable-mysql --enable-pgsql --enable-sapdb --all

I probably uninstalled and reinstalled ROOT 10 times in the past few days but the same error I can’t seem to fix is this one. I am using NetBeans with either clang++ or g++, or clang++ and g++ alone and it still gives me the same error.

I am using the exec3.C example.

If you have any idea, please let me know.

Thanks,

Cyrille

[quote]“/usr/bin/make” -f nbproject/Makefile-Release.mk QMAKE= SUBPROJECTS= .build-conf
“/usr/bin/make” -f nbproject/Makefile-Release.mk dist/Release/Clang-MacOSX/root_experiment
mkdir -p build/Release/Clang-MacOSX
rm -f build/Release/Clang-MacOSX/exec3.o.d
clang++ -time -v -c -g -s -MMD -MP -MF build/Release/Clang-MacOSX/exec3.o.d -o build/Release/Clang-MacOSX/exec3.o exec3.C
Apple clang version 3.0 (tags/Apple/clang-211.12) (based on LLVM 3.0svn)
Target: x86_64-apple-darwin11.3.0
Thread model: posix
clang: warning: argument unused during compilation: ‘-time’
clang: warning: argument unused during compilation: ‘-s’
“/usr/bin/clang” -cc1 -triple x86_64-apple-macosx10.7.3 -emit-obj -mrelax-all -disable-free -disable-llvm-verifier -main-file-name exec3.C -pic-level 1 -mdisable-fp-elim -relaxed-aliasing -masm-verbose -munwind-tables -target-cpu core2 -target-linker-version 127.2 -v -g -coverage-file build/Release/Clang-MacOSX/exec3.o -resource-dir /usr/bin/…/lib/clang/3.0 -dependency-file build/Release/Clang-MacOSX/exec3.o.d -MT build/Release/Clang-MacOSX/exec3.o -MP -fdeprecated-macro -ferror-limit 19 -fmessage-length 0 -stack-protector 1 -fblocks -fcxx-exceptions -fexceptions -fdiagnostics-show-option -o build/Release/Clang-MacOSX/exec3.o -x c++ exec3.C
clang -cc1 version 3.0 based upon llvm 3.0svn hosted on x86_64-apple-darwin11.3.0
ignoring nonexistent directory “/usr/include/c++/4.2.1/i686-apple-darwin10/x86_64”
ignoring nonexistent directory “/usr/include/c++/4.0.0”
ignoring nonexistent directory “/usr/include/c++/4.0.0/i686-apple-darwin8/”
ignoring nonexistent directory “/usr/include/c++/4.0.0/backward”
#include “…” search starts here:
#include <…> search starts here:
/usr/include/c++/4.2.1
/usr/include/c++/4.2.1/backward
/usr/local/include
/usr/bin/…/lib/clang/3.0/include
/usr/include
/System/Library/Frameworks (framework directory)
/Library/Frameworks (framework directory)
End of search list.
mkdir -p dist/Release/Clang-MacOSX
clang++ -time -v -arch x86_64 -o dist/Release/Clang-MacOSX/root_experiment build/Release/Clang-MacOSX/exec3.o -L/usr/local/lib/root -L/usr/local/lib -L/usr/local/include/root -llzma
Apple clang version 3.0 (tags/Apple/clang-211.12) (based on LLVM 3.0svn)
Target: x86_64-apple-darwin11.3.0
Thread model: posix
clang: warning: argument unused during compilation: ‘-time’
“/usr/bin/ld” -demangle -dynamic -arch x86_64 -macosx_version_min 10.7.3 -o dist/Release/Clang-MacOSX/root_experiment -lcrt1.10.6.o -L/usr/local/lib/root -L/usr/local/lib -L/usr/local/include/root build/Release/Clang-MacOSX/exec3.o -llzma -lstdc++ -lSystem /usr/bin/…/lib/clang/3.0/lib/darwin/libclang_rt.osx.a
Undefined symbols for architecture x86_64:
“_main”, referenced from:
start in crt1.10.6.o
“TVersionCheck::TVersionCheck(int)”, referenced from:
___cxx_global_var_init in exec3.o
“TH1F::TH1F(char const*, char const*, int, double, double)”, referenced from:
exec3() in exec3.o
“TCanvas::TCanvas(char const*, char const*, int)”, referenced from:
exec3() in exec3.o
“TQObject::Connect(char const*, char const*, void*, char const*)”, referenced from:
exec3() in exec3.o
“TObject::operator delete(void*)”, referenced from:
exec3() in exec3.o
“TStorage::ObjectAlloc(unsigned long)”, referenced from:
TObject::operator new(unsigned long) in exec3.o
“_gTQSender”, referenced from:
exec3event(int, int, int, TObject*) in exec3.o
“TCanvasImp::Class()”, referenced from:
TCanvasImp::IsA() const in exec3.o
“TCanvasImp::ShowMembers(TMemberInspector&)”, referenced from:
vtable for TCanvasImp in exec3.o
“TCanvasImp::Streamer(TBuffer&)”, referenced from:
vtable for TCanvasImp in exec3.o
ld: symbol(s) not found for architecture x86_64
clang: error: linker command failed with exit code 1 (use -v to see invocation)
make[2]: *** [dist/Release/Clang-MacOSX/root_experiment] Error 1
make[1]: *** [.build-conf] Error 2
make: *** [.build-impl] Error 2[/quote]

===============Solution===============

The problem was that when I compiled the program, I did not pass on the right flags to the linker. Here’s what needs to be added:

To figure this out, I used the following link, compiled in XCode and looked at how XCode was configured and noticed the differences with my NetBeans configuration.

This may not be the only reason why you’d get this error but this fixed it for me.

Where exactly does this need to be added?