xcode 重复的symbol_main

声明:本页面是StackOverFlow热门问题的中英对照翻译,遵循CC BY-SA 4.0协议,如果您需要使用它,必须同样遵循CC BY-SA许可,注明原文地址和作者信息,同时你必须将它归于原作者(不是我):StackOverFlow 原文地址: http://stackoverflow.com/questions/10651363/
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

提示:将鼠标放在中文语句上可以显示对应的英文。显示中英文
时间:2020-09-15 00:21:37  来源:igfitidea点击:

Duplicate symbol_main

c++xcode

提问by Laura

I've been looking for solutions for this problem but them didn't work for me! I've been having a lot of problems compiling programs. When I'm trying to execute a program in Xcode appears:

我一直在寻找解决此问题的方法,但它们对我不起作用!我在编译程序时遇到了很多问题。当我尝试在 Xcode 中执行程序时出现:

duplicate symbol _main in /Users/LauraChaparro/Library/Developer/Xcode/DerivedData/Busqueda-ercduihvfosqcoczkrgljkkmgxam/Build/Intermediates/Busqueda.build/Debug/Busqueda.build/Objects-normal/x86_64/Uno.o and /Users/LauraChaparro/Library/Developer/Xcode/DerivedData/Busqueda-ercduihvfosqcoczkrgljkkmgxam/Build/Intermediates/Busqueda.build/Debug/Busqueda.build/Objects-normal/x86_64/main.o for architecture x86_64

重复符号 _main 在 /Users/LauraChaparro/Library/Developer/Xcode/DerivedData/Busqueda-ercduihvfosqcoczkrgljkkmgxam/Build/Intermediates/Busqueda.build/Debug/Busqueda.build/Objects-normal/x86_64/Uno.o/LauraUsers Library/Developer/Xcode/DerivedData/Busqueda-ercduihvfosqcoczkrgljkkmgxam/Build/Intermediates/Busqueda.build/Debug/Busqueda.build/Objects-normal/x86_64/main.o 架构 x86_64

I don't understand why this happens! Is a C++ project... Or if you can recommend me another IDE I'll be really thankful!

我不明白为什么会这样!是一个 C++ 项目...或者如果你能向我推荐另一个 IDE,我将非常感激!

回答by juanchopanza

It looks like you are defining a mainin some of the code used to make the Uno.oobject file. You can only have one main, so objects used to build libraries should not define a main. This should only be defined in the application itself.

看起来您正在main一些用于制作Uno.o目标文件的代码中定义 a 。您只能拥有一个main,因此用于构建库的对象不应定义main. 这应该只在应用程序本身中定义。

This a linker error and it likely you would encounter it with other IDEs. You need to find where in Uno.othe mainis defined and remove it.

这是一个链接器错误,您可能会在其他 IDE 中遇到它。你需要找到其中Uno.omain定义,将其取下。

回答by daramarak

The error you have there is a linker error. It tells you exactly what is wrong. The linker has found out that it can find the symbol *_main* defined more than one time looking through the object files. This makes it impossible for the linker to create an executable of your object files, as it have no way of telling which symbol you want to use. It continues to tell you where it found the two symbols.

您遇到的错误是链接器错误。它会准确地告诉您出了什么问题。链接器发现它可以找到多次查看目标文件时定义的符号 *_main*。这使得链接器无法创建目标文件的可执行文件,因为它无法告诉您要使用哪个符号。它会继续告诉您它在哪里找到这两个符号。

Once in the Uno.o file (which I will assume come from compiling the Uno.cpp file) another from the main.o file (from the main.cpp file)

一旦进入 Uno.o 文件(我假设它来自编译 Uno.cpp 文件)另一个来自 main.o 文件(来自 main.cpp 文件)

This means, that somehow the linker can find the symbol for the main method in both files.

这意味着,链接器可以以某种方式在两个文件中找到 main 方法的符号。

This could happen by:

这可能通过以下方式发生:

  • Defining a mainfunction both inthe Uno.cpp and main.cpp
  • Having placed a non inlinemaindefinition in a header and including this both in the Uno.cpp file and the main.cpp file (or an include that includes another include and so on.)
  • Uno.cpp 和 main.cpp 中定义函数
  • 在头文件中放置了一个非内联定义并将其包含在 Uno.cpp 文件和 main.cpp 文件中(或包含另一个包含等的包含)。

As your request for another IDE I would like to remind you that neither compiler errors or linker errors are errors in the IDE, in an overwhelming number of cases the problem is that the user of the IDE has done something wrong.

作为您对另一个 IDE 的请求,我想提醒您,编译器错误或链接器错误都不是 IDE 中的错误,在绝大多数情况下,问题是 IDE 的用户做错了。