我已經編程了7個小時,現在我真的無法看到由於耗盡問題。我需要一些額外的眼睛。我錯過了什麼?未定義的參考
爲什麼這段代碼不能編譯?
bool readFromFile(const char*, Graph[5]);
bool writeToFile(Graph[5]);
int main(int argc, char* argv[]) {
.
.
.
Graph graph[5];
if(readFromFile(argv[1], graph) == false){ //read and error check
cout << "Returning from main(). . ." << endl;
return -1;
}
if(writeToFile(graph) == false){
cout << "Returning from main(). . ." << endl;
return -1;
}
return 0;
}
bool writetoFile(Graph graph[5]){
FILE* fp;
fp = fopen("output2.txt","w");
if(fp == NULL){
cout << "Error opening file: output2.txt" << endl;
return false;
}
//count pairs
int pairCount[5] = {0};
fclose(fp);
return true;
}
使用NetBeans,其實當我按下F9(編譯)彙編,但是當我嘗試運行:
g++ -o dist/Debug/GNU-Linux-x86/algorithm_hw1_task2 build/Debug/GNU-Linux-x86/Graph.o build/Debug/GNU-Linux-x86/main.o build/Debug/GNU-Linux-x86/Node.o
build/Debug/GNU-Linux-x86/main.o: In function `main':
/home/varaquilex/NetBeansProjects/algorithm_hw1_task2/main.cpp:40: undefined reference to `writeToFile(Graph*)'
collect2: error: ld returned 1 exit status
make[2]: *** [dist/Debug/GNU-Linux-x86/algorithm_hw1_task2] Error 1
make[2]: Leaving directory `/home/varaquilex/NetBeansProjects/algorithm_hw1_task2'
make[1]: *** [.build-conf] Error 2
make[1]: Leaving directory `/home/varaquilex/NetBeansProjects/algorithm_hw1_task2'
make: *** [.build-impl] Error 2
還當我嘗試使用G ++
/tmp/ccM7A6te.o: In function `main':
main.cpp:(.text+0x187): undefined reference to `writeToFile(Graph*)'
collect2: error: ld returned 1 exit status
編譯註意:我會盡快刪除問題,謝謝您的關注。
好的,你可以刪除你的答案,以便我可以刪除帖子?並非常感謝你... – Varaquilex 2013-03-24 00:57:30
爲什麼要刪除它?駱駝案例捕獲了很多疲憊的程序員,包括我自己在內。將它留給正在搜索'undefined netbeans compile'的其他人。 – 2013-03-24 01:03:13
這是正確的...我不這樣認爲,我的意思是我確定有很多像這樣的實例,所以我想刪除它。無所謂,它可以留下來。 我想我會切換到使用下劃線,遇到這樣的錯誤後:) – Varaquilex 2013-03-24 01:08:02