2014-10-08 102 views
-1
Ld /Users/noahheath/Library/Developer/Xcode/DerivedData/NBAPlayer- aeoygjukxhrzaxddvctkqcefsiql/Build/Products/Debug/NBAPlayer normal x86_64 
    cd /Users/noahheath/Documents/NBAPlayer 
    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/noahheath/Library/Developer/Xcode/DerivedData/NBAPlayer-aeoygjukxhrzaxddvctkqcefsiql/Build/Products/Debug -F/Users/noahheath/Library/Developer/Xcode/DerivedData/NBAPlayer-aeoygjukxhrzaxddvctkqcefsiql/Build/Products/Debug -filelist /Users/noahheath/Library/Developer/Xcode/DerivedData/NBAPlayer-aeoygjukxhrzaxddvctkqcefsiql/Build/Intermediates/NBAPlayer.build/Debug/NBAPlayer.build/Objects-normal/x86_64/NBAPlayer.LinkFileList -mmacosx-version-min=10.9 -stdlib=libc++ -Xlinker -dependency_info -Xlinker /Users/noahheath/Library/Developer/Xcode/DerivedData/NBAPlayer-aeoygjukxhrzaxddvctkqcefsiql/Build/Intermediates/NBAPlayer.build/Debug/NBAPlayer.build/Objects-normal/x86_64/NBAPlayer_dependency_info.dat -o /Users/noahheath/Library/Developer/Xcode/DerivedData/NBAPlayer-aeoygjukxhrzaxddvctkqcefsiql/Build/Products/Debug/NBAPlayer 

duplicate symbol __ZN9NFLplayerC1Ev in: 
    /Users/noahheath/Library/Developer/Xcode/DerivedData/NBAPlayer-aeoygjukxhrzaxddvctkqcefsiql/Build/Intermediates/NBAPlayer.build/Debug/NBAPlayer.build/Objects-normal/x86_64/UnsortedStruct.o 
    /Users/noahheath/Library/Developer/Xcode/DerivedData/NBAPlayer-aeoygjukxhrzaxddvctkqcefsiql/Build/Intermediates/NBAPlayer.build/Debug/NBAPlayer.build/Objects-normal/x86_64/main.o 
duplicate symbol __ZN9NFLplayerC2Ev in: 
    /Users/noahheath/Library/Developer/Xcode/DerivedData/NBAPlayer-aeoygjukxhrzaxddvctkqcefsiql/Build/Intermediates/NBAPlayer.build/Debug/NBAPlayer.build/Objects-normal/x86_64/UnsortedStruct.o 
    /Users/noahheath/Library/Developer/Xcode/DerivedData/NBAPlayer-aeoygjukxhrzaxddvctkqcefsiql/Build/Intermediates/NBAPlayer.build/Debug/NBAPlayer.build/Objects-normal/x86_64/main.o 
duplicate symbol __ZN9NFLplayer8ComparedES_ in: 
    /Users/noahheath/Library/Developer/Xcode/DerivedData/NBAPlayer-aeoygjukxhrzaxddvctkqcefsiql/Build/Intermediates/NBAPlayer.build/Debug/NBAPlayer.build/Objects-normal/x86_64/UnsortedStruct.o 
    /Users/noahheath/Library/Developer/Xcode/DerivedData/NBAPlayer-aeoygjukxhrzaxddvctkqcefsiql/Build/Intermediates/NBAPlayer.build/Debug/NBAPlayer.build/Objects-normal/x86_64/main.o 
ld: 3 duplicate symbols for architecture x86_64 
clang: error: linker command failed with exit code 1 (use -v to see invocation) 

這是我從xcode收到的腳本,我找不到錯誤以挽救我的生命。有人可以幫我調試嗎?原諒我,如果這不是以正確的格式。這是我第一次使用這個網站。Xcode鏈接器命令失敗問題

這是我主要的代碼和這裏是無序結構類

#include "NFL.h" 
class UnsortedStruct 
{ 
public: 
    UnsortedStruct(); 
    int GetLength() const; 
    bool IsFull() const; 
    void EmptyList(); 
    void InsertItem(NFLplayer nflplayers); 
    void DeleteItem(NFLplayer nflplayers); 
    void ResetList(); 
    NFLplayer GetItem(NFLplayer nflPlayers, bool& found); 
    NFLplayer GetNextItem(); 
private: 
    int length; 
    int currentPos; 
    NFLplayer NFLlist[MAX_PLAYERS]; 
}; 

#include <string> 
using namespace std; 

const int MAX_PLAYERS = 10; 
enum RelationType1 {LESS1, GREATER1, EQUAL1}; 

struct NFLplayer//describes the set of information for a NFL player. 
{ 
    string position, school, name, team; 
    RelationType1 Compared(NFLplayer); 
    NFLplayer(); 
}; 

NFLplayer::NFLplayer() 
{ 
    position=" "; 
    school=" "; 
    name=" "; 
    team=" "; 
} 
RelationType1 NFLplayer::Compared(NFLplayer players) 
{ 
    if(name < players.name) 
     return LESS1; 
    else if(name > players.name) 
     return GREATER1; 
    else 
     return EQUAL1; 
} 
+0

你有一個重複的符號錯誤,這基本上意味着你在多個地方聲明瞭同一個對象。請添加代碼示例(來自main/UnsortedStruct),其中聲明瞭「player」。如果可能,簡短代碼片段。 – MichaelCMS 2014-10-08 12:59:59

+0

@MichaelCMS我已經添加了我的客戶端代碼和我的UnsortedStruct文件 – 2014-10-08 13:30:41

+0

問題可能出現在NFL.h中。你確定只包含一次(pragma once/ifndef方法)嗎?除了函數原型和外部/類變量外,您是否在NFL.h中實現/聲明瞭任何內容? – MichaelCMS 2014-10-08 13:40:43

回答

0

您在.h文件中聲明瞭您的構造函數和Comparison函數。將它們移動到.cpp文件中,並且應該順利運行。

剛剛發生一個更深入的瞭解:

.h文件是拷貝粘貼到正在編譯的每個對象。因此,main.o和UnsortedStruct.o將在預處理器時間將頭文件複製粘貼到其對象中。

你有兩個對象,並且你在每個對象中定義:: Comparison和:: NFLPlayer函數的實現。你最終得到兩個相同函數的實現,因此是重複的符號。

的.h文件旨在爲將要使用的結構,類功能(這是一個向前聲明這麼說)提供的定義。

實現主體是在.cpp文件中實現的,而這些文件將在編譯後被編譯並鏈接到代碼中。

當你看到.h文件實現,你會看到,這些都是類定義:

Class A 
{ 
    void foo() { // do something }; 
} 

這是有效的,因爲該功能將成爲內聯。如果該文件被包括作爲報頭中的多個編譯單元(對象)

然而,宣佈無效美孚,然後將其實現爲A :: foo的()在同一個文件將是麻煩的。

+0

謝謝。我明白現在發生了什麼事。我重新設計了我的程序的一部分,現在它可以工作。謝謝! – 2014-10-08 14:35:48

0

很多錯誤來源於數據,我認爲你做的Xcode的升級?

做在Xcode以下步驟:

  • 產品 - >(按住Alt鍵) - >乾淨生成文件夾
  • 產品 - >清理項目
  • 窗口 - >管理 - >刪除派生數據

然後重新編譯您的項目。

+0

我沒有升級xcode。我回來了,並從我的代碼中添加了兩個文件,以展示我正在進行的操作。 – 2014-10-08 13:41:33

相關問題