Swift compiling error [duplicate] - ios

This question already has answers here:
'filenames are used to distinguish private declarations of the same name' error
(8 answers)
Closed 4 years ago.
my team and I are having problems for compile a Objective C project in Xcode 9.4. Anyone have an idea of what's happening??
<unknown>:0: error: filename "Message+CoreDataClass.swift" used twice: '/Users/josepmmirabent/houtel-ios-2016/Houtel2/DerivedData/Jumbotours/Build/Intermediates.noindex/Jumbotours.build/Debug-iphonesimulator/Jumbotours.build/DerivedSources/CoreDataGenerated/Model/Message+CoreDataClass.swift' and '/Users/josepmmirabent/houtel-ios-2016/Houtel2/DerivedData/Jumbotours/Build/Intermediates.noindex/Jumbotours.build/Debug-iphonesimulator/Jumbotours.build/DerivedSources/CoreDataGenerated/Model/Message+CoreDataClass.swift'
<unknown>:0: note: filenames are used to distinguish private declarations with the same name
<unknown>:0: error: filename "Message+CoreDataProperties.swift" used twice: '/Users/josepmmirabent/houtel-ios-2016/Houtel2/DerivedData/Jumbotours/Build/Intermediates.noindex/Jumbotours.build/Debug-iphonesimulator/Jumbotours.build/DerivedSources/CoreDataGenerated/Model/Message+CoreDataProperties.swift' and '/Users/josepmmirabent/houtel-ios-2016/Houtel2/DerivedData/Jumbotours/Build/Intermediates.noindex/Jumbotours.build/Debug-iphonesimulator/Jumbotours.build/DerivedSources/CoreDataGenerated/Model/Message+CoreDataProperties.swift'
<unknown>:0: note: filenames are used to distinguish private declarations with the same name
<unknown>:0: error: filename "Model+CoreDataModel.swift" used twice: '/Users/josepmmirabent/houtel-ios-2016/Houtel2/DerivedData/Jumbotours/Build/Intermediates.noindex/Jumbotours.build/Debug-iphonesimulator/Jumbotours.build/DerivedSources/CoreDataGenerated/Model/Model+CoreDataModel.swift' and '/Users/josepmmirabent/houtel-ios-2016/Houtel2/DerivedData/Jumbotours/Build/Intermediates.noindex/Jumbotours.build/Debug-iphonesimulator/Jumbotours.build/DerivedSources/CoreDataGenerated/Model/Model+CoreDataModel.swift'
<unknown>:0: note: filenames are used to distinguish private declarations with the same name
Command /Applications/Xcode.app/Contents/Developer/Toolchains/XcodeDefault.xctoolchain/usr/bin/swiftc failed with exit code 1
Thanks!

Go into your project settings > select your main app target > Build phases > Compile Sources and remove the duplicate entries in that list referring to the files listed in your compile errors. It looks like some files are listed for compilation twice which would cause this issue.
This is usually an issue in the xcode project file, I have had this issue occur due to manually resolving git conflicts in the project file.
If that does not solve your issue make sure you do not have files with the same name in the project.

Related

Swift expression evaluator (LLDB): error while loading Swift module

I have a target with mixed Swift and Objective-C code. I do the following:
I put a breakpoint on a line in a Swift file part of this target.
I run this target.
I type po $someVariableName in the debugger once it hits the breakpoint.
The debugger now shows a host of errors, ending with:
error: failed to import bridging header '/path/to/Bridging-Header.h'
Couldn't initialize Swift expression evaluator due to previous errors.
The output starts with:
Error while loading Swift module:
TARGET_NAME: /path/to/Bridging-Header.h:18:9: note: in file included from /path/to/Bridging-Header.h:18:
In between are a host of nullability annotation warnings and errors about unknown type names. Some errors come from bridging headers in the Carthage builds directory:
error: /path/to/project/Carthage/Build/iOS/Some.framework/Headers/Some-Swift.h
It seems as if whatever is executing after my po statement, lacks a few header imports or executes things in the wrong order. Any clue as to what could be wrong here?
I am using Xcode 11.4 (11E146)

Build failed with error Command /Applications/Xcode.app/Contents/Developer/Toolchains/XcodeDefault.xctoolchain/usr/bin/swiftc

