簡體   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;
}

您只能擁有一個main()-您決定需要保留哪一個以及需要刪除哪一個。 使用main()方法僅保留一頁。

該錯誤消息告訴您您需要了解的所有內容-您有兩個主電源-一個在main.cpp中,一個在praca.cpp中。只能有1個主方法。

該線程上的其他人已經在這里指出了問題。 我將嘗試給出上下文。

編譯程序時,C ++編譯器會在目標文件中尋找其定義的主要功能,並將其編譯為調用程序的入口點。

如您的錯誤所示,編譯器在praca.o(praca.cpp?)中找到2個主要函數定義,而在main.o(main.cpp?)中找到另一個主函數定義。

因此,您必須在main.cpp或praca.cpp中選擇main並刪除另一個。

暫無
暫無

聲明:本站的技術帖子網頁,遵循CC BY-SA 4.0協議,如果您需要轉載,請注明本站網址或者原文地址。任何問題請咨詢:yoyou2525@163.com.

 
粵ICP備18138465號  © 2020-2024 STACKOOM.COM