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

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

本文关键字:使用 调用 代码 退出 C++ Mac 链接 失败 命令      更新时间:2023-10-16
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;
}

你只能有一个main(( - 你决定你需要保留哪一个,哪一个需要删除。只保留一页,使用 main(( 方法。

线程上的其他人已经在这里指出了这个问题。我将尝试提供上下文。

编译程序时,c++ 编译器会在已编译的对象文件中查找 main 函数定义,作为调用程序的入口点。

由于您的错误表明编译器在 praca.o(praca.cpp 中找到 2 个主函数定义 ? 另一个在main.o(main.cpp

因此,您必须在main中选择主要.cpp或praca.cpp并删除另一个。