I am using Xcode 8.2.1. I am also using CoreData in my project.
When I try to generate a build or when I archive I am seeing the following error. Files mentioned in the error also changes at times.
ERROR:
<unknown>:0: error: no such file or directory: '/Users/anuragparashar/Library/Developer/Xcode/DerivedData/app-drgjxhipxxqdrcatqfdgpayyxnud/Build/Intermediates/app.build/Debug-iphoneos/app.build/DerivedSources/CoreDataGenerated/app/BuildingRoofMapping+CoreDataClass.swift'
<unknown>:0: error: no such file or directory: '/Users/anuragparashar/Library/Developer/Xcode/DerivedData/app-drgjxhipxxqdrcatqfdgpayyxnud/Build/Intermediates/app.build/Debug-iphoneos/app.build/DerivedSources/CoreDataGenerated/app/BuildingRoofMapping+CoreDataProperties.swift'
<unknown>:0: error: no such file or directory: '/Users/anuragparashar/Library/Developer/Xcode/DerivedData/app-drgjxhipxxqdrcatqfdgpayyxnud/Build/Intermediates/app.build/Debug-iphoneos/app.build/DerivedSources/CoreDataGenerated/app/Region+CoreDataClass.swift'
<unknown>:0: error: no such file or directory: '/Users/anuragparashar/Library/Developer/Xcode/DerivedData/app-drgjxhipxxqdrcatqfdgpayyxnud/Build/Intermediates/app.build/Debug-iphoneos/app.build/DerivedSources/CoreDataGenerated/app/Region+CoreDataProperties.swift'
<unknown>:0: error: no such file or directory: '/Users/anuragparashar/Library/Developer/Xcode/DerivedData/app-drgjxhipxxqdrcatqfdgpayyxnud/Build/Intermediates/app.build/Debug-iphoneos/app.build/DerivedSources/CoreDataGenerated/app/StateRegionMapping+CoreDataProperties.swift'
<unknown>:0: error: no such file or directory: '/Users/anuragparashar/Library/Developer/Xcode/DerivedData/app-drgjxhipxxqdrcatqfdgpayyxnud/Build/Intermediates/app.build/Debug-iphoneos/app.build/DerivedSources/CoreDataGenerated/app/WalkingDoors+CoreDataClass.swift'
<unknown>:0: error: no such file or directory: '/Users/anuragparashar/Library/Developer/Xcode/DerivedData/app-drgjxhipxxqdrcatqfdgpayyxnud/Build/Intermediates/app.build/Debug-iphoneos/app.build/DerivedSources/CoreDataGenerated/app/WalkingDoors+CoreDataProperties.swift'
Command /Applications/Xcode.app/Contents/Developer/Toolchains/XcodeDefault.xctoolchain/usr/bin/swiftc failed with exit code 1
Here is how my CoreData Entities are configured:
Things I have Tried:
Check the location to see if files are actually missing, Files where present exactly at the same path.
I cleaned the build folder and removed derived data and build it again. Nothing helped.
Tried all the answers in this link. Nothing Worked.
Accepted Answer of this question doesn't seem to work either.
I am not sure why this error is coming. Any help is appreciated
EDIT
If I completely remove CoreData from my code then it Archives Successfully.
EDIT 2 :
When I change CodeGen to Manual/None and add files manually as suggested by #Anil . It builds successfully, But when I try to fetch the CoreData entity using :
let context = appDelegate.persistentContainer.viewContext
let buildingRoofMapping = BuildingRoofMapping(context:context)
It gives me run time error.
Error :
'NSInvalidArgumentException', reason: 'An NSManagedObject of class 'BuildingRoofMapping' must have a valid NSEntityDescription.'
EDIT 3:
Sample Code link. Run it in simulator. It crashes in fetchBasicPrice() of ViewController.swift file
I'll tell you what I have faced the same issue. In my case from Xcode 8 CoreData creates NSManagedObject class files in documents directory. I am sure you must have also created the same NSManagedObject files by your own.
You need to do following changes .xcdatamodel and regenerate a build. I have attached image below.
Make a change in Module and set it to Current Product Module and change the Codegen to Manual/None.
Let me know if you have more questions.
Below steps worked for me:
Change Module to Current Product Module and Codegen to Manual/None as suggested in Anil's Answer, for ALL the entities.
Manually Create CoreData files. For every entity two files are created.
One will be EntityName+CoreData with below contents :
import Foundation
import CoreData
public class EntityName: NSManagedObject {
}
another will be named : EntityName+Properties
import Foundation
import CoreData
extension BasicPrice {
#nonobjc public class func fetchRequest() -> NSFetchRequest<BasicPrice> {
return NSFetchRequest<BasicPrice>(entityName: "BasicPrice");}
#NSManaged public var var1 : String?
#NSManaged public var var2 : Int32
#NSManaged public var var3 : Float
#NSManaged public var var4 : Bool
}
NOTE:
This kind of class/structure is not my developed, it is followed by CoreData internally when we select Class Definition from CodeGen.
Hope it helps someone!
First, If you are checking or running the code in simulator and on changes in coreData code you are getting crashed, then you need to delete the app from the simulator and then again install and run. By doing this, changes that are made in your code do not make crash or show error.
I am writing it as an answer because I am not allowed to comment yet.
From your comments I have assumed that you have cleaned the derived folder as well as deleted the app from simulator as well as from device while building on it.
Did you try setting Build Active Architecture Only flag to No in the Project settings tab? If not please do that as well.
While archiving, the app will be built for all targets. And thus some issue might surface which you would have missed by setting the flag to Yes during development.

