I am developing an iPhone application. I am unfamiliar with Xcode, so please bear with me. I have the iOS 4.1 Device SDK. When I select "Simulator" in the "Active ..." drop-down box, my application compiles without errors and runs in the iPhone simulator.
When I select "Device" in the drop-down box, however, I get the following linker error regarding a duplicate symbol:
Ld build/PineCone.build/Debug-iphoneos/PineCone.build/Objects-normal/armv6/PineCone normal armv6
cd /Users/isaacsutherland/fydp/PineCone/PineCone
setenv IPHONEOS_DEPLOYMENT_TARGET 4.1
setenv PATH "/Developer/Platforms/iPhoneOS.platform/Developer/usr/bin:/Developer/usr/bin:/usr/bin:/bin:/usr/sbin:/sbin"
/Developer/Platforms/iPhoneOS.platform/Developer/usr/bin/gcc-4.2 -arch armv6 -isysroot /Developer/Platforms/iPhoneOS.platform/Developer/SDKs/iPhoneOS4.1.sdk -L/Users/isaacsutherland/fydp/PineCone/PineCone/build/Debug-iphoneos -L/Users/isaacsutherland/fydp/PineCone/PineCone/../3rd/libGHUnitIPhone -F/Users/isaacsutherland/fydp/PineCone/PineCone/build/Debug-iphoneos -filelist /Users/isaacsutherland/fydp/PineCone/PineCone/build/PineCone.build/Debug-iphoneos/PineCone.build/Objects-normal/armv6/PineCone.LinkFileList -dead_strip -all_load -ObjC -miphoneos-version-min=4.1 -framework Foundation -framework UIKit -framework CoreGraphics /Users/isaacsutherland/fydp/PineCone/3rd/three20/Build/Products/Debug-iphoneos/libThree20.a /Users/isaacsutherland/fydp/PineCone/3rd/three20/Build/Products/Debug-iphoneos/libThree20Core.a /Users/isaacsutherland/fydp/PineCone/3rd/three20/Build/Products/Debug-iphoneos/libThree20Network.a /Users/isaacsutherland/fydp/PineCone/3rd/three20/Build/Products/Debug-iphoneos/libThree20Style.a /Users/isaacsutherland/fydp/PineCone/3rd/three20/Build/Products/Debug-iphoneos/libThree20UI.a /Users/isaacsutherland/fydp/PineCone/3rd/three20/Build/Products/Debug-iphoneos/libThree20UICommon.a /Users/isaacsutherland/fydp/PineCone/3rd/three20/Build/Products/Debug-iphoneos/libThree20UINavigator.a -framework QuartzCore -framework CFNetwork -framework MobileCoreServices -framework SystemConfiguration -lz.1.2.3 /Users/isaacsutherland/fydp/PineCone/ClientDal/build/Debug-iphoneos/libClientDal.a -lGHUnitIPhone4_0 -o /Users/isaacsutherland/fydp/PineCone/PineCone/build/PineCone.build/Debug-iphoneos/PineCone.build/Objects-normal/armv6/PineCone
ld: duplicate symbol _RedirectionLimit in /Users/isaacsutherland/fydp/PineCone/ClientDal/build/Debug-iphoneos/libClientDal.a(libASIHTTPRequest.a-armv6-master.o) and /Users/isaacsutherland/fydp/PineCone/ClientDal/build/Debug-iphoneos/libClientDal.a(libASIHTTPRequest.a-armv6-master.o)
collect2: ld returned 1 exit status
Command /Developer/Platforms/iPhoneOS.platform/Developer/usr/bin/gcc-4.2 failed with exit code 1
The error is strange because it complains that _RedirectionLimit is found twice -- in the same file! libClientDal.a(libASIHTTPRequest.a-armv6-master.o) is the offending library. Can someone help me understand what is going on? How could this library have compiled properly in the first place? Or perhaps the linker is trying to include the same library twice?
The workaround provided in this similar question does not work for me.
If you need more information, I will gladly provide it -- as I said, I'm new to Xcode development.
When you have a web of projects that compile to static libraries and refer to one another, there are 2 distinct concerns you must consider:
A project's Direct Dependencies inform Xcode which projects depend on each other so it knows to recompile a project when its dependencies change.
A project's Linked Libaries actually get included in its object code.
In a nutshell, your web of direct dependencies can be as tangled as you want, but you must be careful to link each project's code into the application executable only once.
Basically, my problem was that I had 3 projects A, B, and C, and the dependencies looked like A=>B, A=>C, B=>C. I was linking libC.a into both A and B, so the linker complained about duplicate code.
The configuration stuff you need to change is on the Target Info page for each of your projects' targets.
This happened to me when I used the -all_load linker flag, which forces the linker to load all symbols from all libraries. The Three20 project says you should use it, because otherwise the Categories won't be loaded and you get a runtime exception. I removed that flag, and added the -force_load flag just for each library that needed it (the Three20 libraries). See also: What does the -all_load linker flag do?
I've several apps that need to embed a small custom library that makes use of ASI and TBXML. Some of this apps have their own version of that libraries. In order to avoid duplicate symbol issue, I duplicated the each library's target removing the .m files that causes the issue.
Hope it helps.
Related
I am working on a C project with its own make-based build system. The project tries to interact with the SCSI subsystem through the IOKit framework. I am developing for arm64 macOS 12.4. The IT staff at our institute has set up this computer for software development, though I don't know exactly what this entails. Compiling and executing simple C programs seems to work fine.
Now, when linking the project, I get an error that the IOKit framework is not found.
ld: framework not found IOKit
fatal error: /Library/Developer/CommandLineTools/usr/bin/libtool: internal link edit command failed
smake: *** Code 1 (Operation not permitted) from command line for target '../../../../../libs/arm64-darwin-clang/pic/libmakestate.dylib'.
smake: The following command caused the error:
echo " ==> LINKING dynamic library \"../../../../../libs/arm64-darwin-clang/pic/libmakestate.dylib\""; libtool -dynamic -o ../../../../../libs/arm64-darwin-clang/pic/libmakestate.dylib -L../../../../../libs/arm64-darwin-clang/pic -L/usr/local/lib -framework IOKit -framework CoreFoundation -install_name /opt/schily/lib/libmakestate.dylib `echo OBJ/arm64-darwin-clang/pic/ld_file.o OBJ/arm64-darwin-clang/pic/lock.o | cat` -lc
Are there any additional options I have to supply to get access to the IOKit framework? A solution that is not specific to the particular macOS version in use would be best.
I have found an old question on a similar topic, but it seems to concern very old versions of macOS and I'm not sure if it is relevant. Also, I do not have permissions to move system files around on this computer.
Please bear with me, I'm not at all experienced in macOS development and am just trying to get this code to work. If you need any additional information, do not hesitate to ask.
This appears to be a consequence of using libtool to link. I was able to produce a working shared library using clang -dynamiclib as indicated in the manual.
Getting an Apple Mach-O Librarian Error when trying to archive my project.
I have an Xcode project that links to an FDLibrary. Its a static library contained in the same workspace. FDLibrary links to an SDLibrary. Another static library also contained in the workspace.
I know its unconventional to have multiple static libraries however the SDLibrary contains a lot of common code to several apps while the FDLibrary contains a lot of common code built on the SDLibrary only needed by a few apps. Most basically the FDLibrary contains a lot of specific interface templates while the SDLibrary is almost all data structures and object types.
Building and Running to device works completely fine. But I started to archive today and ran into this error.
All hints welcome! Thanks in advance!
Libtool "/Users/rpools1951/Library/Developer/Xcode/DerivedData/FunDecks-fqrkiylcrromdnbuuyxoyjotckal/Build/Intermediates/ArchiveIntermediates/Irregular Verbs/IntermediateBuildFilesPath/FDLibrary.build/Release-iphoneos/FDLibrary.build/Objects-normal/armv7s/libFDLibrary.a" normal armv7s
cd /Users/rpools1951/Projects/Workspaces/FDLibrary
setenv IPHONEOS_DEPLOYMENT_TARGET 6.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/libtool -static -arch_only armv7s -syslibroot /Applications/Xcode.app/Contents/Developer/Platforms/iPhoneOS.platform/Developer/SDKs/iPhoneOS6.0.sdk "-L/Users/rpools1951/Library/Developer/Xcode/DerivedData/FunDecks-fqrkiylcrromdnbuuyxoyjotckal/Build/Intermediates/ArchiveIntermediates/Irregular Verbs/BuildProductsPath/Release-iphoneos" -LSDLibrary -filelist "/Users/rpools1951/Library/Developer/Xcode/DerivedData/FunDecks-fqrkiylcrromdnbuuyxoyjotckal/Build/Intermediates/ArchiveIntermediates/Irregular Verbs/IntermediateBuildFilesPath/FDLibrary.build/Release-iphoneos/FDLibrary.build/Objects-normal/armv7s/FDLibrary.LinkFileList" -ObjC -framework UIKit -lSDLibrary -framework Foundation -o "/Users/rpools1951/Library/Developer/Xcode/DerivedData/FunDecks-fqrkiylcrromdnbuuyxoyjotckal/Build/Intermediates/ArchiveIntermediates/Irregular Verbs/IntermediateBuildFilesPath/FDLibrary.build/Release-iphoneos/FDLibrary.build/Objects-normal/armv7s/libFDLibrary.a"
/Applications/Xcode.app/Contents/Developer/Toolchains/XcodeDefault.xctoolchain/usr/bin/libtool: -dynamic not specified the following flags are invalid: -ObjC
/Applications/Xcode.app/Contents/Developer/Toolchains/XcodeDefault.xctoolchain/usr/bin/libtool: can't locate file for: -lSDLibrary
/Applications/Xcode.app/Contents/Developer/Toolchains/XcodeDefault.xctoolchain/usr/bin/libtool: file: -lSDLibrary is not an object file (not allowed in a library)
Command /Applications/Xcode.app/Contents/Developer/Toolchains/XcodeDefault.xctoolchain/usr/bin/libtool failed with exit code 1
On the MonoTouch cruise ship wet behind the ears.
Steps I followed the Hellow World tut from the Xamarin site; http://docs.xamarin.com/ios/getting_started/hello_iphone
1) Installed XCode via App Store
2) Installed MonoDevelop fresh from the Xamarin site
Created new project "HelloApple" (Single View Application) in MonoDevelop.
Built the app (command+B).
Opened the generated HelloApple_UIViewController.xib file with XCode Interface Builder
Clicked the Run button.
Received the following error;
Ld
DerivedData/HelloApple.UI/Build/Products/MonoTouch-iphonesimulator/HelloApple.UI.app/HelloApple.UI
normal i386
cd /Users/randerson/Projects/HelloApple/HelloApple.UI/obj/Xcode/1
setenv IPHONEOS_DEPLOYMENT_TARGET 6.0
setenv PATH "/Applications/Xcode.app/Contents/Developer/Platforms/iPhoneSimulator.platform/Developer/usr/bin:/Applications/Xcode.app/Contents/Developer/usr/bin:/Applications/MonoDevelop.app:/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/iPhoneSimulator6.0.sdk
-L/Users/randerson/Projects/HelloApple/HelloApple.UI/obj/Xcode/1/DerivedData/HelloApple.UI/Build/Products/MonoTouch-iphonesimulator
-F/Users/randerson/Projects/HelloApple/HelloApple.UI/obj/Xcode/1/DerivedData/HelloApple.UI/Build/Products/MonoTouch-iphonesimulator
-filelist /Users/randerson/Projects/HelloApple/HelloApple.UI/obj/Xcode/1/DerivedData/HelloApple.UI/Build/Intermediates/HelloApple.UI.build/MonoTouch-iphonesimulator/HelloApple.UI.build/Objects-normal/i386/HelloApple.UI.LinkFileList
-Xlinker -objc_abi_version -Xlinker 2 -fobjc-link-runtime -Xlinker -no_implicit_dylibs -mios-simulator-version-min=6.0 -framework UIKit -framework MapKit -framework Foundation -framework CoreGraphics -o /Users/randerson/Projects/HelloApple/HelloApple.UI/obj/Xcode/1/DerivedData/HelloApple.UI/Build/Products/MonoTouch-iphonesimulator/HelloApple.UI.app/HelloApple.UI
Undefined symbols for architecture i386: "_main", referenced from:
start in crt1.o ld: symbol(s) not found for architecture i386 clang: error: linker command failed with exit code 1 (use -v to see
invocation)
I have uninstalled XCode and MonoDevelop thinking I did things out of order or something a few times.
Really stumped. I would think the example would work out the box, so I gotta be missing something here.
Several posts on StackOverflow revolve around more complex already built apps, this is adding nothing to the project right out of the box and build.
What am I missing?
You do not build from Xcode itself, you build from MonoDevelop.
The most commonly used part of Xcode is the Interface Builder. You can create your UI using this tool (or using code) and then save it to disk. You then switch back to MonoDevelop to compile verything into a native application.
Note: MonoTouch itself will use parts of Xcode (command line tools) to build the native application. However, for most developers, this is not something you'll be aware of.
question:
How does Xcode generate the list of framework directories (-F flags in the call to ld) when building a Cocoa app? I keep getting a warning for an old directory which (I think) I have removed from the project settings.
details:
I moved a working Xcode project from one directory to another. I had to fix some broken references to frameworks that now have a different relative path. Everything appears to be working, except for a single warning on the final linker step:
ld: warning: directory '../Some/Path/To/Framework' following -F not found
../Some/Path/To/Framework is definitely part of the old setup. The external frameworks were stored in a directory that was one level up from the project file.
The full text of the call to ld looks something like this (lightly sanitized):
Ld /Volumes/Projects/Builds/Debug/MyApp.app/Contents/MacOS/MyApp normal i386
cd /Volumes/Projects/MyApp
setenv MACOSX_DEPLOYMENT_TARGET 10.6
/Developer/usr/bin/gcc-4.2 -arch i386 -isysroot /Developer/SDKs/MacOSX10.6.sdk
-L/Volumes/Projects/Builds/Debug -F/Volumes/Projects/Builds/Debug
-F../Some/Path/To/Framework
-F/Correct/Path/To/Framework
-filelist /Volumes/Projects/Builds/MyApp.build/Debug/MyApp.build/
Objects-normal/i386/MyApp.LinkFileList
-mmacosx-version-min=10.6
-framework Cocoa
-framework FRAMEWORK
-framework Carbon
-framework Quartz
-o /Volumes/Projects/Builds/Debug/MyApp.app/Contents/MacOS/MyApp
The warning is triggered by that old value for -F. I have searched through all of the build settings, and everything points to /Correct/Path/To/Framework, not ../Some/Path/To/Framework. I have also cleaned the entire build, but to no avail.
Check your build settings. The framework search paths are under Framework Search Paths, or build variable FRAMEWORK_SEARCH_PATHS.
I'm following a tutorial from chapter 12 of the book "Beginning iPhone 3 Development." When I try to build the project I get an error. The book came with the project files, so I went through every file in my Classes directory and copied and pasted the code from the example project so that they are identical. This has solved my build errors in the past. I checked that the same frameworks were installed and the files in the Other Sources and Resources folder are identical. Still, when I try to build, I get the following build error:
Ld
build/Debug-iphonesimulator/GLFun.app/GLFun
normal i386 cd
/Users/gin/Documents/development/GLFun
setenv MACOSX_DEPLOYMENT_TARGET 10.5
setenv PATH
"/Developer/Platforms/iPhoneSimulator.platform/Developer/usr/bin:/Developer/usr/bin:/usr/bin:/bin:/usr/sbin:/sbin"
/Developer/Platforms/iPhoneSimulator.platform/Developer/usr/bin/gcc-4.2
-arch i386 -isysroot /Developer/Platforms/iPhoneSimulator.platform/Developer/SDKs/iPhoneSimulator3.1.3.sdk
-L/Users/gin/Documents/development/GLFun/build/Debug-iphonesimulator
-F/Users/gin/Documents/development/GLFun/build/Debug-iphonesimulator
-filelist /Users/gin/Documents/development/GLFun/build/GLFun.build/Debug-iphonesimulator/GLFun.build/Objects-normal/i386/GLFun.LinkFileList
-mmacosx-version-min=10.5 -framework Foundation -framework UIKit -framework
CoreGraphics -framework OpenGLES
-framework QuartzCore -o /Users/gin/Documents/development/GLFun/build/Debug-iphonesimulator/GLFun.app/GLFun
ld: duplicate symbol
.objc_class_name_GLFunView in
/Users/gin/Documents/development/GLFun/build/GLFun.build/Debug-iphonesimulator/GLFun.build/Objects-normal/i386/GLFunView-7A51E8797CBB3D72.o
and
/Users/gin/Documents/development/GLFun/build/GLFun.build/Debug-iphonesimulator/GLFun.build/Objects-normal/i386/GLFunView-7A51E8797CBB3D72.o
From what I can see my project is identical to the one supplied with the book, which I can build and run successfully. What could possibly still be different that is causing this error?
Use diff(1) between the two projects' project.pbxproj files and find out.
Clean the project then try again, sometimes strange things happen. Check the build configurations between the two projects to see if they have any differences (building for the same architecture, sdk, etc.). Since you have duplicate symbols my first guess would be that Clean will solve your issue.