在 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(( 方法。
线程上的其他人已经在这里指出了这个问题。我将尝试提供上下文。
编译程序时,c++ 编译器会在已编译的对象文件中查找 main 函数定义,作为调用程序的入口点。
由于您的错误表明编译器在 praca.o(praca.cpp 中找到 2 个主函数定义 ? 另一个在main.o(main.cpp
?因此,您必须在main中选择主要.cpp或praca.cpp并删除另一个。
相关文章:
- 没有头文件如何使用c ++调用其他模块中的函数?
- 使用 %s 调用 printf 并传递零长度的字符*是未定义的行为吗?
- 使用 "()" 调用构造函数不同于"{}"
- 使用 c++ 调用.dll的默认参数的函数
- 当我同时将 T& 和 T 作为同名函数的返回类型时,如何使用 T& 调用函数
- 使用 P/调用传递取消标志时是否需要同步
- 当被调用方法使用调用方已锁定的同一锁时,如何避免死锁
- 在QT Creator中使用C++调用Python脚本
- C++按引用传递:如何使用调用堆栈
- 如何使用调用和别名指令在 llvm 字节码中查找函数名称
- 如何使用调用和分配指令在 llvm 字节码中查找类名
- 使用C++调用带有库的powershell脚本
- c++-如何使用调用函数的对象
- 使用 C++ 调用函数,其名称两边带有括号
- 如何 使用 C++ 调用 LabVIEW 构建 的 DLL
- 使用c#调用返回struct数组的非托管dll函数
- CUDA c++:使用调用模板内核的模板函数
- 如何创建win32智能手机dll并在WinCE中使用c#调用dll
- 使用 "->" 调用函数
- 错误:使用 C++ 调用 没有匹配函数