linking boost serialisation static library in XCode 4.5.2 c++ project - c++

I’m building an application on Mac OSX 10.8 (Mountain Lion) and I’m getting a linkage error relating to a Boost library (serialisation.a). I’m using other Boost binaries in the same project and they’re not throwing up any problems, so I’m pretty confident that I’ve built the libraries correctly (I elected to build the entire suite of libraries for the Darwin toolset). For the same reason, I’m reasonably confident that my linker path is set correctly. I know there aren’t many Mac developers on this list, but I’m wondering if anybody can offer any suggestions. The project is handled by XCode 4.5.2 and uses the GCC 4.2 compiler. The following is the output from the build (I’ve only included the first error – all of the rest are variations on a theme and all refer to Boost::archive or Boost::serialisation (both of which are contained within the Boost serialisation.a static library file).
Ld /Users/tim/Library/Developer/Xcode/DerivedData/SurfaceReader-fwryryuvfvwihnglkuymbbjtxpac/Build/Products/Debug/SurfaceReader.app/Contents/MacOS/SurfaceReader normal x86_64
cd /Users/tim/Developer/SurfaceReader
setenv MACOSX_DEPLOYMENT_TARGET 10.8
/Applications/Xcode.app/Contents/Developer/usr/bin/llvm-g++-4.2 -arch x86_64 -isysroot /Applications/Xcode.app/Contents/Developer/Platforms/MacOSX.platform/Developer/SDKs/MacOSX10.8.sdk -L/Users/tim/Library/Developer/Xcode/DerivedData/SurfaceReader-fwryryuvfvwihnglkuymbbjtxpac/Build/Products/Debug -L/users/tim/developer/libraries/boost_1_50_0/lib -L/users/tim/developer/libraries/cryptopp561 -F/Users/tim/Library/Developer/Xcode/DerivedData/SurfaceReader-fwryryuvfvwihnglkuymbbjtxpac/Build/Products/Debug -filelist /Users/tim/Library/Developer/Xcode/DerivedData/SurfaceReader-fwryryuvfvwihnglkuymbbjtxpac/Build/Intermediates/SurfaceReader.build/Debug/SurfaceReader.build/Objects-normal/x86_64/SurfaceReader.LinkFileList -mmacosx-version-min=10.8 -L/Users/tim/developer/libraries/wxwidgets-2.9.4/build-debug/lib -framework IOKit -framework Carbon -framework Cocoa -framework AudioToolbox -framework System -framework OpenGL /Users/tim/developer/libraries/wxwidgets-2.9.4/build-debug/lib/libwx_osx_cocoau_xrc-2.9.a /Users/tim/developer/libraries/wxwidgets-2.9.4/build-debug/lib/libwx_osx_cocoau_webview-2.9.a /Users/tim/developer/libraries/wxwidgets-2.9.4/build-debug/lib/libwx_osx_cocoau_qa-2.9.a /Users/tim/developer/libraries/wxwidgets-2.9.4/build-debug/lib/libwx_baseu_net-2.9.a /Users/tim/developer/libraries/wxwidgets-2.9.4/build-debug/lib/libwx_osx_cocoau_html-2.9.a /Users/tim/developer/libraries/wxwidgets-2.9.4/build-debug/lib/libwx_osx_cocoau_adv-2.9.a /Users/tim/developer/libraries/wxwidgets-2.9.4/build-debug/lib/libwx_osx_cocoau_core-2.9.a /Users/tim/developer/libraries/wxwidgets-2.9.4/build-debug/lib/libwx_baseu_xml-2.9.a /Users/tim/developer/libraries/wxwidgets-2.9.4/build-debug/lib/libwx_baseu-2.9.a -framework WebKit -lexpat -lwxregexu-2.9 -lwxtiff-2.9 -lwxjpeg-2.9 -lwxpng-2.9 -lz -lpthread -liconv -stdlib=libc++ -fobjc-arc -fobjc-link-runtime -framework CoreMIDI -framework CoreAudio -framework Cocoa -lboost_filesystem -lboost_iostreams -lboost_serialization -lboost_system -lcryptopp -o /Users/tim/Library/Developer/Xcode/DerivedData/SurfaceReader-fwryryuvfvwihnglkuymbbjtxpac/Build/Products/Debug/SurfaceReader.app/Contents/MacOS/SurfaceReader
Undefined symbols for architecture x86_64:
"boost::archive::basic_xml_iarchive<boost::archive::xml_wiarchive>::load_start(char const*)", referenced from:
void boost::archive::basic_xml_iarchive<boost::archive::xml_wiarchive>::load_override<std::basic_string<wchar_t, std::char_traits<wchar_t>, std::allocator<wchar_t> > >(boost::serialization::nvp<std::basic_string<wchar_t, std::char_traits<wchar_t>, std::allocator<wchar_t> > > const&, int)in SurfaceFrame.o

Changing Apple LLVM Standard Compiler 4.2 - Language / C++ Standard Library setting from libc++ (LLVM) to libstdc++ (GNU) solved the same case for me.

Related

stl Linking Error on xcode

When to generate an executable with xcode, I have 3 Linking errors. I used Irrlicht 1.9 that I compile myself this morning.
I would like to say that the file CIrrDeviceOSX.mm is an objective-c file that can be found here :
https://github.com/zaki/irrlicht/blob/master/source/Irrlicht/CIrrDeviceOSX.h
https://github.com/zaki/irrlicht/blob/master/source/Irrlicht/CIrrDeviceOSX.mm
I think that the error is inside "std::map KeyCodes;" in CIrrDeviceOSX.h and used in CIrrDeviceOSX.mm
I dont know if the problem is that the file is in objective-c and the signature of the methods is different or that there are difference in version of the C++ (c++11 or ???).
Ld bin/Debug/minetest normal x86_64
cd /Users/bluholm/Desktop/minetest-release/minetest
export MACOSX_DEPLOYMENT_TARGET=10.12
/Applications/Xcode.app/Contents/Developer/Toolchains/XcodeDefault.xctoolchain/usr/bin/clang++ -arch x86_64 -isysroot /Applications/Xcode.app/Contents/Developer/Platforms/MacOSX.platform/Developer/SDKs/MacOSX10.12.sdk -L/Users/bluholm/Desktop/minetest-release/minetest/bin/Debug -F/Users/bluholm/Desktop/minetest-release/minetest/bin/Debug -filelist /Users/bluholm/Desktop/minetest-release/minetest-osx/src/minetest.build/Debug/minetest.build/Objects-normal/x86_64/minetest.LinkFileList -mmacosx-version-min=10.12 -Xlinker -object_path_lto -Xlinker /Users/bluholm/Desktop/minetest-release/minetest-osx/src/minetest.build/Debug/minetest.build/Objects-normal/x86_64/minetest_lto.o -Xlinker -no_deduplicate -lc++ -pagezero_size 10000 -image_base 100000000 -Wl,-search_paths_first -Wl,-headerpad_max_install_names /usr/lib/libz.dylib /usr/local/Cellar/irrlicht/1.9/lib/libIrrlicht.a -framework OpenGL -framework OpenAL /usr/local/lib/libvorbisfile.dylib /usr/local/lib/libvorbis.dylib /usr/local/lib/libogg.dylib /usr/lib/libsqlite3.dylib /usr/local/lib/libluajit-5.1.dylib /Users/bluholm/Desktop/minetest-release/minetest-osx/src/gmp/Debug/libgmp.a /Users/bluholm/Desktop/minetest-release/minetest-osx/src/jsoncpp/json/Debug/libjsoncpp.a -framework CoreFoundation -lpthread /usr/lib/libiconv.dylib -framework Carbon -framework Cocoa -framework IOKit /usr/lib/libiconv.dylib /usr/lib/libcurl.dylib /usr/local/lib/libfreetype.dylib /Users/bluholm/Desktop/minetest-release/minetest-osx/src/cguittfont/Debug/libcguittfont.a /usr/lib/libcurses.dylib /usr/lib/libform.dylib /usr/local/lib/libhiredis.dylib -framework Carbon -framework Cocoa -framework IOKit /usr/lib/libcurl.dylib /usr/lib/libcurses.dylib /usr/lib/libform.dylib /usr/local/lib/libhiredis.dylib /usr/lib/libz.dylib /usr/local/Cellar/irrlicht/1.9/lib/libIrrlicht.a /usr/local/lib/libfreetype.dylib -Xlinker -dependency_info -Xlinker /Users/bluholm/Desktop/minetest-release/minetest-osx/src/minetest.build/Debug/minetest.build/Objects-normal/x86_64/minetest_dependency_info.dat -o /Users/bluholm/Desktop/minetest-release/minetest/bin/Debug/minetest
Undefined symbols for architecture x86_64:
"std::_Rb_tree_decrement(std::_Rb_tree_node_base*)", referenced from:
std::_Rb_tree_iterator >::operator--() in libIrrlicht.a(CIrrDeviceOSX.o)
"std::_Rb_tree_increment(std::_Rb_tree_node_base*)", referenced from:
std::_Rb_tree_iterator >::operator++() in libIrrlicht.a(CIrrDeviceOSX.o)
"std::_Rb_tree_insert_and_rebalance(bool, std::_Rb_tree_node_base*, std::_Rb_tree_node_base*, std::_Rb_tree_node_base&)", referenced from:
std::_Rb_tree, std::_Select1st >, std::less, std::allocator > >::_M_insert(std::_Rb_tree_node_base*, std::_Rb_tree_node_base*, std::pair const&) in libIrrlicht.a(CIrrDeviceOSX.o)
ld: symbol(s) not found for architecture x86_64
clang: error: linker command failed with exit code 1 (use -v to see invocation)
Try to created a new project in XCode with the sources and changed the C++ Standard Library from the default libc++ to libstdc++

clang: error: linker command failed with exit code 1 (use -v to see invocation) XCode and wxWidgets

I'm trying to start a project in XCode 8 using wxWidgets 3.1.0 on OS X 10.11
After downloading wxWidgets-3.1.0 I've built and make everything according to the /docs/osx/install.txt
Now I tried to create a new project and followed their guide: https://wiki.wxwidgets.org/Creating_Xcode_projects_for_wxWidgets_applications
I followed almost every step exactly as instructed. (Static and Debug)
I didn't find the Summary Tab and a Choose Info.plist File Button, I chose it over General under Identity (which may be the same)
Then I tried to compile and run.
I'm getting Warnings and 1 Error.
Warning: Telling me to check dependencies
wxcocoa.xcconfig line 3: Unable to find included file "wx.xcconfig"
Warning: The Copy Bundle Resources build phase contains this target's Info.plist file '/Users/me/Desktop/git/xcode/wx_mac_xcode/Info_cocoa.plist'.
Error:
Ld /Users/me/Library/Developer/Xcode/DerivedData/wx_mac_xcode-bhbnjqgpmqtgwxhfxmjhvrtjnraz/Build/Products/Debug/Static.app/Contents/MacOS/Static normal x86_64
cd /Users/me/Desktop/git/xcode/wx_mac_xcode
export MACOSX_DEPLOYMENT_TARGET=10.5
/Applications/Xcode.app/Contents/Developer/Toolchains/XcodeDefault.xctoolchain/usr/bin/clang++ -arch x86_64 -isysroot /Applications/Xcode.app/Contents/Developer/Platforms/MacOSX.platform/Developer/SDKs/MacOSX10.11.sdk -L/Users/me/Library/Developer/Xcode/DerivedData/wx_mac_xcode-bhbnjqgpmqtgwxhfxmjhvrtjnraz/Build/Products/Debug -F/Users/me/Library/Developer/Xcode/DerivedData/wx_mac_xcode-bhbnjqgpmqtgwxhfxmjhvrtjnraz/Build/Products/Debug -filelist /Users/me/Library/Developer/Xcode/DerivedData/wx_mac_xcode-bhbnjqgpmqtgwxhfxmjhvrtjnraz/Build/Intermediates/wx_mac_xcode.build/Debug/Static.build/Objects-normal/x86_64/Static.LinkFileList -Xlinker -rpath -Xlinker #executable_path/../Frameworks -mmacosx-version-min=10.5 -Xlinker -no_deduplicate -framework WebKit -framework IOKit -framework Carbon -framework Cocoa -framework AudioToolbox -framework OpenGL -framework QTKit -framework WebKit -framework IOKit -framework Carbon -framework Cocoa -framework AudioToolbox -framework OpenGL -framework QTKit -lz -stdlib=libstdc++ -lwx_osx_cocoa_static -Xlinker -dependency_info -Xlinker /Users/me/Library/Developer/Xcode/DerivedData/wx_mac_xcode-bhbnjqgpmqtgwxhfxmjhvrtjnraz/Build/Intermediates/wx_mac_xcode.build/Debug/Static.build/Objects-normal/x86_64/Static_dependency_info.dat -o /Users/me/Library/Developer/Xcode/DerivedData/wx_mac_xcode-bhbnjqgpmqtgwxhfxmjhvrtjnraz/Build/Products/Debug/Static.app/Contents/MacOS/Static
ld: library not found for -lwx_osx_cocoa_static
clang: error: linker command failed with exit code 1 (use -v to see invocation)
Double checked every step, but don't know how to fix those dependencies.
Project and library are debug mode
Cheers

Native linking error on xamarin ios binding

I am writing a wrapper that bind to an iOS SDK using the P/Invoke as Sharpie was not able to generate a compilable code for this SDK.
When compiling the iOS App with the wrapper project referenced I am having many linking issues such as this one :
MTOUCH: error MT5210: Native linking failed, undefined symbol: std::locale::classic(). Please verify that all the necessary frameworks have been referenced and native libraries are properly linked in.
MTOUCH: error MT5210: Native linking failed, undefined symbol: std::__throw_bad_cast(). Please verify that all the necessary frameworks have been referenced and native libraries are properly linked in.
MTOUCH: error MT5210: Native linking failed, undefined symbol: std::invalid_argument::invalid_argument(std::string const&). Please verify that all the necessary frameworks have been referenced and native libraries are properly linked in. (Please find the complete log on this complete log file.)
The extra mono touch argument passed from the iOS project are described below:
-cxx -v -gcc_flags "-L${ProjectDir} -lstdc++ -lresolv -liconv -lxml2 -lz -ObjC
-force_load ${ProjectDir}/Libs/libcrypto.a" -cxx -v -gcc_flags "-L${ProjectDir} -lstdc++ -lresolv -liconv -lxml2 -lz -ObjC -force_load ${ProjectDir}/Libs/libssl.a" -cxx -v -gcc_flags "-lstdc++ -lresolv -liconv -lxml2 -lz -ObjC -L${ProjectDir} -framework Security -framework CoreVideo -framework CoreMedia -framework AVFoundation -framework CFNetwork -framework Accelerate -framework AudioToolbox -framework CoreAudio -framework Foundation -framework CoreGraphics -framework UIKit -force_load ${ProjectDir}/Libs/libsipwrapper.a -dead_strip -all_load"
The SDK is composed of three libraries : libcrypto.a, libssl.a and libsipwrapper.a.
Following many articles/posts on the internet, it is recommended to add add the standard library such as -lstdc++, lz, and ObjC, but this not seems to work on my case.
I have also tried to create a Binding Project that includes the three libraries and the wrapper code, the content added to the linkwith files seems like that :
[assembly: LinkWith ("libsipwrapper.a", LinkTarget.ArmV7 | LinkTarget.ArmV7s | LinkTarget.Arm64, Frameworks = "CoreVideo CoreMedia AVFoundation CFNetwork Accelerate AudioToolbox CoreAudio Foundation CoreGraphics UIKit", ForceLoad = false, SmartLink = true, IsCxx = true, LinkerFlags = "-lstdc++ -lresolv -liconv -lxml2 -lz -ObjC")]
The problem was not resolved and I continue to have the described linking errors.
After two days of wasted time, I finally got it, to be clear, it's not evident to guess the parameters to pass to touch, to link correctly a library built by a tier only by yourself. To simplify the task, I have compiled the demo app provided by the SDK provider and used Xcode to compile the demo and gets the parameters sent by Xcode to clang++. this helped me to figure out the parameters to send to monotouch:
--compiler:clang++ -cxx -v -gcc_flags "-stdlib=libstdc++ -L${ProjectDir} -force_load ${ProjectDir}/Libs/libcrypto.a" -cxx -v -gcc_flags "-stdlib=libstdc++ -L${ProjectDir} -force_load ${ProjectDir}/Libs/libssl.a" -cxx -v -gcc_flags "-dead_strip -lresolv -liconv -stdlib=libstdc++ -fobjc-arc -fobjc-link-runtime -framework CoreMedia -framework CoreVideo -framework AVFoundation -framework CFNetwork -framework AudioToolbox -framework CoreAudio -lz -lxml2 -framework CoreGraphics -framework UIKit -framework Foundation -L${ProjectDir} -force_load ${ProjectDir}/Libs/libsipwrapper.a"
Hope this will help other guys.
(Check the two points described by #NyxSway below are also very important)
Without knowing more details of your project, have you checked:
1) have you checked if your .a file really have that symbol it's complaining about using terminal -> grep command, for all the architecture you are supporting: armv7/armv7s/arm64
2) in your C# code, did you use [DllImport ("__Internal")] instead of your own library name?