Using an Obj-C sub-project in a Swift application

My team has a few full Obj-C libraries we like te reuse in our projects. To do so, we usually set up a git submodule, and then add it to the xcode project as a sub-project (Using target dependency, link binary with library and updating the User Header Search Paths)
So far it's only been done in full Obj-C projects, and I'm now trying to use it in a Swift project but with very little success so far. I tried to add the briding-header file, referenced it in the project and filled it like so :
#import "MyLibraryHeader.h"
With the target header being in the User Header Search Paths.
It lets me build, but when using it in my Swift files:
let test = MyLib();
let secondTest = MyLib.classMethod1("some_arguments");
I get an EXC_BAD_INSTRUCTION on secondTest, and the following logs in the debugger:
(lldb) po test
error: <EXPR>:1:1: error: use of unresolved identifier 'test'
(lldb) po secondTest
error: Error in auto-import:
failed to get module 'MyProject' from AST context:
/Users/siegele/Sources/MyProject_iOS/MyProject/Classes/MyProject-Bridging-Header.h:12:9: error: 'MyLibraryHeader.h' file not found
#import "MyLibraryHeader.h"
^
failed to import bridging header '/Users/siegele/Sources/MyProject_iOS/MyProject/Classes/MyProject-Bridging-Header.h'
Found the following question with no answer : Xcode 6 crashing when using Objective-C subproject inside Swift
Any help would be appreciated.
I followed the HockeyApp tutorial that can be found here:
http://support.hockeyapp.net/kb/client-integration-ios-mac-os-x/integrate-hockeyapp-for-ios-as-a-subproject
In the end, I was on the right tracks but messed up the Header Search Paths:
Add subproject xcodeproj to the workspace
On the main project : Link binary with library, and add the subproject product library (Bonus points : add it as a target dependency too)
Update Header Search Paths (not User Header Search Paths) accordingly
Import your Library.h in the main project Bridging-Header.h file
What threw me off for a while is that the Swift Compiler setting for the Objective-C Bridging Header was not set automatically. Check the Build Settings for your target and ensure the "Objective-C Bridging Header" setting is not blank.

Duplicate symbols for architecture x86_64 under Xcode

