使用C++类时,x86_64架构出现未定义符号

4
我已经阅读了其他关于这个问题的提问,但仍然无法解决我的问题。
非常感谢您的帮助!
我的错误是:
未定义符号架构x86_64: "Record :: Record(std ::__ 1 :: vector,std ::__ 1 :: allocator >,std ::__ 1 :: allocator,std ::__ 1 :: allocator >>>,double *)",在 akh70P3ClassTester-946637.o 中被引用 ld:找不到符号(s)架构x86_64
Record.h
#include <string>
#include <vector>

using namespace std;

class Record
{
public:
    Record();
    Record(vector<string> , double []);

private:
    //some variables
};

Record.cpp

#include "Record.h"
#include <string>
#include <vector>

using namespace std;

Record::Record() {}

Record::Record(vector<string> inputs, double num_inputs[] )
{
    //variables happens
}

Main.cpp

#include "Record.h"
#include <vector>

using namespace std;

int main() {

    vector<string> inputs;

    double num_inputs[] = {};

    Record temp(inputs, num_inputs);

    return 0;
}

你是如何编译这个程序的?如果有的话,请包含你的Makefile。 - Syntactic Fructose
我看到了Objective-C的标签,这是通过Xcode编译的吗? - NonCreature0714
@NonCreature0714 我使用SublimeText2编译它,它告诉我使用了这个shell命令:g++ "main.cpp" -o "main" && "main"(我省略了完整的文件路径)所以我认为Syntactic Fructose的答案是正确的,因为它没有编译report.cpp。我正在测试它。 - herteladrian
1个回答

9

你可能没有在编译中包含Report.cpp文件,例如只执行g++ main.cpp -o main

相反,通过包含报告文件来编译程序:g++ main.cpp report.cpp -o main


1
你说得对。我之前没有使用makefile,因为在你问之前我不知道那是什么,直到现在通过谷歌搜索才了解。我一直使用SublimeText2的单文件C++构建和运行功能(通过Cmd-B)。使用你给我的命令行在终端编译是有效的,也很合理。 谢谢! - herteladrian

网页内容由stack overflow 提供, 点击上面的
可以查看英文原文,
原文链接