Diagnosing "contains undefined reference for architecture" at linking phase

I'm trying to build a x86_64 application on MacOSX, using qmake/qt. I was able to compile in QT4, but not in QT5.
Anyway, after running qmake to generate my makefiles etc:
qmake -recursive -spec macx-clang app.pro CONFIG+='release static'
Then when I run make, eventually I end up here:
/Applications/Xcode.app/Contents/Developer/Toolchains/XcodeDefault.xctoolchain/usr/bin/clang++ -headerpad_max_install_names -arch x86_64 -Wl,-dead_strip -framework Cocoa -framework Carbon -Wl,-syslibroot,/Applications/Xcode.app/Contents/Developer/Platforms/MacOSX.platform/Developer/SDKs/MacOSX10.8.sdk -mmacosx-version-min=10.6 -o (...author's note--tons of .o files here...) -L../lib -L../../debug -F/Users/seth/workspace/qt5.1.0//5.1.0/clang_64/lib -lprotobuf -framework Security -framework SecurityInterface -framework ApplicationServices -framework CoreFoundation -lxml2 -lbz2 -lxar -framework ScriptingBridge -L/Users/seth/workspace/qt5.1.0//5.1.0/clang_64/plugins/iconengines -lssl -lcrypto -lz -lFLAC -framework Carbon -framework QtWebKitWidgets -framework QtQuick -framework QtQml -framework QtNetwork -framework QtCore -framework QtGui -framework QtOpenGL -framework QtWidgets -framework QtPrintSupport -framework Cocoa -framework QtWebKit -framework QtSql -framework QtSensors -framework QtSvg -framework QtXml -framework OpenGL -framework AGL
ld: '__ZN3Log16DebugE7QStringS3_' in debug/Log.o contains undefined reference for architecture x86_64
clang: error: linker command failed with exit code 1 (use -v to see invocation)
I do not understand what 'undefined reference for architecture x86_64' means, and that's certainly the heart of the problem. Upon reading some other threads, some suggest that the libraries I'm linking against aren't x86_64, but after checking and rechecking, I can't find any non-x86_64 libraries involved in the process.
All my .o files from the build are Mach-O 64-bit object x86_64, after checking with the file command.
And for all libraries that I'm trying to reference (like libcrypto, for instance):
Non-fat file: ../lib/libcrypto.a is architecture: x86_64
And of course all the mac framework libraries are both 32/64bit capable.
Does anyone have any suggestions on how I could debug this further?
Been fiddling all day, found it.
The method that the link is complaining about has this in it:
qt_mac_execute_apple_script
This method does not exist in qt5.
Also, earlier in the problematic file, I have this:
extern bool qt_mac_execute_apple_script(const QString &script, AEDesc *ret);
if i comment these lines, the error goes away.
So basically, a very bad compiler error for a missing symbol – because the compiler wasn’t nice enough to point out what the actual problem is beyond the vague architecture statement; probably made worse because I’m building my application statically coupled with the extern.

How to setup linkage for OpenCV and Qt to use createButton?

I'm looking at opencv highgui samples (like connectedcomponents.cpp) and trying to get used to adding GUI elements. Currently I'm trying to add a button:
void on_button(int, void*){
cout << "click" << end;
}
//in main()
createButton("test",on_button);
but I get a link error:
g++ -c -pipe -g -gdwarf-2 -arch x86_64 -Xarch_x86_64 -mmacosx-version-min=10.5 -Wall -W -DQT_CORE_LIB -I../../../QtSDK/Desktop/Qt/474/gcc/mkspecs/macx-g++ -I. -I../../../QtSDK/Desktop/Qt/474/gcc/lib/QtCore.framework/Versions/4/Headers -I../../../QtSDK/Desktop/Qt/474/gcc/include/QtCore -I../../../QtSDK/Desktop/Qt/474/gcc/include -I/opt/local/include -I../../../QtSDK/Desktop/Qt/474/gcc/include -I. -F/Users/george/QtSDK/Desktop/Qt/474/gcc/lib -o main.o main.cpp
g++ -headerpad_max_install_names -arch x86_64 -Xarch_x86_64 -mmacosx-version-min=10.5 -o CVConnectedComponent main.o -F/Users/george/QtSDK/Desktop/Qt/474/gcc/lib -L/Users/george/QtSDK/Desktop/Qt/474/gcc/lib /opt/local/lib/libopencv_core.dylib /opt/local/lib/libopencv_contrib.dylib /opt/local/lib/libopencv_highgui.dylib /opt/local/lib/libopencv_objdetect.dylib /opt/local/lib/libopencv_imgproc.dylib /opt/local/lib/libopencv_features2d.dylib /opt/local/lib/libopencv_video.dylib -framework QtCore -F/Users/george/Documents/Qt/CVConnectedComponent/../../../QtSDK/Desktop/Qt/474/gcc/lib/
Undefined symbols:
"cv::createButton(std::basic_string<char, std::char_traits<char>, std::allocator<char> > const&, void (*)(int, void*), void*, int, bool)", referenced from:
_main in main.o
make: Leaving directory `/Users/george/Documents/Qt/CVConnectedComponent'
ld: symbol(s) not found
As far as I can understand I'm not linking against the QtCore library properly.
I've this:
mac: LIBS += -framework QtCore
and this:
mac: LIBS += -F$$PWD/../../../QtSDK/Desktop/Qt/474/gcc/lib/ -framework QtCore
INCLUDEPATH += $$PWD/../../../QtSDK/Desktop/Qt/474/gcc/include
DEPENDPATH += $$PWD/../../../QtSDK/Desktop/Qt/474/gcc/include
In the .pro file of the Qt project, but with no luck.
I'm using OpenCV 2.4.1 with Qt 4.7.4 on osx 10.6.8.
What's the correct way to link to QtCore in Qt Creator to use createButton in OpenCV ?
I've reinstalled OpenCV, this time with Qt support and the code worked.
Still it's worth remembering that buttons will go into the Control Panel by default, as I found out by reading some documentation: