在c++ MinGW中包含汇编函数

include assembly function in c++ MinGW

本文关键字:汇编 函数 包含 c++ MinGW      更新时间:2023-10-16

我想在c++中包含一个汇编函数。我用谷歌发现extern int test(int,int)在C中工作得很好,但在c++中不行。我在c++中需要做什么?我的代码:

#include <iostream>
extern int test(int,int);
int main () {
  std::cout<<test(2,2); //Here I get "../main.cpp:6: undefined reference to `test'"
  return 0;
}

我正在使用eclipse与MinGW。

您可以使用extern "C"在c++中包含汇编函数。工作的例子:

#include <iostream>
extern "C" int test(int,int);
int main () {
  std::cout<<test(2,2);
  return 0;
}  

MinGW在函数后面加了下划线,所以在汇编中必须将其命名为_test