Xcode 重复符号 _main
声明:本页面是StackOverFlow热门问题的中英对照翻译,遵循CC BY-SA 4.0协议,如果您需要使用它,必须同样遵循CC BY-SA许可,注明原文地址和作者信息,同时你必须将它归于原作者(不是我):StackOverFlow
原文地址: http://stackoverflow.com/questions/2535265/
Warning: these are provided under cc-by-sa 4.0 license. You are free to use/share it, But you must attribute it to the original authors (not me):
StackOverFlow
Xcode duplicate symbol _main
提问by Prithvi Raj
I'm getting the following error in Xcode 3.2.1 on Snow Leopard 10.6.2 whenever I try to compile any iPhone application generated by Appcelerator Titanium. However, the build error only appears when I select iPhone simulator on the architecture menu and if I select the iPhone device, I am able to run the app on my device .
每当我尝试编译由 Appcelerator Titanium 生成的任何 iPhone 应用程序时,我都会在 Snow Leopard 10.6.2 上的 Xcode 3.2.1 中收到以下错误。但是,构建错误仅在我在架构菜单上选择 iPhone 模拟器时出现,如果我选择 iPhone 设备,我就可以在我的设备上运行该应用程序。
Further more, the iPhone simulator launches successfully and executes the program directly from the Titanium environment which uses Xcode to build .
此外,iPhone 模拟器成功启动并直接从使用 Xcode 构建的 Titanium 环境中执行程序。
Why is this happening ?
为什么会这样?
ld: duplicate symbol _main in Resources/libTitanium.a(main.o) and /Users/prithviraj/Documents/project/Final/build/iphone/build/Final.build/Debug-iphonesimulator/Final.build/Objects-normal/i386/main.o collect2: ld returned 1 exit status Command /Developer/Platforms/iPhoneSimulator.platform/Developer/usr/bin/gcc-4.2 failed with exit code 1
ld: duplicate symbol _main in Resources/libTitanium.a(main.o) and /Users/prithviraj/Documents/project/Final/build/iphone/build/Final.build/Debug-iphonesimulator/Final.build/Objects-normal/i386/main.o collect2: ld returned 1 exit status Command /Developer/Platforms/iPhoneSimulator.platform/Developer/usr/bin/gcc-4.2 failed with exit code 1
回答by warrenm
I can't tell you why this is happening, but I can suggest a workaround. When I commented out the entire contents of the main.m file that was generated for my Titanium project, I was able to compile successfully and run on the Simulator. Let me know if that works for you.
我不能告诉你为什么会发生这种情况,但我可以建议一个解决方法。当我注释掉为我的 Titanium 项目生成的 main.m 文件的全部内容时,我能够成功编译并在模拟器上运行。让我知道这是否适合您。
回答by Vishal Jaiswal
Check to see if you have multiple declarations of main function in your project.
检查您的项目中是否有多个 main 函数声明。
回答by William Jockusch
回答by gstroup
I had a similar problem. A unit test class was accidentally included in my build. If you search your project for "main(" you'll probably find the duplicate functions.
我有一个类似的问题。我的构建中不小心包含了一个单元测试类。如果您在项目中搜索“main(”,您可能会找到重复的函数。
回答by Arthur Rocha de Menezes
This happened to me for 2 reasons:
这发生在我身上有两个原因:
1: Class A calls class B and both had imported the same class. Fix it by importing the class in .m file.
1:A 类调用B 类并且两者都导入了相同的类。通过在 .m 文件中导入类来修复它。
2: Two classes have a constant with the same name (even if the constant is defined in the .m file). Fix it by changing the name of the constants.
2:两个类有一个同名的常量(即使这个常量是在 .m 文件中定义的)。通过更改常量的名称来修复它。
回答by helsont
I had this problem because I define a file as such:
我有这个问题,因为我定义了一个文件:
@UIApplicationMain
class AppDelegate: UIResponder, UIApplicationDelegate {
...
}
And also had a file main.m:
还有一个文件main.m:
int main(int argc, char* argv[])
{
@autoreleasepool {
int retVal = UIApplicationMain(argc, argv, nil, @"AppDelegate");
return retVal;
}
}
回答by Venuu Munnuruu
I spent more than an hour in searching for a correct answer but nothing worked for me. Finally the xcode it self telling something is duplicated, so go to that particular folder(in this case: /Users/prithviraj/Documents/project/Final/build/iphone/build/Final.build/Debug-iphonesimulator/Final.build/Objects-normal/i386/main.o) and delete all the files and also check same in your project whether that particular class/interface is declared twice if yes delete it.
我花了一个多小时来寻找正确的答案,但没有任何效果对我有用。最后,它自己告诉某些东西的 xcode 是重复的,所以转到那个特定的文件夹(在这种情况下:/Users/prithviraj/Documents/project/Final/build/iphone/build/Final.build/Debug-iphonesimulator/Final.build/ Objects-normal/i386/main.o) 并删除所有文件,并在您的项目中检查相同的特定类/接口是否声明了两次,如果是,则删除它。
After deletion clean and run the project.
删除后清理并运行项目。
It worked for me hope this helps(-_-).
它对我有用,希望这会有所帮助(-_-)。
回答by Doug Squires
Seems as though there are multiple ways to get into this state. Mine was different. I read a hint where you could drag from a .xib event selector into the .h implementation of your view controller and it would auto-gen your methods. It did - which was cool. I immediately started getting duplicate symbol errors - which was not cool.
似乎有多种方法可以进入这种状态。我的是不同的。我读到一个提示,你可以从一个 .xib 事件选择器拖动到你的视图控制器的 .h 实现中,它会自动生成你的方法。它做到了——这很酷。我立即开始收到重复的符号错误 - 这并不酷。
I did not have time to dig deep into the linker to see what happened. I created a new view controller, copied the context of my old .xib into the new guy. Deleted the old .h, .m and .xib and built and it worked again. Very odd, very annoying time waste.
我没有时间深入研究链接器以查看发生了什么。我创建了一个新的视图控制器,将旧 .xib 的上下文复制到新人中。删除旧的 .h、.m 和 .xib 并构建并再次运行。很奇怪,很烦人的时间浪费。
There is obviously some bug with this xcode "convenience".
这个xcode“方便”显然存在一些错误。
回答by boulder_ruby
Based off what I can tell from these other answers, I'm going to need to be remove a bunch of main
methods.
根据我从这些其他答案中可以看出的,我将需要删除一堆main
方法。
But to do that easily I first need to remove all the gd comments from my files because they are assiduously documented with comments at nearly every other line
但是为了轻松做到这一点,我首先需要从我的文件中删除所有 gd 注释,因为它们几乎每行都有注释记录
This regular expression matches all C multi-line comments including their delimeters & may help you on your journey
此正则表达式匹配所有 C 多行注释,包括它们的分隔符,并可能对您的旅程有所帮助
/\*((?!\*/).)*\*/
回答by Sri
I found this happened when i had an implementation file with a main function in it (say abc.m) and also had another main.m
. Once I commented out the main function in abc.m
, the project compiled successfully.
我发现当我有一个包含主函数的实现文件(比如 abc.m)并且还有另一个main.m
. 一旦我将 中的 main 函数注释掉abc.m
,项目就编译成功了。