首先,我完全是个菜鸟,所以请放轻松:)
话虽如此,我的问题可能很容易回答:
我如何将 sublime text 3 用于具有多个文件(头文件/实现文件)的 c++
我一直在尝试其他人提供的一些构建系统,这是我目前正在使用的系统,似乎可以很好地编译单个 .cpp 文件,但它告诉我一些我不明白的错误
这是我使用 g++ 的构建配置
{
"cmd": ["g++.exe", "-std=c++14", "-o", "$file_base_name", "$file", "&&", "start", "cmd", "/c", "$file_base_name & echo. & echo. & pause"],
"shell": true,
"selector": "source.c++"}
这是我的 main.cpp:
#include <iostream>
#include <string>
#include "num.h"
using namespace std;
int main(){
Num n(35);
cout << n.getNum() << endl;
return 0;}
这是我的 num.h 文件:
#ifndef NUM_H
#define NUM_H
class Num
{
private:
int num;
public:
Num(int n);
int getNum();
};
#endif
这是我的 num.cpp:
#include "num.h"
#include <iostream>
#include <stdlib.h>
Num::Num(int x){
num = x;
}
int Num::getNum()
{
return num;
}
所有文件都在同一个目录中,每当我在这样的命令上使用 g++ 时:(g++ (tdm64-1) 5.1.0)
g++ main.cpp num.cpp
没有问题,一切正常
但是每当我尝试用崇高的文本构建它时,它都会抛出这个错误
C:\Users\GEBRUI~1\AppData\Local\Temp\ccqq94my.o:main.cpp:(.text+0x1a): undefined reference to `Num::Num(int)'
C:\Users\GEBRUI~1\AppData\Local\Temp\ccqq94my.o:main.cpp:(.text+0x26): undefined reference to `Num::getNum()'
collect2.exe: error: ld returned 1 exit status
[Finished in 0.8s]
如果有人能告诉我我在这里做错了什么,我将不胜感激:)