在 C++ 中调用时对内联程序集代码的未定义引用
Undefined reference to inline assembly code while calling in c++
Link Fast MD5 Assembly
上面给出的链接具有MD5的汇编实现。 当我尝试使用给定的执行指令在 C 中调用以下代码时,它成功运行。但是当我尝试在 C++11 中调用或执行时,我收到错误,因为未定义Md5_hash
函数引用
用于在 C 语言中编译
gcc --std=c99 md5-test.c md5-fast-x8664.S -o md5-test
同样用于 C++11
gcc --std=c++11 md5-test.cpp md5-fast-x8664.S -o md5-test
它显示错误
/staticLibmd5/main.cpp|32|undefined reference to md5_compress(unsigned char
const*, unsigned long, unsigned int*)'
C++ 中是否缺少任何其他指令。
假设您正在逐字编译链接中的代码,请更改这些md5-test.c
行...
// Link this program with an external C or x86 compression function
extern void md5_compress(uint32_t state[static STATE_LEN],
const uint8_t block[static BLOCK_LEN]);
改为阅读
// Link this program with an external C or x86 compression function
#ifdef __cplusplus
extern "C" {
#endif
extern void md5_compress(uint32_t state[static STATE_LEN],
const uint8_t block[static BLOCK_LEN]);
#ifdef __cplusplus
} // extern "C"
#endif
它应该开始工作。 要了解为什么会出现这个问题,请参阅此旧答案。
在完整的应用程序中,md5_compress
的声明将位于包含 MD5 实现的库提供的头文件中,并且该库负责将extern "C"
注释放在其头文件中。 这就是为什么您在使用现成库时可能没有遇到此问题的原因。
相关文章:
- 用于将C++代码转换为 Web 程序集的脚本未终止
- 为什么我的C++程序的程序集输出充满了 .ascii,没有汇编代码?
- 为什么在堆栈和堆上创建变量会产生相同的程序集代码?
- 为什么从 constexpr 引用生成的程序集代码与从 constexpr 指针生成的程序集代码不同?
- 在OpenGL中使用程序集代码渲染视频时出错
- 如何编写与此程序集代码相等的c/c++代码
- 在链接的程序集文件中,我想从 c++ 调用代码访问变量.是否可以在不触发访问冲突的情况下执行此操作?
- 在 C++ 中调用时对内联程序集代码的未定义引用
- 将程序集 NASM 代码链接到 GCC
- 确定代码中当前程序集是否为 32/64 位的最简单方法
- 在结构中嵌入函数程序集代码
- 程序集字符串和 C++ 中的等效代码
- 为什么添加内联程序集注释会导致 GCC 生成的代码发生如此根本的变化?
- 使用 Visual Studio 从C++代码调用程序集过程
- 如何使用g++获取C++头文件(.hpp)的程序集代码
- 从我的 C/C++ 代码 - x86 和 ARM 获取程序集等效代码
- 如何将此c++代码转换为程序集
- C++外部程序集:我的代码中的错误在哪里
- 如何在不创建新进程的情况下运行程序集代码
- 从C++调用程序集代码