过载链接错误
Overload linking error
所以我有一个带有默认值函数的标题:
head.h:
a(int x, int y, bool* b = NULL);
head.cpp:
a(int x, int y, bool* b = NULL){...}
source.cpp:
a(1, 2, NULL);
a(1, 2);
,我在链接阶段遇到了一个错误:
undefined reference to a(int, int, bool*)
我也尝试删除默认值:
head.h:
a(int x, int y, bool* b);
a(int x, int y);
head.cpp:
a(int x, int y, bool* b){...}
a(int x, int y){...}
source.cpp:
a(1, 2, NULL);
a(1, 2);
与相同错误链接:
undefined reference to a(int, int, bool*)
undefined reference to a(int, int)
这会是什么?我的编译器不好?不好的makefile?
编辑:
它接缝了真实的标头文件,就像:
a(const int x, const int y, bool* b = NULL);
使用const
,对不起。
它接缝我是在使用const
变量的标题中定义函数,但在没有const
的情况下在CPP中实现它,因此链接器未能找到函数的实现。
gcc -o source source.cpp header.cpp
命令应该像这样
我想你忘了header.cpp
尝试像这样
首先分别编译程序并生成对象文件
gcc -c header.c
gcc -c source.c
然后像这样生成exe
gcc header.o source.o -o exefile
相关文章:
- Netbeans 10:错误:链接器命令失败,退出代码为 1(使用 -v 查看调用)
- CMake 错误:链接器命令失败,退出代码为 1 和 cpp.o 文件
- clang:错误:链接器命令失败,退出代码为 1(使用 -v 查看调用) - 体系结构的未定义符号 x86_64:
- 如何修复 clang: 错误:链接器命令失败,退出代码为 1(使用 -v 查看调用)
- Android NDK.Build命令失败.未定义的引用.clang++:错误:链接器命令失败,退出代码为1
- 使用cmake错误链接boost日志
- 错误:链接器命令失败,退出代码为 1(使用 -v 查看调用):在 Macbook 上
- C++ XCODE ld:找不到体系结构x86_64 clang 的符号:错误:链接器命令失败,退出代码为 1(使用 -
- clang:错误:链接器命令失败,C++代码中的退出代码为 1(使用 -v 查看调用)
- 静态库中的 g++ 错误链接函数
- 未定义的参考错误链接天然函数Android
- C++编译错误:ld:找不到体系结构x86_64 clang 的符号:错误:链接器命令失败,退出代码为 1(使用 -v
- QT Q_PROPERTY错误:链接器命令失败,退出代码为 1(使用 -v 查看调用)
- ld:找不到体系结构x86_64 clang 的符号:错误:链接器命令失败,退出代码为 1(使用 -v 查看调用)
- OSX MOJAVE -LD:架构X86_64 clang找不到符号:错误:链接器命令失败,出口代码1
- C 错误链接器命令失败了出口代码1(使用-V查看调用)
- LD:架构x86_64 clang找不到符号:错误:链接器命令失败,出口代码1(使用-v to See
- 聚输出错误 - 链接列表
- Xcode链接器错误:链接器命令失败,退出代码为1(使用-v查看调用)
- 尝试构建C DLIB示例无法与数百个未定义的参考错误链接