问题在内联汇编中定义函数并从 C++ 调用
Issue defining a function in inline assembly and calling from c++
我正在尝试编译下面 link 中提到的代码。我收到以下 linker 错误:
/tmp/ccUVLIZ0.ltrans0.ltrans.o:在函数“main”中:
:(.text.startup+0x5): 未定义对“一”的引用
collect2:错误:ld 返回了 1 个退出状态
Equivalent for GCC's naked attribute
linker 没有看到程序集定义?
代码如下:
#include <stdio.h>
asm("_one: \n\
movl ,%eax \n\
ret \n\
");
int one();
int main() {
printf("result: %d\n", one());
return 0;
}
对于此类技巧,您需要明确提供函数规范
#include <stdio.h>
asm("one: \n\
movl ,%eax \n\
ret \n\
");
extern "C" int one();
int main() {
printf("result: %d\n", one());
return 0;
}
您可能可以在以下位置找到有关 extern "C" 的更多解释
What is the effect of extern "C" in C++?
我正在尝试编译下面 link 中提到的代码。我收到以下 linker 错误:
/tmp/ccUVLIZ0.ltrans0.ltrans.o:在函数“main”中:
:(.text.startup+0x5): 未定义对“一”的引用
collect2:错误:ld 返回了 1 个退出状态
Equivalent for GCC's naked attribute
linker 没有看到程序集定义?
代码如下:
#include <stdio.h>
asm("_one: \n\
movl ,%eax \n\
ret \n\
");
int one();
int main() {
printf("result: %d\n", one());
return 0;
}
对于此类技巧,您需要明确提供函数规范
#include <stdio.h>
asm("one: \n\
movl ,%eax \n\
ret \n\
");
extern "C" int one();
int main() {
printf("result: %d\n", one());
return 0;
}
您可能可以在以下位置找到有关 extern "C" 的更多解释 What is the effect of extern "C" in C++?