So, I am building a c++ executable(exe) on my Mac in Xcode. exe depends on frmwrk target which I am building as a Framework. To frmwrk target, I am linking a static library libA and libA further depends on static libB.
exe -> frmwrk -> libA -> libB
I am using symbols from libA and libB in my exe. However, I am getting linking error while building my exe. It is not able to find the symbols from libB. However, it is able to find the symbols from libA.
It looks like symbols of libB are only visible in frmwrk and not outside. Is there a way to expose symbols of libB to whoever links to frmwrk. In CMake, we have option to specify PUBLIC/PRIVATE dependency but I couldn't find in Xcode.
I debugged for hours but couldn't find any solutions. Can anybody help?
Here is my linker command for frmwrk
Ld /Users/vmangal/my/project/BuildResults/bin/Frameworks/Debug/Intel_64_libcpp/frmwrk.framework/Versions/A/frmwrk normal (in target 'myfrm_Debug' from project 'Project')
cd /Users/vmangal/my/project/Build/Toolkit/Mac
-filelist
/Users/vmangal/my/project/BuildResults/obj/myfrm/myfrm.build/Default/myfrm_Debug.build/Objects-normal/x86_64/frmwrk.LinkFileList -exported_symbols_list
/Users/vmangal/my/project/BuildResults/obj/myfrm/myfrm.build/Default/myfrm_Debug.build/DerivedSources/myfrm.exp -install_name u/executable_path/../Frameworks/frmwrk.framework/Versions/A/frmwrk -dead_strip -Xlinker -object_path_lto -Xlinker
/Users/vmangal/my/project/BuildResults/obj/myfrm/myfrm_Debug/myfrm.build/Default/myfrm_Debug.build/Objects-normal/x86_64/frmwrk_lto.o
-Xlinker -no_deduplicate -stdlib\=libc++ -fobjc-link-runtime -Xlinker -search_paths_first -lz -single_module -lPDCore -Xlinker -no_data_in_code_info
***Here is linking libA***
/Users/vmangal/my/project/pdfl_to_t5_approach_4/pdfTools/adobe/BuildResults/lib/debug/pdflib/Intel_libcpp/libA.a
-framework System -framework AppKit -framework QuickLook -Xlinker -no_adhoc_codesign -compatibility_version 1 -current_version 1 -Xlinker -dependency_info -Xlinker /Users/vmangal/my/project/obj/myfrm/myfrm_Debug/myfrm.build/Default/myfrm_Debug.build/Objects-normal/x86_64/frmwrk_dependency_info.dat -o /Users/vmangal/my/project/BuildResults/bin/Frameworks/Debug/Intel_64_libcpp/frmwrk.framework/Versions/A/frmwrk
Here is the linker command for exe
Ld /Users/vmangal/my/project/project/mac/debug/exe.app/Contents/MacOS/exe normal (in target 'exe.Debug' from project 'exe.mp')
cd /Users/vmangal/my/project/project/mac
/Applications/Xcode.app/Contents/Developer/Toolchains/XcodeDefault.xctoolchain/usr/bin/clang++ -target x86_64-apple-macos10.15 -isysroot /Applications/Xcode.app/Contents/Developer/Platforms/MacOSX.platform/Developer/SDKs/MacOSX12.1.sdk
-L/Users/vmangal/my/project/project/mac/debug -L..
-L../../../../../../../../../usr/lib
-F/Users/vmangal/my/project/project/mac/debug
-F/Applications/Xcode.app/Contents/Developer/Platforms/MacOSX.platform/Developer/SDKs/MacOSX.sdk/System/Library/Frameworks
-F/Users/vmangal/my/project/Public/Libraries/Mac/intel_64_libcpp/debug
-filelist
/Users/vmangal/my/project/project/mac/build/exe.mp.build/exe.Debug.build/Objects-normal/x86_64/exe.LinkFileList -Xlinker -no_pie -Xlinker -rpath -Xlinker u/executable_path/../Frameworks -Xlinker -object_path_lto -Xlinker
/Users/vmangal/my/project/project/mac/build/exe_SDK.mp.build/exe_SDK.Debug.build/Objects-normal/x86_64/exe_SDK_lto.o -Xlinker -no_deduplicate -stdlib\=libc++ -Wl,-keep_dwarf_unwind -Wl,-no_compact_unwind -Wl,-no_data_in_code_info -Wl,-no_function_starts -framework CoreServices -framework ApplicationServices -framework Foundation -framework AppKit
***Here is linking frmwrk***
-framework frmwrk
-lxml2.2 -lz.1 -Xlinker -no_adhoc_codesign -Xlinker -dependency_info -Xlinker
/Users/vmangal/my/project/project/mac/build/exe_SDK.mp.build/exe_SDK.Debug.build/Objects-normal/x86_64/exe_SDK_dependency_info.dat -o /Users/vmangal/my/project/project/mac/debug/exe_SDK.app/Contents/MacOS/exe
Here is the creation command of libA:
Libtool /Users/vmangal/my/project/BuildResults/lib/debug/Intel_libcpp/libA.a normal (in target 'libA_debug_libcpp' from project 'Cos')
cd /Users/vmangal/my/project/Build/Cos/Mac
export MACOSX_DEPLOYMENT_TARGET\=10.15
/Applications/Xcode.app/Contents/Developer/Toolchains/XcodeDefault.xctoolchain/usr/bin/libtool -static -arch_only x86_64 -D -syslibroot
/Applications/Xcode.app/Contents/Developer/Platforms/MacOSX.platform/Developer/SDKs/MacOSX12.1.sdk
-L/Users/vmangal/my/project/BuildResults/lib/debug/pdflib/Intel_libcpp -filelist
/Users/vmangal/my/project/BuildResults/obj/Cos/libA_debug_libcpp/Cos.build/Default/libA_debug_libcpp.build/Objects-normal/x86_64/Cos.LinkFileList
***Here is linking libB***
/Users/vmangal/my/project/t5/xcode/build/Debug/libB.a
-dependency_info /Users/vmangal/my/project/pBuildResults/obj/Cos/libA_debug_libcpp/Cos.build/Default/libA_debug_libcpp.build/Objects-normal/x86_64/Cos_libtool_dependency_info.dat -o /Users/vmangal/my/project/BuildResults/lib/debug/Intel_libcpp/libA.a
I have added the linker command in question.
I have added Here is linking tag to show where my libraries appear in command.
This is the order in which linking takes place:
exe -> frmwrk -> libA -> libB
Also, when I run nm command on frmwrk, I can see all symbols which linker is complaining about.
Related
I want to statically link a library say libcurl. As both static and shared libraries are in same folder, I am using -Wl,-Bstatic to let the linker know to use static library.
g++ -o prog prog.o -Wl,-Bstatic -lcurl.
But above command is giving error:
/usr/bin/ld: cannot find -lgcc_s
If I exclude -Wl,-Bstatic, it works fine, but It will use shared library which I dont want.
What is going wrong?
When you use the g++ front-end to perform your linkage, like:
g++ -o prog prog.o -Wl,-Bstatic -lcurl
g++ invokes the linker passing it your linkage options and also silently
adding to the linker commandline a large number of boiler-plate options that
are invariant for C++ linkage.
For example, your C++ program very probably will need to link the standard C++ library,
libstdc++, but your g++ command doesn't mention it. It certainly also needs the standard C library,
but it isn't mentioned either. g++ automatically adds linkage options to link these and
other libraries.
You can see all the boilerplate that g++ adds to your linkage by running it in
verbose mode. You will see the like of:
$ g++ -v -o prog prog.o -Wl,-Bstatic -lcurl
...
...
COLLECT_GCC_OPTIONS='-v' '-o' 'prog' '-shared-libgcc' '-mtune=generic' '-march=x86-64'
/usr/lib/gcc/x86_64-linux-gnu/7/collect2 -plugin /usr/lib/gcc/x86_64-linux-gnu/7/liblto_plugin.so \
-plugin-opt=/usr/lib/gcc/x86_64-linux-gnu/7/lto-wrapper \
-plugin-opt=-fresolution=/tmp/cckwrJp6.res -plugin-opt=-pass-through=-lgcc_s \
-plugin-opt=-pass-through=-lgcc -plugin-opt=-pass-through=-lc \
-plugin-opt=-pass-through=-lgcc_s -plugin-opt=-pass-through=-lgcc \
--sysroot=/ --build-id --eh-frame-hdr -m elf_x86_64 --hash-style=gnu \
--as-needed -dynamic-linker /lib64/ld-linux-x86-64.so.2 -pie -z now -z relro \
-o prog /usr/lib/gcc/x86_64-linux-gnu/7/../../../x86_64-linux-gnu/Scrt1.o \
/usr/lib/gcc/x86_64-linux-gnu/7/../../../x86_64-linux-gnu/crti.o \
/usr/lib/gcc/x86_64-linux-gnu/7/crtbeginS.o \
-L/usr/lib/gcc/x86_64-linux-gnu/7 -L/usr/lib/gcc/x86_64-linux-gnu/7/../../../x86_64-linux-gnu \
-L/usr/lib/gcc/x86_64-linux-gnu/7/../../../../lib -L/lib/x86_64-linux-gnu \
-L/lib/../lib -L/usr/lib/x86_64-linux-gnu -L/usr/lib/../lib \
-L/usr/lib/gcc/x86_64-linux-gnu/7/../../.. prog.o \
-Bstatic -lcurl -lstdc++ -lm -lgcc_s -lgcc -lc -lgcc_s -lgcc \
/usr/lib/gcc/x86_64-linux-gnu/7/crtendS.o \
/usr/lib/gcc/x86_64-linux-gnu/7/../../../x86_64-linux-gnu/crtn.o
/usr/bin/x86_64-linux-gnu-ld: cannot find -lgcc_s
/usr/bin/x86_64-linux-gnu-ld: cannot find -lgcc_s
collect2: error: ld returned 1 exit status
Note in particular your -Bstatic option and the following linkage options:
-Bstatic -lcurl -lstdc++ -lm -lgcc_s -lgcc -lc -lgcc_s -lgcc \
/usr/lib/gcc/x86_64-linux-gnu/7/crtendS.o \
/usr/lib/gcc/x86_64-linux-gnu/7/../../../x86_64-linux-gnu/crtn.o
which include your -lcurl and also the default system libraries:
-lcurl -lstdc++ -lm -lgcc_s -lgcc -lc -lgcc_s -lgcc
Then see the documentation of the -Bstatic linker option:
-Bstatic
...
Do not link against shared libraries. This is only meaningful on platforms for which shared libraries are supported.
The different variants of this option are for compatibility with various systems.
You may use this option multiple times on the command line: it affects library searching for -l options which follow it.
This option also implies --unresolved-symbols=report-all. This option can be used with -shared.
Doing so means that a shared library is being created but that all of the library’s external
references must be resolved by pulling in entries from static libraries.
[my emphasis]
So, your -Bstatic option directs the linker to link static versions of:
-lcurl -lstdc++ -lm -lgcc_s -lgcc -lc -lgcc_s -lgcc
It finds the static libcurl.a that you have installed. It fails to find a
static library for -lgcc_s because there isn't any libgcc_s.a installed on
your system. You just have dynamic versions of this and other basic system libraries,
which is pretty normal.
If you want the linker to link static libraries only for the -l options that you
specify, then you must turn on -Bstatic before your -l options and turn it off
after them, -Bdynamic, even if this makes -Bdynamic the last thing on your commandline.
Because g++ (or any other GCC front-end, gcc, gfortran...) is going to add -l
options to your commandline behind the scenes. Link like:
g++ -o prog prog.o -Wl,-Bstatic -lcurl -Wl,-Bdynamic
to fix this particular linkage error.
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
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?
I'm almost done upgrading Cocos2D from 0.99.5 to 2.1, but I don't know how to resolve this error. This is what shows up as the error:
Ld /Users/Admin/Library/Developer/Xcode/DerivedData/flyingAdventure-esbllafxkpvprvdfdsnfuyectjnh/Build/Products/Debug-iphonesimulator/Flying\ Adventure.app/Flying\ Adventure normal i386
cd /Users/Admin/Documents/EriksFiles/Erik/iPad/cocos2d/flyingAdventure/flyingAdventure_current
setenv IPHONEOS_DEPLOYMENT_TARGET 7.0
setenv PATH "/Applications/Xcode.app/Contents/Developer/Platforms/iPhoneSimulator.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 i386 -isysroot /Applications/Xcode.app/Contents/Developer/Platforms/iPhoneSimulator.platform/Developer/SDKs/iPhoneSimulator7.0.sdk -L/Users/Admin/Library/Developer/Xcode/DerivedData/flyingAdventure-esbllafxkpvprvdfdsnfuyectjnh/Build/Products/Debug-iphonesimulator -F/Users/Admin/Library/Developer/Xcode/DerivedData/flyingAdventure-esbllafxkpvprvdfdsnfuyectjnh/Build/Products/Debug-iphonesimulator -filelist /Users/Admin/Library/Developer/Xcode/DerivedData/flyingAdventure-esbllafxkpvprvdfdsnfuyectjnh/Build/Intermediates/flyingAdventure.build/Debug-iphonesimulator/flyingAdventure1.build/Objects-normal/i386/Flying\ Adventure.LinkFileList -Xlinker -objc_abi_version -Xlinker 2 -all_load -ObjC -fobjc-link-runtime -Xlinker -no_implicit_dylibs -mios-simulator-version-min=7.0 -lcocos2d\ libraries -framework CoreText -framework GameKit -lz.1.2.5 -framework CoreGraphics -framework Foundation -framework OpenGLES -framework QuartzCore -framework UIKit -framework AudioToolbox -framework OpenAL -lz -framework AVFoundation -Xlinker -dependency_info -Xlinker /Users/Admin/Library/Developer/Xcode/DerivedData/flyingAdventure-esbllafxkpvprvdfdsnfuyectjnh/Build/Intermediates/flyingAdventure.build/Debug-iphonesimulator/flyingAdventure1.build/Objects-normal/i386/Flying\ Adventure_dependency_info.dat -o /Users/Admin/Library/Developer/Xcode/DerivedData/flyingAdventure-esbllafxkpvprvdfdsnfuyectjnh/Build/Products/Debug-iphonesimulator/Flying\ Adventure.app/Flying\ Adventure
ld: library not found for -lcocos2d libraries
Library not found for -lcocos2d libraries
Linker command failed with exit code 1 (use -v to see invocation)
Does it have to do with my Link Binary With Libraries? Here's what that looks like:
I am trying to use Eclipse C++ and Irrlicht to a project in school. My problem is to set op the environment.
I have used this http://irrlicht3d.org/wiki/index.php?n=Main.Macintosh
I am using the new MacBook Pro.
I think the error is in this flag.
**** Build of configuration Debug for project HalloWorld2 ****
make all
Building file: ../src/helloworld.cpp
Invoking: GCC C++ Compiler
g++ -I/Users/JAMES/Code/irrlicht-1.7.2/include -O0 -g3 -Wall -c -fmessage-length=0 -arch i386 -fvisibility=hidden -MMD -MP -MF"src/helloworld.d" -MT"src/helloworld.d" -o "src/helloworld.o" "../src/helloworld.cpp"
Finished building: ../src/helloworld.cpp
Building target: HalloWorld2
Invoking: MacOS X C++ Linker
g++ -L/Users/JAMES/Code/irrlicht-1.7.2/source/Irrlicht/MacOSX/build/Release -L/Developer/SDKs/MacOSX10.6.sdk/usr/X11/lib -Xlinker -arch i386 -framework OpenGL -framework Carbon -framework Cocoa -framework IOKit -o "HalloWorld2" ./src/helloworld.o -lIrrlicht
i686-apple-darwin11-llvm-g++-4.2: i386: No such file or directory
make: *** [HalloWorld2] Error 1
The problem comes from the use of -Xlinker to pass arguments to the linker. The man page of g++ says:
-Xlinker option
Pass option as an option to the linker. You can use this to supply system-specific linker options which GCC does not know how to recognize.
If you want to pass an option that takes an argument, you must use -Xlinker twice, once for the option and once for the argument. For example, to pass -assert definitions, you must write -Xlinker -assert -Xlinker definitions. It
does not work to write -Xlinker "-assert definitions", because this passes the entire string as a single argument, which is not what the linker expects.
Here -Xlinker appears only once whereas it should be appear between each argument sent to the linker. So a ugly solution is to write:
-arch -Xlinker i386 -Xlinker -framework -Xlinker OpenGL -Xlinker -framework -Xlinker Carbon -Xlinker -framework -Xlinker Cocoa -Xlinker -framework -Xlinker IOKit
But if you find a way to configure Eclipse to use -Wl, instead of -Xlinker it would be better I think:
-Wl,option
Pass option as an option to the linker. If option contains commas, it is split into multiple options at the commas.
Then you could use:
-arch,i386,-framework,OpenGL,-framework,Carbon,-framework,Cocoa,-framework,IOKit