我尝试从C程序调用编译的NASM函数时未定义的引用错误

时间:2022-09-07 22:51:30

I have a c program, to optimize this program I have tried this:

我有一个c程序,为了优化这个程序我试过这个:

  1. compile the most heavy method (named my_method) separately
  2. 分别编译最重的方法(名为my_method)
  3. disassembly the compiled method
  4. 反汇编编译的方法
  5. editing the assembly code generated from the compiler to optimize this
  6. 编辑从编译器生成的汇编代码以优化它
  7. compile edited and optimized assembly code with NASM compiler
  8. 使用NASM编译器编译编辑和优化的汇编代码

the original c method has this signature

原始的c方法有这个签名

float **my_method(int m, int n, float **MatrixA, float **VectorB){
   //method boby
}

The problem: How to call the compiled optimized "NASMed" version of the method from C?

问题:如何从C调用已编译的优化“NASMed”版本的方法?

I have tried to declare this at the beginning of the c file

我试图在c文件的开头声明这个

extern float **my_method(int m, int n, float **MatrixA, float **VectorB);

but when I try to call the method in c for example with

但是当我尝试用c调用c中的方法时

float **res= mymethod(rows, columns, matrix1, vect);

GCC returns me this error: Undefined reference to my_method

GCC返回给我这个错误:对my_method的未定义引用

the compiled assembly file is named my_method.o my c file is named my_program.c

已编译的程序集文件名为my_method.o,我的c文件名为my_program.c

I have tried to compile with gcc my_program.c

我试图用gcc my_program.c编译

1 个解决方案

#1


1  

You might like to use something like

你可能想要使用类似的东西

gcc -Wall -Wextra -pedantic my_program.c -o my_program my_method.o

with my_method.o being the result of the NASM compilation.

my_method.o是NASM编译的结果。

#1


1  

You might like to use something like

你可能想要使用类似的东西

gcc -Wall -Wextra -pedantic my_program.c -o my_program my_method.o

with my_method.o being the result of the NASM compilation.

my_method.o是NASM编译的结果。