簡體   English   中英

在內聯匯編中定義函數並從C ++調用時出現問題

[英]Issue defining a function in inline assembly and calling from c++

我正在嘗試編譯以下鏈接中提到的代碼。 我收到以下鏈接器錯誤:

/tmp/ccUVLIZ0.ltrans0.ltrans.o:在函數“ main”中:

:(。text.startup + 0x5):對“ one”的未定義引用

collect2:錯誤:ld返回1退出狀態

相當於GCC的裸屬性

鏈接器看不到程序集定義?

代碼如下:

#include <stdio.h>

asm("_one:              \n\
    movl $1,%eax    \n\
    ret             \n\
");

int one();

int main() {
    printf("result: %d\n", one());
    return 0;
}

對於此類技巧,您需要明確提供功能說明

#include <stdio.h>

asm("one:              \n\
    movl $1,%eax    \n\
    ret             \n\
");

extern "C" int one();

int main() {
    printf("result: %d\n", one());
    return 0;
}

您可能會在C ++中找到關於extern“ C”的更多解釋

暫無
暫無

聲明:本站的技術帖子網頁,遵循CC BY-SA 4.0協議,如果您需要轉載,請注明本站網址或者原文地址。任何問題請咨詢:yoyou2525@163.com.

 
粵ICP備18138465號  © 2020-2024 STACKOOM.COM