简体   繁体   English

当我尝试从C程序调用已编译的NASM函数时出现未定义的参考错误

[英]Undefined reference error when I try to call compiled NASM function from C program

I have ac program, to optimize this program I have tried this: 我有一个交流程序,为了优化该程序,我尝试了以下方法:

  1. compile the most heavy method (named my_method ) separately 分别编译最繁重的方法(名为my_method
  2. disassembly the compiled method 分解编译的方法
  3. editing the assembly code generated from the compiler to optimize this 编辑从编译器生成的汇编代码以对此进行优化
  4. compile edited and optimized assembly code with NASM compiler 使用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中调用方法时

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进行编译

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编译的结果。

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

相关问题 已编译的C程序,带有对未定义/未声明的函数的调用; 没有错误或警告的报告。 为什么? - Compiled C program with call to undefined/undeclared function; no error or warning reported. Why? 尝试使用 function 通过引用 C 写入文件时程序崩溃 - Program crash when try to write into a file using a function by reference C 在C程序中未定义对函数的引用 - Undefined reference to function in C program C程序中未定义的参考错误 - Undefined reference error in a C program 当我尝试拨打 function 时显示错误 - when i try to call a function it shows error 错误:未定义对函数调用的引用 - Error:Undefined reference to function call 从C调用静态C ++方法会在编译时提供未定义的引用 - Calling static C++ method from C gives undefined reference when compiled 当我尝试使用C中的参数调用函数时,出现错误“错误:期望表达式…” - Getting an error “error: expected expression before…” when I try to call a function with parameters in C 从C函数调用时C ++函数的未定义引用 - Undefined reference for a C++ function when called from C function 从C程序调用C ++ DLL时,当我尝试访问DLL中的调用参数指针时会崩溃 - When calling a C++ DLL from a C program it crashes when I try to access call parameter pointer in the DLL
 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM