I would like to implement a number of functions in (32bit) NASM that have the following signature:
int function1();
int function2();
etc.
Then I want to create an object file and be able to statically link it with a C++ program compiled with gcc. I am looking for an example implementation of a function that returns an int, any additional code needed to export the symbols and the command line for NASM to produce a .a file that I can link to statically. Thanks in advance.
Assembler will output an object file, just use it when linking (I don’t remember NASM options, so don’t try this verbatim — something like
nasm foo.asm -o foo.o; g++ -o prog foo.o bar.cpp).Static libraries are nothing more than fancy archives (hence the .a extension) of object files. binutils has
arutility if you really want to pack a single object into an archive.