在内联程序集中定义函数和从 C++ 调用时出现问题
Issue defining a function in inline assembly and calling from c++
我正在尝试编译以下链接中提到的代码。 我收到以下链接器错误:
/tmp/ccUVLIZ0.ltrans0.ltrans.o: 在函数 'main' 中:
:(.text.startup+0x5(:对"一"的未定义引用
collect2:错误:ld 返回 1 个退出状态
等效于 GCC 的裸属性
链接器未看到程序集定义?
代码如下:
#include <stdio.h>
asm("_one: n
movl $1,%eax n
ret n
");
int one();
int main() {
printf("result: %dn", one());
return 0;
}
对于这样的技巧,你需要显式提供函数规范
#include <stdio.h>
asm("one: n
movl $1,%eax n
ret n
");
extern "C" int one();
int main() {
printf("result: %dn", one());
return 0;
}
您可能可以在以下位置找到有关外部"C"的更多解释 外置"C"在C++的影响是什么?
相关文章:
- 什么时候调用组成单元对象的析构函数
- 对RValue对象调用的LValue ref限定成员函数
- 为什么使用 "this" 指针调用派生成员函数?
- 函数调用中参数的顺序重要吗
- OpenGL - 在抛出"__gnu_cxx::recursive_init_error"实例后终止调用?
- 基于另一个成员参数将函数调用从类传递给它的一个成员
- 为什么我的C#代码在调用回C++COM直到Task时会暂停.等待/线程.加入
- 在c++类上调用void函数
- 为什么 std::unique 不调用 std::sort?
- 调用专用模板时出错"no matching function for call to [...]"
- 选择要调用的构造函数
- C++为什么尽管我调用了void函数,它却不起作用
- 构造函数正在调用一个使用当前类类型的函数
- 变量没有改变?通过向量的函数调用
- 没有为自己的结构调用列表推回方法
- 调用'begin(int [n])'没有匹配函数
- 什么时候调用析构函数
- 如何用参数值调用函数(仅在运行时已知)
- std::cout.imbue()多重调用
- 函数何时会在c++中包含stack_Unwind_Resume调用