gpt4 book ai didi

c++ - 我错过了什么?未定义引用

转载 作者:行者123 更新时间:2023-11-28 03:20:28 25 4
gpt4 key购买 nike

<分区>

到现在为止我已经编程了 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

注意:我会尽快删除问题,感谢您的关注。

25 4 0
Copyright 2021 - 2024 cfsdn All Rights Reserved 蜀ICP备2022000587号
广告合作:1813099741@qq.com 6ren.com