可能重複:
What is an undefined reference/unresolved external symbol error and how do I fix it?類未定義參考
這應該是一個簡單的問題,但我仍然有問題。我已經看過類似的問題,但他們似乎有點複雜,然後我正在尋找。
我使用Code :: Blocks 10.05。
我收到了一個未定義的對我的類文件的引用。我知道這是一個鏈接器錯誤,但我不知道如何解決它。我很害怕我對鏈接文件不太瞭解。
s\Desktop\the cool container\Test 1\Class2.o:Class2.cpp|| undefined reference to `Burrito::Burrito()'|
||=== Build finished: 1 errors, 0 warnings ===|
我所有的文件都在同一個文件夾中。我的對象什麼都不做,我只是試試這個,我不應該從另一個類創建一個對象。
啊,這是從TheNewBoston教程...他能得到這個工作,所以我應該能夠得到它的工作。
如果我包括在Class2.cpp #include "Burrito.cpp"
那麼它的工作原理,但他並沒有包括。
------------ Class2.cpp -----------------
#include <iostream>
#include "Burrito.h"
using namespace std;
int main(){
Burrito Bo;
return 0;
}
- -------------- Burrito.h ----------------
#ifndef BURRITO_H
#define BURRITO_H
class Burrito
{
public:
Burrito();
};
#endif // BURRITO_H
---------- ----- Burrito.cpp -----------------
#include "Burrito.h"
#include<iostream>
using namespace std;
Burrito::Burrito()
{
}
最有可能[this](http://stackoverflow.com/questions/12573816/what-is-an-undefined-reference-unresolved-external-symbol-error-and-how-doi-i-fix/12574400 #12574400) - 你沒有編譯或鏈接'Burrito.cpp'。 –
請詳細說明你編譯你的文件的方式來生成一個可執行文件... – sergio
我只是想我可以構建它並運行它我沒有意識到我不得不做任何特殊的編譯。我會研究一下。 – user1771489