I am trying to build an small sample CUDA code matrixMul.cu in XCode 4.5.2. I did:
a custom script which runs nvcc to compile the .cu file to an object file.
then let xcode to link it with cuda lib to produce the final executable matrixMul
However, in the linking stage, xcode always runs gcc on the .o file instead of g++, and becos of this it results in error:
/Applications/Xcode.app/Contents/Developer/usr/bin/gcc -arch x86_64 -isysroot ...
Undefined symbols for architecture x86_64:
"std::ios_base::Init::Init()", referenced from:
__static_initialization_and_destruction_0(int, int)in matrixMul.o
"std::ios_base::Init::~Init()", referenced from:
___tcf_0 in matrixMul.o
ld: symbol(s) not found for architecture x86_64
collect2: ld returned 1 exit status
I don't know how to make XCode to run g++ instead of gcc to link the object file. I have only the .cu file in the project so no .cpp to indicate it's c++. However, I DO choose C++ when I created the xcode project in the very beginning. It runs gcc for me regardless I choose Apple LLVM compiler or LLVM GCC in the build settings.
Thank you!
Gary
It turns out that I can't force XCode to use g++ for linkage, but has a workaround where I add -lstdc++ to the "Other linker flags" section, making gcc link the c++ lib for me.
It works for now, but I am not too sure if this the only/best solution. Please let me know if anyone has other solution.
Gary
Related
I am making a project in Mac OSX and use the boost compiled libraries (serialisation amongst others). I installed all my dependencies as x86_64 libraries, but now want to make explicitly 32 bit ones (i386) and recompile my project for 32bit users.
I have recompiled by libraries with g++ -m32 where appropriate and then re made 32 bit boost libraries using
./bootstrap.sh link=static
./b2 cflags=-m32 cxxflags=-m32 address-model=32 threading=multi architecture=x86 instruction-set=i686
I then recompile my project by explicitly linking to the 32 bit libraries. So something like
g++ file.cpp /usr/local/lib/boost_i386/libboost_serialization.a -m32 -o executable
where the library is explicitly the 32 bit version verified by using otool as follows with (partial) output (all list cputype as i386)
otool -hv -arch all libboost_serialization.a
Archive : libboost_serialization.a
libboost_serialization.a(basic_archive.o):
Mach header
magic cputype cpusubtype caps filetype ncmds sizeofcmds flags
MH_MAGIC I386 ALL 0x00 OBJECT 3 1180 SUBSECTIONS_VIA_SYMBOLS
However, when I compile my project (despite most dependencies working fine), it trips up and that symbols are missing for this architecture
Explicitly:
Undefined symbols for architecture i386:
"boost::archive::detail::shared_ptr_helper::shared_ptr_helper()", referenced from:
boost::archive::binary_iarchive::binary_iarchive(std::basic_istream<char, std::char_traits<char> >&, unsigned int)in ccCH1ama.o
"boost::archive::detail::shared_ptr_helper::~shared_ptr_helper()", referenced from:
boost::archive::binary_iarchive::~binary_iarchive()in ccCH1ama.o
boost::archive::binary_iarchive::~binary_iarchive()in ccCH1ama.o
ld: symbol(s) not found for architecture i386
collect2: ld returned 1 exit status
I have explicitly built the 32bit libraries, checked they are in fact 32 bit, and explicitly linked to them, I don't know what else to do. Any ideas?
Turns out the header files were boost v1.55 but the i386 libraries used the most current version v1.57. This caused the error. Building the libraries with the older v1.55 to match the headers fixed the problem.
I am trying to build a library that only has static references to libgfortran (and preferably libgcc also).
However, if I use the linker flags
-static -lgfortran -static-libgfortran -static-libgcc
on OS X I get
ld: library not found for -lcrt0.o
collect2: error: ld returned 1 exit status
and if I try to use
-shared -lgfortran -static-libgfortran
I get
Undefined symbols for architecture x86_64:
"_quadmath_snprintf", referenced from:
_write_float in libgfortran.a(write.o)
"_strtoflt128", referenced from:
__gfortrani_convert_real in libgfortran.a(read.o)
__gfortrani_convert_infnan in libgfortran.a(read.o)
and everything compiles fine (but has a dynamic link to libgfortran and libgcc) if I use -dynamiclib -lgfortran.
It would appear that gcc is not build statically on OS X.
How do I build my library so that end-users don't need to have gfortran or gcc installed?
I'm using the macports version of gcc but I'm prepared to use another distributor of gfortran/gcc if it allows me to do this.
-dynamiclib -lgfortran -static-libgfortran \
/opt/local/lib/gcc47/libquadmath.a -static-libgcc
seems to do the trick!
The bizarre thing was figuring out that I needed to add a full path to the libquadmath.a, which feels like a bug with gcc/gfortran to be honest.
I am trying to compile boost C++ using clang.
./b2 --prefix=~/boost --includedir=~/boost/include --libdir=~/boost/lib toolset=clang cxxflags="-std=c++11 -stdlib=libc++ -isystem ~/libcxx/include/" linkflags="-stdlib=libc++ -L ~/libcxx/lib/"
When I see log file it gives error saying
Undefined symbols for architecture x86_64:
"boost::system::system_category()", referenced from:
__GLOBAL__I_a in exceptions.o
"boost::system::generic_category()", referenced from:
__GLOBAL__I_a in exceptions.o
ld: symbol(s) not found for architecture x86_64
clang: error: linker command failed with exit code 1 (use -v to see invocation)
my default clang is clang-mp-3.3. Can anyone please help me figure out what this problem is.
After searching for the reason of error in the web I found this which explain about compiling boost with clang. I am not sure why adding define=BOOST_SYSTEM_NO_DEPRECATED made it worked. Please do comment anyone who knows why it worked. I was then able to compile with no error but I still see some warnings but it worked for me for now.
The default clang I am using is (clang-mp-3.3)
$ clang -v
clang version 3.3 (tags/RELEASE_33/final)
Target: x86_64-apple-darwin11.4.2
Thread model: posix
./bootstrap.sh --with-toolset=clang --without-libraries=mpi,python,graph_parallel
./b2 clean
./b2 toolset=clang cxxflags="-std=c++11 -stdlib=libc++" linkflags="-stdlib=libc++" define=BOOST_SYSTEM_NO_DEPRECATED
I'm trying to make dynamic lib from set of .o files, but when i do
gcc -dynamiclib -current_version 1.0 mymod.o -o mylib.dylib
or
ld *.o -o mylib.dylib
i get a lot of errors like:
"_objc_msgSend", referenced from:
-[NSObject(NSObject_SBJSON) JSONFragment] in NSObject+SBJSON.o
"operator new(unsigned long)", referenced from:
MStatistic::instance() in MStatistic.o
StatisticProfileLoggingObserver::instance() in StatisticObserver.o
ld: symbol(s) not found for architecture x86_64
Can you please help me, how to solve it and get my .dylib?
You can pass -undefined dynamic_lookup as an option to ld, or:
-Wl,-undefined -Wl,dynamic_lookup to gcc or clang (which passes it to the linker).
From this line:
ld: symbol(s) not found for architecture x86_64
it sounds like you are building some libraries that have make files that only build for 32-bit architectures.
You need to modify the makefiles for all the libraries / frameworks you're building to build both 32-bit and 64-bit; and in a practical sense, all shipping MacOS machines are 64-bit capable so it may just be safe to build only for 64-bit.
In your compile / linking lines, add something like this: "-arch x86_64" and that should compile things for the 64-bit side. To do both 32 & 64-bit, you'll basically need to duplicate the compile & link lines with their own "-arch i386" and "-arch x86_64" lines.
I am trying to implement openssl code I found into my project but I get these linker errors that aren't going away. I checked that the frameworks are properly linked and even included the library and header search paths manually using ../lib and ../include. Despite this the error goes away when I get rid of the Openssl function or any function calls such as EVP_OpenUpdate or EVP_OpenInit. This only if I create and then call the function from my ViewController.h file for some reason.
Here is the log of the error:
Ld /Users/User/Library/Developer/Xcode/DerivedData/LineaSSL-clrggexngizkqqbtcxpnmsciuwag/Build/Products/Debug-iphoneos/LineaSSL.app/LineaSSL normal armv7
cd /Users/User/Documents/LineaSSL
setenv IPHONEOS_DEPLOYMENT_TARGET 4.0
setenv PATH "/Applications/Xcode.app/Contents/Developer/Platforms/iPhoneOS.platform/Developer/usr/bin:/Applications/Xcode.app/Contents/Developer/usr/bin:/usr/bin:/bin:/usr/sbin:/sbin"
/Applications/Xcode.app/Contents/Developer/Toolchains/XcodeDefault.xctoolchain/usr/bin/clang -arch armv7 -isysroot /Applications/Xcode.app/Contents/Developer/Platforms/iPhoneOS.platform/Developer/SDKs
/iPhoneOS5.1.sdk -L/Users/User/Library/Developer/Xcode/DerivedData/LineaSSL-clrggexngizkqqbtcxpnmsciuwag/Build/Products/Debug-iphoneos -L/Users/User/Documents/LineaSSL/../../Desktop/x2on-OpenSSL-for-iPhone-a095890/OpenSSL-for-iOS/lib -L/Users/User/Documents/LineaSSL/../../Downloads/DTDevices-iOS_2012-06-15_v1/Library -L/Users/User/Documents/LineaSSL/OpenSSL-for-iOS/lib -L/Users/User/Documents/LineaSSL/lib -F/Users/User/Library/Developer/Xcode/DerivedData/LineaSSL-clrggexngizkqqbtcxpnmsciuwag/Build/Products/Debug-iphoneos -Finclude -Finclude/openssl -filelist /Users/User/Library/Developer/Xcode/DerivedData/LineaSSL-clrggexngizkqqbtcxpnmsciuwag/Build/Intermediates/LineaSSL.build/Debug-iphoneos/LineaSSL.build/Objects-normal/armv7/LineaSSL.LinkFileList -dead_strip -miphoneos-version-min=4.0 -lcrypto -lssl -framework CoreGraphics -framework ExternalAccessory -framework Foundation -framework UIKit -ldtdev -o /Users/User/Library/Developer/Xcode/DerivedData/LineaSSL-clrggexngizkqqbtcxpnmsciuwag/Build/Products/Debug-iphoneos/LineaSSL.app/LineaSSL
ld: warning: ignoring file /Users/User/Desktop/x2on-OpenSSL-for-iPhone-a095890/OpenSSL-for-iOS/lib/libcrypto.a, file was built for archive which is not the architecture being linked (armv7)
ld: warning: ignoring file /Users/User/Desktop/x2on-OpenSSL-for-iPhone-a095890/OpenSSL-for-iOS/lib/libssl.a, file was built for archive which is not the architecture being linked (armv7)
Undefined symbols for architecture armv7:
"_rsa_open3", referenced from:
-[ViewController barcodeData:isotype:] in ViewController.o
ld: symbol(s) not found for architecture armv7
clang: error: linker command failed with exit code 1 (use -v to see invocation)
Please let me know what I should do in regards to this error.
Thanks in advance.
I had to rebuild the entire project from scratch in order to get it to work. I don't know why I had to do such a thing though.