Reputation: 31
i have been trying to call a library in c which was made in masm. I have managed to make a .lib file from assembly MASM. But i have no idea how to call it to C language as a library. Here is the .lib file https://www.dropbox.com/s/d9d8cjbxmo51yqg/main.lib
Help needed. Thanks
Upvotes: 0
Views: 2047
Reputation: 3
Oh man. Huge gotcha on this. In a 32bit masm .asm file in visual studio, that ".model flat, c" is CRITICAL. ESPECIALLY the "c". 64 bit masm assembly doesn't need it for some reason it just works. But if you try to call extern "C" defined functions from your C++ or C code in your assembly, the 32 bit won't link and it will complain about unresolved symbols, regardless of defining EXTERN symbol: PROC in your asm.
It's some kind of weird legacy 32 bit thing versus the 64 bit.
Beside that, for your question, I think you just want to declare your asm functions PUBLIC, just "PUBLIC functionname" in your asm, and then you don't need a header or anything for them, just define them with "extern" or extern "C" in your calling C/C++ code and it will find them in the assembly object and link.
Upvotes: 0
Reputation: 490408
The basic idea is fairly simple:
The general idea looks something like this (warning: untested code):
; masm file
.model flat, c
.code
plus1 proc input:dword
mov eax, input
add eax, 1
ret
plus1 endp
end
C/C++ header:
#ifdef __cplusplus
extern "C" {
#endif
int plus1(int);
#ifdef __cplusplus
}
#endif
Calling code:
#include "header.h"
int main() {
int x = plus1(14);
}
Upvotes: 1