Why does Xcode mismatch Target membership? - macos

I have been creating an entire plethora of c++ syntax to help beginners. I use Xcode as my primary IDE. I tried running a program in "function" target but it keeps showing this error.
duplicate symbol _main in:
/Users/xivya/Library/Developer/Xcode/DerivedData/parentcpp-afpbdfpaaxeerfdalgncgzpkuaqt/Build/Intermediates.noindex/parentcpp.build/Debug/function.build/Objects-normal/x86_64/manipulator.o
/Users/xivya/Library/Developer/Xcode/DerivedData/parentcpp-afpbdfpaaxeerfdalgncgzpkuaqt/Build/Intermediates.noindex/parentcpp.build/Debug/function.build/Objects-normal/x86_64/pattern_program.o
ld: 1 duplicate symbol for architecture x86_64
clang: error: linker command failed with exit code 1 (use -v to see invocation)
I have selected "function" target from top-left, see image -
But at mid-right of the screen "array" target is selected under "Target membership". It selects itself automatically. Whenever I change my target to anything else no error happens. Any and all help will be highly appreciated!

I will divide the answer into two categories.
> Hunting down the issues
Whenever you've multiple targets lurking into your project structure, it may invoke the same error if you ignore just one thing. Suppose, you ran a target and wish to run some different target now. It's obvious that you will change the active scheme from the top-left. More obvious that you will choose the corresponding Build Phases BUT one might miss a minute option to change the target from "select a project or target" option lurking at that instance. If you didn't get me please, read it again or see these pictures.
There is nothing wrong here. pointers target has been selected and reference.cpp execute without any issue.
Now, what if we chose to run a different target? We will do all the customary things required.
We chose function target and in Build Phases we chose the required file. What we miss to observe is that pointers target is still been selected and Xcode hasn't changed it.
That creates a problem which leads to errors like this:
A possible error that can be displayed if one misses changing the target at a different instance, where Xcode should already have changed the target but has not.
Please keep those small things in mind.
> Meaning of error
Most of the times one might encounter "duplicate...etc.." type error. This may roughly mean that Xcode is not sure as to which target to run, as you might have forgotten to change the target at a different instance, probably in Build Phases pannel.

Related

How do I better diagnose linker error LNK2022?

I have a Visual Studio linker error that popped up recently. I stumbled upon a workaround but it is driving me crazy that I can't figure out why it is happening in the first place. I need to learn how to better diagnose it.
So my question is not about how to fix it, but how to diagnose it better. In short what I'm trying to learn here is how to get the linker (or some other tool) to tell me more info about the problem. So this question is not about this particular enum or how I coded it exactly.
The project is a C++/CLI project I have a managed enum which I wanted to refer to in several other header files. So I tried to put a forward declaration of it in the shared file that I use for all my other forward declarations. That started giving me this error.
1>profileregioncli.obj : error LNK2022: metadata operation failed (801311E4) : Duplicate managed types have different visibilities.
OK, fine. My forward declaration probably looks different to the linker than the definition. But I cannot see how the declarations are different in code. And technically, since the linker doesn't even bother to tell me exactly what type is involved I cannot even be 100% sure it's this enum.
So how do I determine following two things?
Exactly what symbol is mismatching AND
Exactly what is the difference (to the linker) between the two versions.
Obviously the first item I probably know. The second, not at all.
What I have tried so far
I've tried setting linker output to full verbosity but it doesn't tell me anything new. Here is the full linker output
1>------ Build started: Project: Core.Sdk, Configuration: Release x64 ------
1>Generating code
1>0 of 1470 functions ( 0.0%) were compiled, the rest were copied from previous compilation.
1> 0 functions were new in current compilation
1> 0 functions had inline decision re-evaluated but remain unchanged
1>Finished generating code
1>profileregioncli.obj : error LNK2022: metadata operation failed (801311E4) : Duplicate managed types have different visibilities.
1>LINK : fatal error LNK1255: link failed because of metadata errors
1>Done building project "corecli_v16.vcxproj" -- FAILED.
========== Build: 0 succeeded, 1 failed, 10 up-to-date, 0 skipped ==========
ILDasm Microsoft recommends trying to use ILDasm for this error but that doesn't work. When I tried using it from the command line as they described, it tells me I have to use it interactive mode. When I then try to use it in interactive mode and open up the .OBJ file in question, it wants an .EXE or DLL, not an .OBJ
MAP File I tried changing the linker settings to generate a MAP file but it never does. So I'm guessing thats not generated unless linking is successful.
Change Something, anything Sometimes the best way to figure out an obscure linker error is to make a change -- any change -- to force the linker to give you a different error so I tried changing the managed enum type to derive from System:UInt32 (a valid thing to do which I do with some of my other managed enums) just to see if I would get a different error. And I did get it to tell me that there were two different definitions of the enum in question, but not what they were. But aside from that, no extra information
But this still leads me to want to see the two definitions side-by-side. Not in code but as the linker sees them. How do I do that?