I now have the same question with above title but have not found the right answer yet. I got the error:
/Users/nle/Library/Developer/Xcode/DerivedData/TestMoboSDK-Client-cgodalyxmwqzynaxfbbewrooymnq/Build/Intermediates/TestMoboSDK-Client.build/Debug-iphonesimulator/TestMoboSDK-Client.build/Objects-normal/x86_64/MoboSDK.o
/Users/nle/Library/Developer/Xcode/DerivedData/TestMoboSDK-Client-cgodalyxmwqzynaxfbbewrooymnq/Build/Products/Debug-iphonesimulator/libMoboSDK.a(MoboSDK.o)
duplicate symbol _OBJC_METACLASS_$_MoboSDK in:
/Users/nle/Library/Developer/Xcode/DerivedData/TestMoboSDK-Client-cgodalyxmwqzynaxfbbewrooymnq/Build/Intermediates/TestMoboSDK-Client.build/Debug-iphonesimulator/TestMoboSDK-Client.build/Objects-normal/x86_64/MoboSDK.o
/Users/nle/Library/Developer/Xcode/DerivedData/TestMoboSDK-Client-cgodalyxmwqzynaxfbbewrooymnq/Build/Products/Debug-iphonesimulator/libMoboSDK.a(MoboSDK.o)
ld: 75 duplicate symbols for architecture x86_64
clang: error: linker command failed with exit code 1 (use -v to see invocation)
Any help is appreciated.
Finally I find out the reason of this error cause I added -ObjC to the Other Linker Flags. After remove this value then I can build my project successfully, but I don't know why. Can anyone explain this?
For me, changing 'No Common Blocks' from Yes to No ( under Targets->Build Settings->Apple LLVM - Code Generation ) fixed the problem.
Stupid one, but make sure you haven't #imported a .m file by mistake somewhere
75 duplicate symbols for architecture x86_64
Means that you have loaded same functions twice.
As the issue disappear after removing -ObjC from Other Linker Flags,
this means that this option result that functions loads twice:
from Technical Q&A
This flag causes the linker to load every object file in the library
that defines an Objective-C class or category. While this option will
typically result in a larger executable (due to additional object code
loaded into the application), it will allow the successful creation of
effective Objective-C static libraries that contain categories on
existing classes.
https://developer.apple.com/library/content/qa/qa1490/_index.html
In my case, I just created a header file to define constant strings like this:
NSString *const AppDescriptionString = #"Healthy is the best way to keep fit";
I solved this scenario by using static:
static NSString *const AppDescriptionString = #"Healthy is the best way to keep fit";
Happens also when you declare const variables with same name in different class:
in file Message.m
const int kMessageLength = 36;
#implementation Message
#end
in file Chat.m
const int kMessageLength = 20;
#implementation Chat
#end
I have same problem.
In Xcode 7.2 in path Project Target > Build Setting > No Common Blocks, i change it to NO.
I found the accepted answer touches on the problem but didn't help me solve it, hopefully this answer will help with this very frustrating issue.
duplicate symbol _OBJC_IVAR_$_BLoginViewController._hud in:
17 duplicate symbols for architecture x86_64
"Means that you have loaded same functions twice. As the issue disappear after removing -ObjC from Other Linker Flags, this means that this option result that functions loads twice:"
In layman's terms this means we have two files in our project with exactly the same name. Maybe you are combining one project into another one? Have a look at the errors above the "duplicate symbols" error to see which folder is duplicated, in my case it was BLoginViewController.
For example, in the image below you can see I have two BImageViewControllers, for me this is what was causing the issue.
As soon as I deleted one then the issue vanished :)
This occurred on me when I accepted "recommended settings" pop-up on a project that I develop two years ago in Objective-C.
The problem was that when you accepted the "recommended settings" update, Xcode automatically changed or added some build settings, including GCC_NO_COMMON_BLOCKS = YES;.
This made the build failed with the duplicate symbol error in my updated project. So I changed No Common Block to NO in my build settings and the error was gone.
I experienced this issue after installing Cocoapods. Now happens everytime I update some pods. Solution I've found:
Go to terminal:
1) pod deintegrate
2) pod install
Also, check the item "Always Embed Swift Libraries" in your Build Settings. It should be "faded" indicating it is using the default configuration. If its set to a manual YES, hit delete over it to revert it to the default configuration. This stopped the behavior.
Fastest way to find the duplicate is:
Go to Targets
Go to Build Phases
Go to Compile Sources
Delete duplicate files.
Go to Targets
Select Build Settings
Search for "No Common Blocks", select it to NO.
It worked for me
Following steps solved the issue for me.
Go to Build Phases in Target settings.
Go to “Link Binary With Libraries”.
Check if any of the libraries exist twice.
Build again.
Remove -ObjC from Other Linker Flags or
Please check you imported any .m file instead of .h by mistake.
Update answer for 2021, Xcode 12.X:
pod deintegrate
pod install
Hope this helps!
My situation with some legacy project opened in Xcode 7.3 was:
duplicate symbol _SomeEnumState in:
followed with list of two unrelated files.o, then this was repeated couple of times, then finally:
ld: 8 duplicate symbols for architecture x86_64
clang: error: linker command failed with exit code 1 (use -v to see invocation)
What solved it for me was changing enum declaration from:
enum SomeEnumState {
SomeEnumStateActive = 0,
SomeEnumStateUsed = 1,
SomeEnumStateHidden = 2
} SomeEnumState;
to this:
typedef NS_ENUM(NSUInteger, SomeEnumState) {
SomeEnumStateActive = 0,
SomeEnumStateUsed = 1,
SomeEnumStateHidden = 2
};
If somebody has explanation for this, please enlighten me.
Defining same variable under #implementation in more than one class also can cause this problem.
In my case, there were two file by same name in the location
Targets > Build Phases > Compile Sources and delete any duplicate files.
For me during the Xcode8 recommended project settings update "No Common Blocks" to YES which causes this issue.
My problem was that I had 5 duplicate symbols for architecture x86_64. After reading this post and their answers, I try with the common solution about change GCC_NO_COMMON_BLOCKS = YES to NO
But, instead of working for me, I went from 5 duplicates to 1 duplicate...
So, I paid attention to that last error, and I realized what was my problem, and it was an "incompatibility" with these packages (I had both in package.json):
rn-fetch-blob
react-native-blob-util
The message was clear about it, and I remove rn-fetch-blob because I have not idea why it was in my project, but, I only used with jest and delete it, it wasn't a problem.
So, after removing that package, and run yarn again, problem solved... And without changing the GCC_NO_COMMON_BLOCKS
Today , I got the same error . The error's key word is duplicate. I fix it by:
1. Remove the duplicate file at Build Phases-->Compile Sources
2. If you can not remove it at Build Phases, you need find the file at your project and remove the reference by DELETE :
3. Add the file to your project again
4. Add the file's .m to your Build Phases-->Compile Sources again
5. Build your project, the error will disappear
Another silly mistake that will cause this error is repeated files. I accidentally copied some files twice. First I went to Targets -> Build Phases -> Compile sources. There I noticed some files on that list twice and their locations.
Make sure you haven't imported a .m file by accident, you might want to delete your derived data in the Projects Window and then build and run again.
I got the same error when I added a pod repository
pod 'SWRevealViewController'
for an already added source code (SWRevealViewController) from gitHub. So, the error will be fixed by either removing the source code or pod repository.
Case # 2:
The 2nd time, this error appeared when I declare a constant in .h file.
NSString * const SomeConstant = #"SomeValue";
#interface AppDelegate : UIResponder <UIApplicationDelegate> {
...
...
None of above solutions works for me, I just fixed it myself.
I got duplicate symbol of my core data model which I make it myself, but
in my .xcdatamodeld inspector, I choose Class Definition of Codegen property, I guess that's what's wrong with. Then I choose Manual/None,it got fixed.
Hope this can be helpful for you!
For anyone else who is having this issue, I didn't see my resolution in any of these answers.
After having a .pbxproj merge conflict which was manually addressed (albeit poorly), there were duplicate references to individual class files in the .pbxproj. Deleting those from the Project > Build Phases > Compile Sources fixed everything for me.
Hope this helps someone down the line.
Similar to Juice007, I had declared and initialized a C type variable in two different .m files (that weren't imported!)
BOOL myVar = NO;
however, this method of declaring and initializing a variable, even in .m, even in #implementation grants it global scope. Your options are:
Declare it as static, to limit the scope to class:
static BOOL myVar = NO;
Remove the initialization (which will make the two classes share the global var):
BOOL myVar;
-(void) init{
myVar = NO;
}
Declare it as a property:
#property BOOL myVar;
Declare it as a proper iVar in the #interface
#interface myClass(){
BOOL myVar;
}
#end
In my case I had two main() methods defined in my project and removing one solved the issue.
The answers above didn't work for me. Here's how I got around it:
1) in finder, delete the entire Pods folder and Podfile.lock file
2) close the xcode project
3) run pod install in the terminal
4) open the xcode project, run the clean build command
Worked for me after that.
Because I haven't seen this answer:
Uninstall and reinstall your podfiles! Remove or uninstall library previously added : cocoapods
I've run into this issue over 3 times building my app and every time this is what fixes it. :)
I've just had this error as well. Found that the problem was variables declared with global scope, with the same names, were being repeated throughout the files being compiled into the program. Once changing the global variables to local scope to the pseudo-main function the error was resolved.

