我做錯了什麼,我知道。我不能完全弄清楚如何通過頭文件將兩個.cpp
文件鏈接在一起。調用 方法無法看到其他來源。如何鏈接C++源文件與Code :: Blocks
我使用Code :: Blocks作爲IDE與MinGW。
任何幫助將不勝感激。如果您可以顯示固定的來源,則會更加讚賞 ,並在回覆到 pastebin頁面時將其鏈接。
/***********************************main.cpp***********************************/
#include <iostream>
using namespace std;
#include "test.h"
int main()
{
printTest(); //can't see printTest, defined in test.cpp
return 0;
};
/***********************************test.h***********************************/
#ifndef TEST_H_INCLUDED
#define TEST_H_INCLUDED
void printTest();
#endif // TEST_H_INCLUDED
/***********************************test.cpp***********************************/
#include "test.h"
void printTest()
{
cout << "Hello world!" << endl;
};
你的代碼是正確的,你如何調用編譯器?你有沒有添加test.cpp到你的項目文件? IDE需要知道要編譯哪些文件。 – pezcode 2012-02-22 23:05:41
顯示makefile。 – lapk 2012-02-22 23:06:10
你是如何構建你的程序的,你的錯誤究竟是什麼? pastebin上的代碼看起來很好。 – Kitsune 2012-02-22 23:06:17