ASM in VC++ problem

Started by x86asm, December 20, 2004, 04:52:53 AM

Previous topic - Next topic

x86asm

Hi guys I gotVC++ to invoke MASM to compile a ASM file into an OBJ file and put it in my project directory. The problem is that I can no longer link the program. VC++ gives me the following error:

Linking...
LIBCD.lib(crt0.obj) : error LNK2001: unresolved external symbol _main
Debug/SMSEM.exe : fatal error LNK1120: 1 unresolved externals
Error executing link.exe.

SMSEM.exe - 2 error(s), 0 warning(s)

Just wondering what can cause this? I'm certain it has something to do with the Obj

x86asm

#1
Now I have another problem guys, I'm having trouble referencing C code and C data variables. I was wondering how I would use the EXTERN keyword to do it. Cause prototyping like I would a normal ASM function gives me this error:

genvdp.obj : error LNK2001: unresolved external symbol _DecodeTile@8
Debug/SMSEM.exe : fatal error LNK1120: 1 unresolved externals
Error executing link.exe.

Jibz

Quote from: x86asm on December 20, 2004, 05:14:48 AM
genvdp.obj : error LNK2001: unresolved external symbol _DecodeTile@8

Looks like stdcall, which is the default in the MASM32 package. C symbols are cdecl by default, so unless you are choosing a different calling convention in your C code, you might try

EXTERN C DecodeTile

or

DecodeTile PROTO C :DWORD,:DWORD

Vortex

Hi x86asm,

Kindly, could you post your source file(s)? Maybe, we can find a solution for the problem.

Relvinian

Quote from: x86asm on December 20, 2004, 05:14:48 AM
Now I have another problem guys, I'm having trouble referencing C code and C data variables. I was wondering how I would use the EXTERN keyword to do it. Cause prototyping like I would a normal ASM function gives me this error:

genvdp.obj : error LNK2001: unresolved external symbol _DecodeTile@8
Debug/SMSEM.exe : fatal error LNK1120: 1 unresolved externals
Error executing link.exe.


When you interface ASM code with Visual C++, most people forget that the typical ASM (at least with MASM) has been assembled with "stdcall" convention. That is what you see when you get the "unresolved external symbol _DecodeTile@8".

To correctly compensate for this in Visual Studio, you need to make sure you prototype your call correctly. A sample prototype for the above would be (assuming the return value is void and the arguments are void*).

extern "C" void __stdcall DecodeTile(void* arg1, void* arg2);


A alternate way to prototype your ASM functions is something like the following:

#ifdef __cplusplus
extern "C"
{
#endif

// prototype goes here (forcing stdcall convention).
void __stdcall DecodeTile(void* arg1, void* arg2);
char* __stdcall StringCopy(char* pDest, const char* pSrc);
etc, etc etc

#ifdef __cplusplus
}
#endif


Notice that in C/C++ code you must make the prototype "C" compiilable otherwise the default convention is mangled naming which isn't what you normally see when assembling .ASM files.

Hope this helps.

Relvinian