This thread has been locked.

If you have a related question, please click the "Ask a related question" button in the top right corner. The newly created question will be automatically linked to this question.

如何在在一个大型CPP工程中调用汇编程序

我现在自己写了一个加法的汇编程序,然后使用C来调取,能够成功编译和运行,但是当我将这个代码放到一个比较大的C++工程里的时候,程序却一直报识别不到函数名的错误,请问该如何解决呢?

我的测试程序如下

这里如果将main.c改成main.cpp,同时在extern 后面加上“C”就可以执行,但是我将汇编代码放在下面这样的一个工程里就不行了。

我的主函数为:

#include <stdlib.h>
#include <stdio.h>
#include <time.h>
#include "TAppDecTop.h"

extern "C" int asm_add(int a ,int b);

bool g_md5_mismatch = false; ///< top level flag that indicates if there has been a decoding mismatch

// ====================================================================================================================
// Main function
// ====================================================================================================================

int main(int argc, char* argv[])
{

  int a=5;
  int b=4;
  int i=0;
  i=asm_add(a,b);
  printf("i:%d\n",i);

  return EXIT_SUCCESS;

}

然后出现的 错误为:

undefined first referenced        
  symbol       in file             
 --------- ----------------        
 asm_add   ./TAppDecoder/decmain.obj
error #10234-D: unresolved symbols remain
error #10010: errors encountered during linking; "Dm642Hevc2.out" not built
我拼搏了一晚上没有解决,请各位大神帮忙看看哈。

 

  • 你好,

    你看看下面的讨论对你是否有帮助?

    http://e2e.ti.com/support/development_tools/compiler/f/343/t/146770

  • 你好,首先非常感谢你的回复,不过我看了之后,还是不行执行呢,在extern "C" int testadd_sa(int a ,int b);处直接提示“linkage specification is not allowed”。

    我使用的环境是C6000,汇编代码是

    testadd.sa:
     .global testadd_sa
    
    testadd_sa:
    
     ADD b4,a4,b4
     MV b4,a4
     B b3

    声明是在类的.h文件的public下:extern "C" int testadd_sa(int a ,int b);

    调用函数为类的一个成员函数下:

    int i=0;

      i=testadd_sa(m_iPOCLastDisplay,m_iSkipFrame);

    我查了很多材料,一直没有找到正确的答案,请问该怎么做才可以呢?如果您能给提供一个demo程序,我更加感激不尽。

    谢谢!