I’ve looked at all the Mach-0 Linker questions on SO but can’t find any that seem specific to my problem. My app was compiling without issues for weeks in the debugger and this seemed to come out of the blue. Problem seems to be pointing to two source files (keypad.o and setoutput.o). Previous Mach-O errors have usually told me that so-and-so can’t be referenced from ‘some file’.o, but no such easy clues in this case. Error shown below:
ld "/Users/Administrator/Library/Developer/Xcode/DerivedData/MacOS_Cover-aemdqkcjvuomtjfhkycsyowsgisn/Build/Products/Debug/MacOS Cover.app/Contents/MacOS/MacOS Cover" normal x86_64
cd "/Users/Administrator/Desktop/MacOS Cover"
setenv MACOSX_DEPLOYMENT_TARGET 10.6
/Developer/usr/bin/clang -arch x86_64 -isysroot /Developer/SDKs/MacOSX10.6.sdk -L/Users Administrator/Library/Developer/Xcode/DerivedData/MacOS_Cover-aemdqkcjvuomtjfhkycsyowsgisn/Build/Products/Debug -F/Users/Administrator/Library/Developer/Xcode/DerivedData/MacOS_Cover-aemdqkcjvuomtjfhkycsyowsgisn/Build/Products/Debug -filelist "/Users/Administrator/Library/Developer/Xcode/DerivedData/MacOS_Cover-aemdqkcjvuomtjfhkycsyowsgisn/Build/Intermediates/MacOS Cover.build/Debug/MacOS Cover.build/Objects-normal/x86_64/MacOS Cover.LinkFileList" -mmacosx-version-min=10.6 -framework Cocoa -o "/Users/Administrator/Library/Developer/Xcode/DerivedData/MacOS_Cover-aemdqkcjvuomtjfhkycsyowsgisn/Build/Products/Debug/MacOS Cover.app/Contents/MacOS/MacOS Cover"
ld: duplicate symbol _required in /Users/Administrator/Library/Developer/Xcode/DerivedData/MacOS_Cover-aemdqkcjvuomtjfhkycsyowsgisn/Build/Intermediates/MacOS Cover.build/Debug/MacOS Cover.build/Objects-normal/x86_64/keypad.o and /Users/Administrator/Library/Developer/Xcode/DerivedData/MacOS_Cover-aemdqkcjvuomtjfhkycsyowsgisn/Build/Intermediates/MacOS Cover.build/Debug/MacOS Cover.build/Objects-normal/x86_64/setoutput.o for architecture x86_64
clang: error: linker command failed with exit code 1 (use -v to see invocation)
Command /Developer/usr/bin/clang failed with exit code 1
I’ve tried throwing away all the derived data files etc (which seem to spring right back a second later). I’d appreciate if anyone could help me resolve this please.
Those two object files are each exporting a symbol with the same name (required; the underscore is an artifact of the compiler). Depending on exactly what you intend for those two, you might need to: a) rename one or both; or b) make one or both have internal linkage, usually by marking them static.
There's a good chance you think there's just one such symbol because you declared it in a header that both source files include. But, you may have unintentionally defined the symbol in the header, rather than just declaring it. Then, it's defined in every source file that includes it. You would have to show your source code with the declaration/definition of required and how it's brought into each source file.
Related
Question: How do I use PCL in the context of an Objective-C Cocoa (OSX, not iOS) app?
Tearing my hair out over this one.I can't get libpcl to link properly with my Objective C project in Xcode. I have checked and re-checked everything I can possibly think of. Probably doing something dumb, but I'm stumped.
Actual error is linker:
Undefined symbols for architecture x86_64:
"pcl::PassThrough<pcl::PointXYZ>::applyFilterIndices(std::__1::vector<int, std::__1::allocator<int> >&)", referenced from:
pcl::PassThrough<pcl::PointXYZ>::applyFilter(std::__1::vector<int, std::__1::allocator<int> >&) in PCLProcess.o
ld: symbol(s) not found for architecture x86_64
The code I'm trying to compile is the standard tutorial code available here:
http://pointclouds.org/documentation/tutorials/passthrough.php#passthrough
I CAN get it to work without Xcode (using Cmake and command line compiling exactly as in the tutorial)
I CAN create a "command line" project and compile and link a one-off CPP file using Xcode
The issue is the same no matter what version of PCL I've tried. Macports, binary distro, self-compiled 1.6 and trunk. All the same result.
I've tried several different machines, OSX 10.7 and 10.8, same issue on both.
I've even run nm against the dylib to verify the missing symbols are in the library I'm linking (filters in this case)
Any thoughts much appreciated, I've lost half a week to this.
See this screenshot for a detailed error message.
Here is the code in question:
//PCLProcess.h
#import <Foundation/Foundation.h>
#interface PCLProcess : NSObject
#end
//PCLProcess.mm
#import "PCLProcess.h"
#include <pcl/point_types.h>
#include <pcl/filters/passthrough.h>
#implementation PCLProcess
-(void)tryThis{
// Code cut and pasted from tutoral (see link above)
}
#end
Update
Here is one more clue. I am in over my head with respect to compilers/linkers and how they work, but now I think I know what is happening but not why (or how to fix it).
I ran the linker tool manually, and out of desperation I started plugging in obsolete flags just to see what the results were. The previous error (above) identifies the missing symbols as ""pcl::PassThrough::applyFilterIndices(std::__1::vector >&)" but ld -y gave me this:
ld: warning: option -y is obsolete and being ignored
Undefined symbols for architecture x86_64:"__ZN3pcl11PassThroughINS_8PointXYZEE18applyFilterIndicesERNSt3__16vectorIiNS3_9allocatorIiEEEE", referenced from:__ZN3pcl11PassThroughINS_8PointXYZEE11applyFilterERNSt3__16vectorIiNS3_9allocatorIiEEEE in PCLProcess.o
ld: symbol(s) not found for architecture x86_64
So then I went looking for that symbol and, sure enough, it's missing (or different):
nm /opt/local/lib/libpcl_filters.dylib | grep __ZN3pcl11PassThroughINS_8PointXYZEE18applyFilterIndices
00000000000a0fa0
T __ZN3pcl11PassThroughINS_8PointXYZEE18applyFilterIndicesERSt6vectorIiSaIiEE
I suspect name mangling? But again, I'm not really sure what I'm talking about at this point or (more importantly) how to fix it.
Short answer:
Two Build settings under "Build Options":
C++ Language Dialect: GNU++98[-std=gnu++98]
C++ Standard Library: libstdc++ (GNU C++ standard library)
This second setting (C++ Standard Library) is the crucial one; Using libc++ will produce the "undefined symbols" linker errors shown in the question above.
Details for anyone trying this:
This works with Xcode 4.62, llvm4.2, libpcl 1.7 (currently dev, I compiled from trunk) and boost 1.53. Along the way I ran into a known issue with Boost and Cocoa involving the use of nil (see this link:https://svn.boost.org/trac/boost/ticket/5010) and also some strangeness with boost traits (see this:c++: Boost 1.48 type traits and Cocoa inclusion weirdness) Consequently I ended up including PCL headers as follows:
#define nil Boost_nil
#define Nil Boost_Nil
#ifdef check
#undef check
#endif
#include <pcl/pcl_base.h>
#include <pcl/point_types.h>
#include <pcl/filters/passthrough.h>
#undef Nil
#undef nil
i tried to port the SimpleFTPsample from apple from this IOS project to my OSX project, but when I try to build I get the following error.
Undefined symbols for architecture x86_64:
"_OBJC_CLASS_$_NetworkManager", referenced from:
objc-class-ref in Document-DAE96E3625ECED63.o
ld: symbol(s) not found for architecture x86_64
clang: error: linker command failed with exit code 1 (use -v to see invocation)
I've searched online, and have been checking all the code I copied twice, all frameworks are added, and the headers included. could somebody please help me to find whats wrong, or even better explain what this means so i can solve it myself in the future? how can i find out what is wrong in the NetworkManager class? i dont get any errors before compiling.
thanks
---EDIT---
forgot to mention that i only need the PUT part of the code in the example, i am only examinating that part. all the rest hasnt been copied over. i copied the NetworkManager.h, NetworkManager.m and copied over the parts of the code that i need from the PUT file.
Usually, when the linker says “what? I've never heard of that class”, it means that the module that implements that class (SomeClass.m) didn't get compiled.
There are two ways that that happens:
Compilation failed
This one would cause an error asking for SomeClass.o (in your case, NetworkManager.o). That's not the error you got, but similar enough that I felt it was worth listing here.
The linker will want an object file, which is produced by a successful compilation. If compilation fails, the object file doesn't exist, so you'll get the “file not found: blah/blah/blah/SomeClass.o” error.
999‰ of compilation failures are because the module contains an error—a syntax error, an unrecognized name (e.g., spelling error/typo), or some other flaw that fails compilation.
Build errors causing other build errors is fairly common, so you should always tackle errors from the top of the list downward.
The solution to this one is to navigate to SomeClass.m and fix everything that's wrong with it, and then try the build again.
You didn't even try to compile it
This is the one you ran into.
Every target has a list of build phases, each describing something that needs to be done to build the target. Most targets have at least Compile Sources and Link Binary with Libraries phases. Every build phase has a list of input files.
The input files for a Compile Sources phase are the module files that Xcode will try to compile. Link Binary with Libraries will implicitly link in everything that the compiler produced—all of the object files—along with the libraries in its list, such as Cocoa.framework.
For each target, Xcode will only try to compile modules that are in that target's Compile Sources build phase.
It's quite possible to forget to add a module to a target but still try to use it in another module within the same target. Maybe you made the module a long time ago for another target, and now want to use that code in the target you're working on now, or maybe you simply forgot to check the box when you created the module or otherwise added it to the project.
Either way, you'll get that error message, telling you that the module whose contents you're trying to use isn't listed for compilation in the target you're trying to use it in.
There are two ways to fix it:
Select or navigate to the “missing” module and show the File Inspector (⌘⌥1), and check the box for the appropriate target under “Target Membership”.
Select the project object in the Project Navigator, select the target within the editor, switch to the Build Phases tab, and drag the “missing” module from the Project Navigator into the Compile Sources build phase.
The way to prevent it is to make sure the relevant targets are checked when you add the module to the project. This includes both creating new modules and adding modules you've obtained from other people (e.g., open source reusable classes).
I'm developing an iPad application which relies on two static utility libraries (libBFSDK & libBetfair-Platform). Both static libraries include AFNetworking. When I try to include the two static libraries in my iPad application, I get a linking error like:
duplicate symbol _OBJC_METACLASS_$_AFImageCache in:
/Users/osheas/Library/Developer/Xcode/DerivedData/Betfair-gnnjnwtovdmtoxakuxbjyvetciyy/Build/Products/Debug-iphonesimulator/libBFSDK.a(UIImageView+AFNetworking.o)
/Users/osheas/Library/Developer/Xcode/DerivedData/Betfair-gnnjnwtovdmtoxakuxbjyvetciyy/Build/Products/Debug-iphonesimulator/libBetfair-Platform.a(UIImageView+AFNetworking.o)
ld: 86 duplicate symbols for architecture i386
clang: error: linker command failed with exit code 1 (use -v to see invocation)
UIImageView+AFNetworking is part of AFNetworking. Both static libraries include AFNetworking. As a result, I get duplicate symbols for UIImageView+AFNetworking.
Anyone have ideas on a workaround for this? I have access to the source code for the two static libraries, but I'm still not sure how to solve this problem.
Thanks & please let me know if you need any other details,
Sean
PS - FWIW I'm running Xcode 4.5 & I need to be able to deploy to iOS 4.x devices.
Since you have access to the source for the static libs, you could use the preprocessor to rename the AFNetworking symbols to something unique.
Add flags for each duplicate symbol to your "Other C Flags" build setting with the format
-AFNetworkingSymbol=UniqueAFNetworkingSymbol
This will still result in duplicate code, but should allow you to have multiple copies of AFNetworking without modifying the source.
More info
Ideally, most open source Obj-C code will move to solutions like CocoaPods and just specify dependencies instead of bundling them.
Apparently, this is a relatively common occurrence. See https://github.com/square/PonyDebugger/issues/36 for more details.
This is the simplest solution I have seen to this problem. I have tested it and it works.
http://blog.sigmapoint.pl/avoiding-dependency-collisions-in-ios-static-library-managed-by-cocoapods/
you check _AFImageCache has tow file in your project and remove one.
this can help you.
I know this is a long shot but, I've been having trouble with a linker error that I specifically don't understand. Please refer to the picture below.
The project contains 4 targets. This error points specifically to one target that is a BSD/Shell helper tool written in c.
I'm sorry for being vague, as I don't fully understand what might be the problem. Any suggestions? Thank you.
Usually, this means that the source file that defines main() hasn’t been added to the corresponding target.
Another possible reason is that the source file that contains main() is being compiled for an architecture (e.g. i386 only) but the target/executable specifies a different architecture (e.g. x86_64 only or fat/universal).
One strategy to help with diagnosing this issue is running xcodebuild against your project+target to inspect the commands that are being issued to compile and link the target.
When all else fails, remove the target and add it again.
Did you #include the appropriate files?
I am trying to link a statically created .a library with another piece of C code.
However, in the final executable several symbols (function names) are are found missing when seen with the nm command. This is due to the fact that the linker (gcc being called) is stripping the symbols which are not referenced in the other piece of C code that is being linked with the library. The function symbol that I am trying to find with the nm command is visible in the .a library.
How can I make the linker not strip the symbols omitted this way?
Compile in gcc with -dynamic to force the compiler to include all symbols. But make sure that's what you really want, since it's wasteful.
Might be useful for some static factory patterns.
Generally, the linker does strip out other symbols - mainly for
Reduce the final size of the executable
Speed up the execution of the program
There are two trains of thoughts here:
When you use the option -O as part of the gcc command line, that is optimizing the code and thus all debugging information gets stripped out, and hence the linker will automatically do the same.
When you use the option -g as part of the gcc command line, that includes all debugging information so that the executable can be loaded under the debugger with symbols intact.
In essence those two are mutually exclusive - you cannot have both combined.
So it depends on which switches did you use for this to happen. Usually, -g switch is for internal debugging and testing prior to public release. The opposite would be something like this -O2 which makes the compiler smart enough to generate a executable that would be considered optimized such as removing dead variables, unrolling loops and so on.
Hope this helps and gives you the hint
Normally you need to call some registration function in your application to generate such a reference. Of course if you don't have access to the code of the first library, you can only use the -g option as described by tommieb75.