我有3個文件: - main.cpp中 - other.cpp - other.hC++跨多個.cpp文件調用函數?
我想調用在other.h聲明的函數,從main.cpp中,用代碼爲寫在other.cpp
我的代碼:
main.cpp中:
//#Allmyincludes
#include "other.h"
int main(int argc, const char *argv[])
{
const char *file = argv[1];
read(file);
return 0;
}
other.cpp:
//#Allmyincludes
#include "other.h"
void read(const char *file)
{
//code
}
other.h:
void read(const char *file);
我得到的錯誤是:
main.cpp:(.text+0x44): undefined reference to 'read(char const*)'
在read()
,我使用main::variableName
從主(沒有錯誤)中訪問的變量,但是我只是不能讓函數調用工作。 如果我試圖做other::read(file);
也不起作用,因爲::
是爲功能而不是文件。它給了我錯誤:'other' has not been declared.
任何解釋爲什麼我的頭文件/調用不起作用非常感謝。
顯示你的編譯命令。如果使用GCC(即'g ++'),則注意到編譯器對程序參數的順序非常重要。 –
包括iostream – Jost