Linker command failed with exit code 1 (duplicate symbol)

I developing a game in Unity and I have used Admob, Facebook and GameCenter in it. It was working fine on iOS until I have added the OpenIAB for in-app purchase, though it works fine in Unity Editor.
I am getting this error in xcode:
duplicate symbol __Z14MakeStringCopyPKc in:
/Users/UmerAzeem/Library/Developer/Xcode/DerivedData/Unity-iPhone-ejwaywhkiokzjofdpwnbebkbleai/Build/Intermediates/Unity-iPhone.build/Debug-iphoneos/Unity-iPhone.build/Objects-normal/armv7/FBUnityUtility.o
/Users/UmerAzeem/Library/Developer/Xcode/DerivedData/Unity-iPhone-ejwaywhkiokzjofdpwnbebkbleai/Build/Intermediates/Unity-iPhone.build/Debug-iphoneos/Unity-iPhone.build/Objects-normal/armv7/AppStoreDelegate.o
ld: 1 duplicate symbol for architecture armv7 clang: error: linker
command failed with exit code 1 (use -v to see invocation)
See error screenshot here
I have tried almost all the solution that I could find over the internet, but still don't understand how can I remove this duplication error, I have tried looking for duplicate files too, but it also went in vain, someone help me out of this, would appreciate it.
Thanks.
Look up in your project for:
MakeStringCopy
And make sure it exists (if exists) only once. If it appears more then once, rename one (make sure to rename it where it being called as well) and try to build again.
I have recently face the same issue. I know Umer Azeem got the answer but to help someone else who may suffer from the same issue I was in.
According to my application flow I am using printer related third party class to print. To use that I have created object of that class in both of my files ImagePrintViewController and PrintResultViewController separately and passed required data to it.
In my scenario I am getting same error with variable name like _printerSetup in two of my files/Library/Developer/Xcode/DerivedData/../x86_64/ImagePrintViewController.o
and /Library/Developer/Xcode/DerivedData/../x86_64/PrintResultViewController.o.
I have search in both of my file for the above variable name. But I couldn't find that.
After searching long on this I got a idea to delete reference of my second file i.e. BRPrintResultViewController.h and BRPrintResultViewController.m after merging code in my first file.
With this I found my solution and my code runs fine after this.

Getting Framework related warning in Xcode 7.0

