2013-05-01 79 views
0

Xcode給我3「Apple Mach-O鏈接器(Id)錯誤」錯誤。但是,當我點擊它們時,它並沒有將我引導到我的代碼中,因此我不知道問題出在哪裏。我知道其他人已經問過這個問題,但是我能找到的所有解決方案都是針對每個人的代碼。我正在學習C++,所以這些錯誤將作爲我正在開發的初學者計劃的一部分。Apple Mach-O鏈接器(Id)錯誤

蘋果的Mach-O接頭(Id)的錯誤 「SensorNode :: SensorNode(字符*,浮球,浮球,浮球,整數,浮點)」,從引用: 蘋果的Mach-O接頭(Id)的錯誤 「LOCATION LOCATION ::()」,從引用: 蘋果的Mach-O接頭(Id)的錯誤 鏈接器命令退出碼1失敗(使用-v看到調用)

如果有幫助,我會把我的代碼放在這裏: Here's my "sensor_node.h"

#ifndef SENSORNODE_H 
#define SENSORNODE_H 

#include <iostream> 

class LOCATION { 
    float lat, longi, height; 

public: 
    LOCATION(); 
    void setx(float xx); 
    void sety(float yy); 
    void setz(float zz); 
    void print(); 
}; 

class SensorNode { 
    char* NodeName; 
    int NodeID; 
    LOCATION Node1; 
    float batt; 
    int func; 


public: 
    SensorNode(char *n, float x, float y, float z, int i, float ah); 
    void print(); 
    void setOK(int o); 
    int getOK(); 
    void setLOC(float longi, float lat, float h); 
}; 

#endif /* defined(__Project_3__sensor_node__) */ 

這裏是我的sensor_node.cpp:

#include "sensor_node.h" 
//#include <iostream> 
using namespace std; 


void LOCATION::setx(float xx) { 
    lat = xx; 
    if (lat > 180.0 || lat < -180.0) { 
     cout << "Latitude is not in the -180 to 180 degree range"; 
     lat = 0.0; 
    } 
} 

void LOCATION::sety(float yy) { 
    longi = yy; 
    if (longi > 180.0 || longi < -180.0) { 
     cout << "Latitude is not in the -180 to 180 degree range"; 
     longi = 0.0; 
    } 


} 
void LOCATION::setz(float zz) { 
    height = zz; 
} 

void LOCATION::print() { 

    cout << "(LONGITUDE: " << longi << " ,LATITUDE: " << lat << " ,HEIGHT: " << height << ")"; 
} 

,這裏是我的main.cpp:

#include <iostream> 
using namespace std; 

#include "sensor_node.h" 

int main() { 

    LOCATION a; SensorNode s1("Pulse",15.9,-30.1,0,157,2.0); 

    cout << "Beginning LOCATION tests.\n\n"; 
    cout << " After initial construction: "; 
    a.print(); 
    cout << "\n"; 
    a.setx(-45.3); 
    a.sety(27.6); 
    a.setz(3.5); 
    cout << " After setting x/y/z to -45.3/27.6/3.5: "; 
    a.print(); 
    cout << "\n"; 

    cout << " After attempting to set longitude to 180.1: "; 
    a.setx(180.1); 
    a.print(); 
    cout << "\n"; 

    cout << " After attempting to set longitude to -180.1: "; 
    a.setx(-180.1); 
    a.print(); 
    cout << "\n"; 

    cout << " After attempting to set latitude to 180.1: "; 
    a.sety(180.1); 
    a.print(); 
    cout << "\n"; 

    cout << " After attempting to set latitude to -180.1: "; 
    a.sety(-180.1); 
    a.print(); 
    cout << "\n"; 
/* 
    cout << "\n\n\n\nBeginning sensor node tests.\n\n"; 
    cout << " After initial construction:"; 
    s1.print(); 
    cout << "\n Printing the value returned by getOK: " << s1.getOK(); 
    cout << "\n After changing location to 20/30/40:"; 
    s1.setLOC(20,30,40); 
    s1.print(); 
    cout << "\n After trying to set location illegally:"; 
    s1.setLOC(181, -181, 10); 
    s1.print(); 
    cout << "\n Node fails, then try to change location:"; 
    s1.setOK(0); 
    s1.setLOC(5,10,15); 
    s1.print(); 
    cout << "\n Printing the value returned by getOK: " << s1.getOK(); 
    cout << "\n\n\n End of tests.\n"; 

    cout << "Enter an integer to quit: "; 
    cin >> hold; 
*/ 
return 0; 
} 

回答

1

您還沒有書面的LOCATION類的構造函數。您聲明一個名爲aLOCATION和一個包含LOCATIONSensorNode,但鏈接器無法找出LOCATION構造函數的代碼位於何處,因此它無法鏈接。爲LOCATION類寫一個構造函數,你應該很好。

0

您似乎忘記實施SensorNode。在SensorNode.h中,您聲明瞭一個類SensorNode,它具有數據和公共方法,但是在SensorNode.cpp中,您沒有提供SensorNode(構造函數),print等的實現。鏈接器無法找到這些實現,因爲它們沒有「沒有實現,因此鏈接器錯誤。

下面是一些樣板,你可以開始了:

SensorNode::SensorNode(char *n, float x, float y, float z, int i, float ah) 
{ 
} 

void SensorNode::print() 
{ 
} 

void SensorNode::setOK(int o) 
{ 
} 

int SensorNode::getOK() 
{ 
} 

void SensorNode::setLOC(float longi, float lat, float h) 
{ 
} 
+0

那好吧!非常感謝Muncken!我雖然因爲我已經將SensorNode測試註釋掉了,但我可以測試出位置的東西,但是我發現它在main的第一行中調用了傳感器節點的東西。非常感謝您的幫助和樣板代碼! – Acoustic77 2013-05-03 01:44:40

+0

非常歡迎。 – 2013-05-03 06:53:16

+0

我放入了鍋爐代碼,然後評論了第一行的後半部分(因爲我試圖測試Location類),並且仍然收到兩個Apple Mach-O鏈接器(Id)錯誤。傳感器節點中的SensorNode :: SensorNode(char *,float,float,float,int,float)未定義符號: 「LOCATION :: LOCATION()」, :符號(s)未找到架構x86_64 鐺:錯誤:鏈接器命令失敗,退出代碼1(使用-v看到調用) 任何想法? – Acoustic77 2013-05-03 23:15:26