c - 当我尝试从 C 程序调用已编译的 NASM 函数时出现 undefined reference 错误

标签 c linux gcc nasm undefined-reference

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

  1. 单独编译最重的方法(名为my_method)
  2. 反汇编编译好的方法
  3. 编辑编译器生成的汇编代码以优化此
  4. 使用 NASM 编译器编译经过编辑和优化的汇编代码

原始的c方法有这个签名

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

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

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

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

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

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

GCC 返回这个错误: 对 my_method 的 undefined reference

编译后的汇编文件名为my_method.o 我的c文件名为my_program.c

我尝试用 gcc my_program.c 编译

最佳答案

你可能喜欢用类似的东西

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

my_method.o 是 NASM 编译的结果。

关于c - 当我尝试从 C 程序调用已编译的 NASM 函数时出现 undefined reference 错误,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/24106864/

相关文章:

c++ - 在库中使用 __gcov_flush 不会强制其他模块生成 .gcda 文件

c - 多次拆分字符串以获得字符串数组的数组

ruby - 捕获从 Ruby 内部运行的交互式外部命令的输出

r - 如何让 R Shiny downloadHandler 文件名起作用?

linux - 每天使用 logrotate 清除日志文件

c - LLVM和GCC,不同的输出相同的代码

c - 了解 C 中的栈帧

C 程序模拟命令行提示符

c++ - 有人可以解释一下这个冒号#语法吗

python - 自定义 C 模块包括