首页
学习
活动
专区
圈层
工具
发布
社区首页 >问答首页 >Apple Mach-O Linker (Id)错误

Apple Mach-O Linker (Id)错误
EN

Stack Overflow用户
提问于 2013-05-01 23:16:32
回答 2查看 1.3K关注 0票数 0

Xcode给了我3 "Apple Mach-O Linker (Id)错误“错误。但是,当我单击它们时,它并不会指向代码中的一行,因此我不知道问题出在哪里。我知道其他人也问过这个问题,但我能找到的所有解决方案都是针对每个人的代码的。我正在学习C++,所以这些错误都是我正在进行的初学者程序的一部分。

Apple Mach-O Linker (Id)错误"SensorNode::SensorNode(char*,float,int,float)",引用来源: Apple O Linker (Id)错误“LOCATION()”,引用自: Apple O Linker (Id) Error Linker命令失败,退出代码1(使用-v查看调用)

如果有用的话,我会把我的代码放在这里:这是my "sensor_node.h"

代码语言:javascript
复制
#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:

代码语言:javascript
复制
#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:

代码语言:javascript
复制
#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;
}
EN

回答 2

Stack Overflow用户

回答已采纳

发布于 2013-05-02 05:11:27

您还没有为LOCATION类编写构造函数。您可以声明一个名为LOCATIONa和一个包含LOCATIONSensorNode,但是链接器无法确定LOCATION构造函数的代码在哪里,所以它无法链接。为LOCATION类编写一个构造函数,您应该很好。

票数 1
EN

Stack Overflow用户

发布于 2013-05-02 07:15:58

您似乎忘记了实现SensorNode。在SensorNode.h中,您声明一个类,SensorNode具有数据和公共方法,但在SensorNode.cpp中,您没有提供SensorNode (构造函数)、print等的实现。链接器无法找到这些实现,因为它们尚未实现,因此出现链接器错误。

下面是一些样板,您可以从这里开始:

代码语言:javascript
复制
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
EN
页面原文内容由Stack Overflow提供。腾讯云小微IT领域专用引擎提供翻译支持
原文链接:

https://stackoverflow.com/questions/16327942

复制
相关文章

相似问题

领券
问题归档专栏文章快讯文章归档关键词归档开发者手册归档开发者手册 Section 归档