我错过了什么?未定义的参考
What am I missing? Undefined reference
到现在为止我已经编程了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
注意:我会尽快删除这个问题,谢谢你的关注。
你在原型和代码中调用函数时将其命名为writeToGraph()
,但在定义它时将其命名为writetoGraph()
(注意大小写不同)
您在函数定义中打错了:writetoFile
而不是writeToFile
相关文章:
- GTest EXPECT_EQ给出未定义的错误参考
- 在VSCode中编译C++给了我一个未定义的参考
- Armadillo正在为共享的lapack库获取未定义的参考
- 我对C++程序有一个未定义的参考,不知道如何处理它
- 未定义的符号参考'pthread_rwlock_wrlock@@GLIBC_2.2.5'
- 新的C ,未定义的参考
- ROS中未定义的参考误差到OpenCV图像转换器
- 使用Arduino IDE的构造函数的未定义参考错误
- 未定义的参考错误链接天然函数Android
- QT的倍频程:未定义的参考
- 未定义的参考,差异使用 CUDA 的 OpenCV 中的双边过滤器
- MSYS2静态QT未定义的参考问题
- LLVM-5.0 MakeFile未定义的参考失败
- 尝试在Windows结果上使用GLOG未定义的参考
- 从链接中缺少什么,导致未定义的参考
- 带有静态库的Android NDK:链接器始终抛出“未定义的参考”
- Lambdas的C 向量 - 未定义的参考
- __extern_inline func导致未定义的参考错误
- OPENCV筛选未定义的参考问题
- C 指针未定义的参考