error I'm receiving is this
directory not found for option '-F/Applications/Xcode-beta.app/Contents/Developer/Platforms/iPhoneSimulator.platform/Developer/SDKs/iPhoneSimulator9.0.sdk/Developer/Library/Frameworks'
I have no idea why this is coming is this related to framework ?
I get rid of these by finding the target(s) that generated the error, then removing/deleting the (odd) path in the "Framework Search Paths" build setting:
What solves this for me is to create a new scheme. Click on Product-> Scheme -> New Scheme and just hit OK.
Then my app seems to build and run.
After much digging, I found this is actually related to my test target of my app.
The Fix
If you select your project, and look under ‘Targets’, you should see two targets. One is your app and the other one is your test. Under ‘Search Paths’ (in my test target), I found it was including two items under ‘Framework Search Paths’:
$(SDKROOT)/Developer/Library/Frameworks
$(inherited)
Deleting those entries in my older project then removed the warning. I did not have to make any changes to the other target.
Instead of deleting Framework Searh Paths (It causes other problems specially if you're using Fabric framework), you can change this line :
$(SDKROOT)/Developer/Library/Frameworks
with
$(SDKROOT)/Developer/Library/PrivateFrameworks
and it should work.
Please, let me this contribution.
I had this problem working with Xcode 8.0 (8A218a) and for a iOS Deployment Target 10.
Concretely, Xcode could not read the MapKit.framework. Error message said:
ld: warning: ignoring file /Users/Admin/Documents/APPS/PeekaWish/PeekaWish/MapKit.framework/MapKit, missing required architecture x86_64 in file /Users/Admin/Documents/APPS/PeekaWish/PeekaWish/MapKit.framework/MapKit (3 slices)
The worst thing was that I had not made any changes. The inconsistency apparently occurred after a bad Product Build (My project folder appear duplicated on the Xcode Editor, on Left Side, the Navigator Bar)
I lost a lot of time: linking repeatedly the MapKit.framework
Finally, I found the solution. It is a mix of above solutions.
1 STEP: Click on Product-> Scheme -> New Scheme and just hit OK
On TARGETS (the App) and Build Settings:
2 STEP: Deleting Framework Search Paths (leave these fields empty)
3 STEP: Always Search User Paths -> NO

Can certain compile errors be suppressed in the Error List Dialog?

When compiling a solution with many projects, if I make a compile time error in a project that many other projects use I'll get a flood of errors in the Error List window of visual studio:
Error 80 Metadata file
'C:\trunk\Projects\Libraries\K2DataBaseClient\bin\x64\Debug\CEPCortex.dll'
could not be found C:\trunk\Projects\TradeAiTeacher\CSC
These errors indicate that a project couldn't be built due to another project not being built. These types of errors cascade and don't really tell me anything useful as I know that its all due to a core project failing to build.
These errors often make it harder to find the actual error in the window.
Is there a way to tell visual studio to suppress this type of output and just show me the compile errors in cases like this to make it easy to find what actual code is broken?
Ideally it once the compile error has been fixed we can toggle this hiding off so I see all errors.
I had originally left this version agnostic but visual-studio 2013 is the version I am most concerned with.
No. The C# compiler categorically refuses to consider one error more "important" than another one. It cannot know how important an error can be, it doesn't know enough about the reason it had to produce the error. A missing reference assembly can produce a lot of errors because type definitions are missing. Of course the compiler cannot know the difference between them being undefined because of the missing assembly reference (ignore) or you mistyping a name (don't ignore).
Interpreting the Error List requires a massively parallel computing machine that's capable of high-speed correlation inference and pattern matching. With practical quantum computing still a distant future, you need to use the one that's readily available to any programmer, the one you have between your ears. Start at the top of the list. And work your way down, feeling less inclined to fix them as you progress down the list.
Never hesitate to rebuild before getting to the end of the list when you fixed a gross error. Like a missing assembly reference.
I've found the best way to work with existing the visual studio behavior is to use the advice in this link: and make the compiler stop after the first compile error.
This seems to get as close to solving my problem as you currently can.

How can I convince Xcode to emit a duplicate symbol linker error?

Here's a different one from the usual confusion over duplicate symbol errors... :-)
I'm working on some legacy Mac code in an Xcode project that has the same global, "trace", defined in several different source files - for instance:
File1.c: SInt32 trace;
File2.c: Boolean trace;
etc. It's clear the original author meant them to have file-specific scope, but just neglected to prefix any of these lines with "static". That's fine, easy enough to fix.
But I'm kind of shocked the linker isn't flagging these! It looks to me like Xcode's linker (I presume gnu ld) only emits duplicate symbol warnings or errors for functions, that are linked into the code segment - but not global variables that are linked into the data segment. Instead, it silently conflates them, which is causing bugs.
So... how do I convince Xcode to emit link errors for duplicate global variables? Or get this information in some other way that can be a routine part of my build?
Well, I thought I'd answered my own question... :-)
I posted earlier:
So if you're using Xcode with LLVM GCC
4.2, go to the build settings dialog, find the "LLVM GCC 4.2 - Code
Generation" section, and check the "No
Common Blocks" checkbox. This enables
the compiler's "-fno-common" option,
and changes the object file generation
so that ld will choke and emit an
error if you have two globals in
different source files with the same
name.
Unfortunately, that doesn't seem to solve all instances. It seems to work fine if all the globals have the same type.
But the example in the question is taken straight from the code, where a variable named "trace" is defined as a global in two different files with two different types. And that's still not caught by the build system when I check that checkbox.

Resources