對不起,如果這是一個重複的問題。 我有eclipse juno,在Ubuntu的CDT。 hello world autotools項目的工作。現在我想用另一個文件中的功能,所以,我創建了一個one.h和one.cpp和修改main_hello.cpp:在eclipse中包含一個新文件在C++中cdt
main_hello.cpp:
#include <iostream>
#include "one.h"
using namespace std;
int main(void) {
cout << "Hello World" << endl;
onehello();
return 0;
}
one.h:
#ifndef ONE_H_
#define ONE_H_
void onehello(void);
#endif /* ONE_H_ */
one.cpp:
#include "one.h"
#include <iostream>
using namespace std;
void onehello(void) {
cout << "Hello one" << endl;
}
當我建立它,我得到一個 「未定義的參考`onehello()」。如果我在one.h中定義函數而不是one.cpp,它會起作用。 我在做什麼錯?
謝謝!
您需要將'one.cpp'作爲源文件添加到'makefile'中。 – lapk 2013-04-24 11:32:35