Building OpenSceneGraph for iOS

I'm getting errors in XCode attempting to build OSG for iOS 7.0. I've followed these instructions:
http://www.openscenegraph.org/index.php/documentation/platform-specifics/ios/23-configuring-cmake-for-ios
with the additional step of changing the framework version to 7.0 in the CMakeLists.txt file, as using the default of 6.0 caused XCode to complain about an unknown framework. I chose the IPHONE_SIMULATOR option.
When I attempt to build the project after generating it with CMake, I get three errors in osgDB complaining about stat64, and one about a missing header (perhaps related but I get the feeling something else is going on):
/Users/clay2/src/OpenSceneGraph-3.2.0/src/osgDB/FileUtils.cpp:153:9: error: call to unavailable function 'stat64': not available on iOS
if( stat64( path.c_str(), &stbuf ) == 0 )
^~~~~~
In file included from /Users/clay2/src/OpenSceneGraph-3.2.0/src/osgDB/FileUtils.cpp:87:
/Applications/Xcode.app/Contents/Developer/Platforms/MacOSX.platform/Developer/SDKs/MacOSX10.9.sdk/usr/include/sys/stat.h:380:5: note: candidate function has been explicitly made unavailable
int stat64(const char *, struct stat64 *) __OSX_AVAILABLE_BUT_DEPRECATED(__MAC_10_5,__MAC_10_6,__IPHONE_NA,__IPHONE_NA);
^
/Users/clay2/src/OpenSceneGraph-3.2.0/src/osgDB/FileUtils.cpp:176:13: error: call to unavailable function 'stat64': not available on iOS
if( stat64( dir.c_str(), &stbuf ) < 0 )
^~~~~~
In file included from /Users/clay2/src/OpenSceneGraph-3.2.0/src/osgDB/FileUtils.cpp:87:
/Applications/Xcode.app/Contents/Developer/Platforms/MacOSX.platform/Developer/SDKs/MacOSX10.9.sdk/usr/include/sys/stat.h:380:5: note: candidate function has been explicitly made unavailable
int stat64(const char *, struct stat64 *) __OSX_AVAILABLE_BUT_DEPRECATED(__MAC_10_5,__MAC_10_6,__IPHONE_NA,__IPHONE_NA);
^
/Users/clay2/src/OpenSceneGraph-3.2.0/src/osgDB/FileUtils.cpp:301:10: error: call to unavailable function 'stat64': not available on iOS
if ( stat64(filename.c_str(), &fileStat) != 0 )
^~~~~~
In file included from /Users/clay2/src/OpenSceneGraph-3.2.0/src/osgDB/FileUtils.cpp:87:
/Applications/Xcode.app/Contents/Developer/Platforms/MacOSX.platform/Developer/SDKs/MacOSX10.9.sdk/usr/include/sys/stat.h:380:5: note: candidate function has been explicitly made unavailable
int stat64(const char *, struct stat64 *) __OSX_AVAILABLE_BUT_DEPRECATED(__MAC_10_5,__MAC_10_6,__IPHONE_NA,__IPHONE_NA);
^
/Users/clay2/src/OpenSceneGraph-3.2.0/src/osgDB/FileUtils.cpp:881:18: fatal error: 'CoreServices/CoreServices.h' file not found
#include <CoreServices/CoreServices.h>
^
4 errors generated.
CMake version is 2.8-12, OSG 3.2.0, XCode 5.0.2.
Various things I've tried:
iphone instead of iphone_simulator setting; iphone complains about openthreads being a dynamic library, even though I unchecked DYNAMIC_OPENTHREADS in cmake. It does, however, appear to make the other errors go away.
Blowing away the build directory and re-doing the config step, several times
Manually setting the framework settings for ios in xcode after configuration
I did previously get an OSX build of OSG to work without issue, for what it's worth.

Resources