用于体系结构的 C++ 未定义符号 x86_64:"function_name"引用自
c++ undefined symbols for architecture x86_64: "function_name" referenced from
是的,我知道已经有几个问题深入到这个细节,但我觉得我的问题不是那么具体。只是有东西在盯着我的脸,但我看不太清楚。
我正在编译C和c++文件一起在一个Makefile。一切似乎都运行良好,直到我得到名义上的错误,这涉及到CFile2中的函数。
编译工作如下(w/占位符名称):
g++ -c main.cpp
g++ -c Class.cpp
gcc -c CFile1.c
gcc -c CFile2.c
g++ main.o Class.o CFile1.o CFile2.o -lcurl
我的Class.cpp有一个Class.hpp,我的CFile1和CFile2都分别有。h文件。所有内容都位于同一目录中,并且它们都具有相同的头保护结构。
#ifndef
#define
//Insert function prototypes here
#endif
我也只包括CFile1.h和CFile2.h在Class.hpp。是否有一些东西我错过了基于这个信息?
也许你错过了c头中的extern "C"
?
如果你编译c文件并想与c++链接,你必须添加extern "C"
,但c编译器不识别它,所以它必须是#ifdef __cplusplus
在标题开始,function减速之前添加:
#include <stdio> // and all other includes...
#ifdef __cplusplus
extern "C" {
#endif
void funnction_name1(); //sample 1
int funnction_name2(char* p); //sample 2
//must close the extern "C" block
#ifdef __cplusplus
}
#endif
也可以在每个函数前添加,如下所示:
#ifdef __cplusplus
extern "C"
#endif
// no block for the extern "C", so it applied only for a single function
void funnction_name(); //a sample func.
相关文章:
- vscode g++链路故障:体系结构x86_64的未定义符号
- 体系结构x86_64的未定义符号:std:terminate(),typeinfo,运算符delete[],运算符new
- OSX clang++:用于 cpp 文件中显式实例化模板的体系结构x86_64的未定义符号
- PCL 出错:体系结构x86_64 @pcl的未定义符号
- clang:错误:链接器命令失败,退出代码为 1(使用 -v 查看调用) - 体系结构的未定义符号 x86_64:
- 体系结构x86_64的未定义符号:链接器错误
- C++ std::vector<int> 体系结构的未定义符号 x86_64:
- 未使用的 asm() 在不受支持的体系结构上的行为
- 用于本地网络运行的客户端服务器体系结构
- 生成文件:体系结构x86_64的未定义符号
- Xcode"体系结构x86_64的未定义符号"
- 有了memory_order_relaxed,原子变量的总修改顺序如何在典型体系结构上得到保证
- 体系结构x86_64的未定义符号:找不到原因
- 在OSx:ld上使用CMake构建C++项目:找不到体系结构x86_64的符号
- 体系结构x86_64的未定义符号:c++/ h 文件和 cpp 文件
- 以编程方式在运行时检测 CPU 体系结构
- C++ XCODE ld:找不到体系结构x86_64 clang 的符号:错误:链接器命令失败,退出代码为 1(使用 -
- 了解类型特征的体系结构
- Apple Mach-O-Linker 错误:在体系结构 x86-64 中找不到从(行)引用的变量
- C++代码只能针对特定的 CPU 体系结构进行编译.有没有办法将其编译为所有架构