简体   繁体   English

Mac上的C ++:链接器命令失败,退出代码为1(使用-v查看调用)

[英]C++ on mac : linker command failed with exit code 1 (use -v to see invocation)

Ld /Users/rahulshrestha/Library/Developer/Xcode/DerivedData/101-bdjjlwlibkuaakgjcxqoslsirofh/Build/Products/Debug/101 normal x86_64
    cd /Users/rahulshrestha/Dropbox/C++/101
    export MACOSX_DEPLOYMENT_TARGET=10.9
    /Applications/Xcode.app/Contents/Developer/Toolchains/XcodeDefault.xctoolchain/usr/bin/clang++ -arch x86_64 -isysroot /Applications/Xcode.app/Contents/Developer/Platforms/MacOSX.platform/Developer/SDKs/MacOSX10.9.sdk -L/Users/rahulshrestha/Library/Developer/Xcode/DerivedData/101-bdjjlwlibkuaakgjcxqoslsirofh/Build/Products/Debug -F/Users/rahulshrestha/Library/Developer/Xcode/DerivedData/101-bdjjlwlibkuaakgjcxqoslsirofh/Build/Products/Debug -filelist /Users/rahulshrestha/Library/Developer/Xcode/DerivedData/101-bdjjlwlibkuaakgjcxqoslsirofh/Build/Intermediates/101.build/Debug/101.build/Objects-normal/x86_64/101.LinkFileList -mmacosx-version-min=10.9 -stdlib=libc++ -Xlinker -dependency_info -Xlinker /Users/rahulshrestha/Library/Developer/Xcode/DerivedData/101-bdjjlwlibkuaakgjcxqoslsirofh/Build/Intermediates/101.build/Debug/101.build/Objects-normal/x86_64/101_dependency_info.dat -o /Users/rahulshrestha/Library/Developer/Xcode/DerivedData/101-bdjjlwlibkuaakgjcxqoslsirofh/Build/Products/Debug/101

duplicate symbol _main in:
    /Users/rahulshrestha/Library/Developer/Xcode/DerivedData/101-bdjjlwlibkuaakgjcxqoslsirofh/Build/Intermediates/101.build/Debug/101.build/Objects-normal/x86_64/main.o
    /Users/rahulshrestha/Library/Developer/Xcode/DerivedData/101-bdjjlwlibkuaakgjcxqoslsirofh/Build/Intermediates/101.build/Debug/101.build/Objects-normal/x86_64/praca.o
ld: 1 duplicate symbol for architecture x86_64
clang: error: linker command failed with exit code 1 (use -v to see invocation)


#include <iostream>
using namespace std;

int main() {
    double radius, circumference, area; // Declare 3 floating-point variables
    const double PI = 3.14159265;       // Declare and define PI

cout << "Enter the radius: ";  // Prompting message
cin >> radius;                 // Read input into variable radius

// Compute area and circumference
area = radius * radius * PI;
circumference = 2.0 * radius * PI;

// Print the results
cout << "The radius is: " << radius << endl;
cout << "The area is: " << area << endl;
cout << "The circumference is: " << circumference << endl;

return 0;
}

You can only have one main() - you decide which one you need to keep and which one needs to be deleted. 您只能拥有一个main()-您决定需要保留哪一个以及需要删除哪一个。 Keep only one page, with the main() method. 使用main()方法仅保留一页。

该错误消息告诉您您需要了解的所有内容-您有两个主电源-一个在main.cpp中,一个在praca.cpp中。只能有1个主方法。

Others on the thread have already indicated the issue here. 该线程上的其他人已经在这里指出了问题。 I will try give the context. 我将尝试给出上下文。

When you compile your program the c++ compiler looks for main function definition amongst the object files it has compiled as an entry-point to invoke your program. 编译程序时,C ++编译器会在目标文件中寻找其定义的主要功能,并将其编译为调用程序的入口点。

As your error indicates the compiler finds 2 main function definition one in praca.o(praca.cpp ?) and the other in main.o(main.cpp ?) 如您的错误所示,编译器在praca.o(praca.cpp?)中找到2个主要函数定义,而在main.o(main.cpp?)中找到另一个主函数定义。

So you have to choose either the main in main.cpp or praca.cpp and remove the other. 因此,您必须在main.cpp或praca.cpp中选择main并删除另一个。

暂无
暂无

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

相关问题 Xcode:链接器命令失败,退出代码为1(使用-v查看调用)[C ++] - Xcode: linker command failed with exit code 1 (use -v to see invocation) [C++] XCode C++ 链接器命令失败,退出代码为 1(使用 -v 查看调用) - XCode C++ linker command failed with exit code 1 (use -v to see invocation) 编译我的 C++ 程序:clang: error: linker command failed with exit code 1(使用 -v 查看调用) - Compiling my c++ program: clang: error: linker command failed with exit code 1 (use -v to see invocation) 链接器命令在 macos 上失败,退出代码为 1(使用 -v 查看调用) - linker command failed with exit code 1 (use -v to see invocation) on macos 获取错误clang:错误:从终端编译C ++文件时,链接器命令失败,退出代码为1(使用-v查看调用) - Getting error clang: error: linker command failed with exit code 1 (use -v to see invocation) while compile C++ file from terminal C++ 文件停止编译 - 不断出现错误:linker 命令失败,退出代码为 1(使用 -v 查看调用) - C++ files stopped compiling - keep getting error: linker command failed with exit code 1 (use -v to see invocation) Xcode链接器错误:链接器命令失败,退出代码为1(使用-v查看调用) - Xcode linker error: linker command failed with exit code 1 (use -v to see invocation) C ++ XCODE ld:对于体系结构x86_64 clang找不到符号:错误:链接器命令失败,退出代码为1(使用-v查看调用) - C++ XCODE ld: symbol(s) not found for architecture x86_64 clang: error: linker command failed with exit code 1 (use -v to see invocation) C ++编译错误:ld:找不到架构x86_64的符号clang:错误:链接器命令失败,退出代码为1(使用-v查看调用) - C++ compilation error: ld: symbol(s) not found for architecture x86_64 clang: error: linker command failed with exit code 1 (use -v to see invocation) Netbeans 10:错误:链接器命令失败,退出代码为1(使用-v查看调用) - Netbeans 10: error: linker command failed with exit code 1 (use -v to see invocation)
 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM