C++ Xcode 未定义的架构符号

C++ Xcode Undefined symbols for architecture

本文关键字:符号 Xcode 未定义 C++      更新时间:2023-10-16

当我尝试使用 Xcode 编译代码时,我收到一个错误。您可以在此处看到错误:

Undefined symbols for architecture x86_64:
  "Sun::Datum2JDatum(Sun::Time)", referenced from:
      _main in main.o
ld: symbol(s) not found for architecture x86_64
clang: error: linker command failed with exit code 1 (use -v to see invocation)

在我看来,他没有看到我的太阳档案。在我看来,我包含了一切。但我没有发现问题所在。谁能告诉我我做错了什么?

这是我的主要.cpp:我包括了我需要的所有库以及我的 Sun.hpp。

#include <iostream>
#include <time.h>
#include "Sun.hpp"
using namespace std;
int main(int argc, const char * argv[]) {
    struct tm* timeinfo;
    static char buf[200];
    time_t now = time(NULL);
    timeinfo = localtime(&now);
    Sun::Sun sunposition;
    Sun::Time time;
    // ...
    Sun::JDatum datum = sunposition.Datum2JDatum(time); // Here I got the Error
    return 0;
}

周日.hpp:

class Sun{
public:
    typedef struct{
        double jd;
        double jd0;
        double T;
        double T0;
    } JDatum;
    Coordinates Locationdetermination(Sun::JDatum, Sun::Location);
    JDatum Datum2JDatum(Sun::Time);
};

周日.cpp:

同样在Sun中.cpp还包括Sun.hpp。

#include "Sun.hpp"
using namespace std;
Sun::JDatum Datum2JDatum(Sun::Time Now){
    //...
}  

我找不到真正的错误。如果你能帮我解决问题,那就太好了。

在 Sun 中.cpp更改为:

JDatum Sun::Datum2JDatum(Sun::Time Now){
    //...
}