【发布时间】:2022-10-02 23:30:33
【问题描述】:
所以我写了一个小程序来测试一切是否正常。 它应该需要两个输入和输出它们的总和。
测试.cpp:
#include <iostream>
#include <stdio.h>
extern \"C\" int test(int a, int b);
int main(){
int x = 0;
std::cout << test(10, 20);
std::cin >> x;
return 0;
}
测试.s:
.global test
test:
mov %eax, %ecx
add %eax, %edx
ret
然后我尝试用 g++ 编译它:g++ -o main.exe test.cpp但我得到一个错误:对“测试”的未定义引用
我对汇编编程完全陌生。有什么建议吗?
-
您的编译命令只编译\"test.cpp\",但您还需要编译和链接\"test.s\",以便解析对
test的引用