1
我對編程非常陌生,並且我將介紹向量的基礎知識。我目前得到錯誤,當我運行這個程序「鏈接器命令失敗,退出代碼1(使用-v看到調用)」鏈接器命令失敗:重複的符號_main
現在我已經看到這篇文章,但我運行的Xcode顯然是非常不同比你的其他人還是我做錯了什麼?我想知道是否有人能用通俗的話來貶低我的錯誤。 我也正在使用的Xcode 7.3
#include <stdio.h>
#include <vector> //vector support
#include <iostream>
using namespace std;
int main()
{
vector <int> vec(3,100);
cout << "Vector size: " << vec.size() << endl;
cout << "Is empty?: " << vec.empty() << endl;
cout << "First element: " << vec.at(0) << endl;
vec.pop_back(); // remove final element
cout << "Vector size: " << vec.size() << endl;
cout << "Final element: " << vec.back() << endl;
vec.clear(); // remove all elements
cout << "Vector size: " << vec.size() << endl;
vec.push_back(200); //add an element
cout << "Vector size: " << vec.size() << endl;
cout << "First element: " << vec.front() << endl;
return 0;
}
錯誤消息:
Ld /Users/Mojo/Library/Developer/Xcode/DerivedData/Project1-eglodkxixcqsglauiwgsasozdrpv/Build/Products/Debug/Project1 normal x86_64
cd /Users/Mojo/Desktop/Project1
export MACOSX_DEPLOYMENT_TARGET=10.11
/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.11.sdk -L/Users/Mojo/Library/Developer/Xcode/DerivedData/Project1-eglodkxixcqsglauiwgsasozdrpv/Build/Products/Debug -F/Users/Mojo/Library/Developer/Xcode/DerivedData/Project1-eglodkxixcqsglauiwgsasozdrpv/Build/Products/Debug -filelist /Users/Mojo/Library/Developer/Xcode/DerivedData/Project1-eglodkxixcqsglauiwgsasozdrpv/Build/Intermediates/Project1.build/Debug/Project1.build/Objects-normal/x86_64/Project1.LinkFileList -mmacosx-version-min=10.11 -Xlinker -no_deduplicate -stdlib=libc++ -Xlinker -dependency_info -Xlinker /Users/Mojo/Library/Developer/Xcode/DerivedData/Project1-eglodkxixcqsglauiwgsasozdrpv/Build/Intermediates/Project1.build/Debug/Project1.build/Objects-normal/x86_64/Project1_dependency_info.dat -o /Users/Mojo/Library/Developer/Xcode/DerivedData/Project1-eglodkxixcqsglauiwgsasozdrpv/Build/Products/Debug/Project1
duplicate symbol _main in:
/Users/Mojo/Library/Developer/Xcode/DerivedData/Project1-eglodkxixcqsglauiwgsasozdrpv/Build/Intermediates/Project1.build/Debug/Project1.build/Objects-normal/x86_64/Hello.o
/Users/Mojo/Library/Developer/Xcode/DerivedData/Project1-eglodkxixcqsglauiwgsasozdrpv/Build/Intermediates/Project1.build/Debug/Project1.build/Objects-normal/x86_64/FirstVector.o
ld: 1 duplicate symbol for architecture x86_64
clang: error: linker command failed with exit code 1 (use -v to see invocation)
必須有一些其他的消息。請複製粘貼完整,完整和未經編輯的實際信息並編輯您的問題以包含它。 –
@Mojo你可以從終端的命令行手動建立和鏈接嗎? –
我不知道如何。我很抱歉,我說我對這一切都非常陌生,我正在努力教我自己。 – Mojo