-
Help Appreciated
Sorry about the vagueness of the thread title, I didn't want to scare anyone away...
Ok, I started learning about Linking assembly routines into visual C++ programs via the Custom Build options.
I think I've declared everything as I should, here's my main C++ source:
Code:
#include <iostream>
extern "C" _asm_main();
int main (int argc, char* argv[])
{
_asm_main();
return 0;
}
Now the .asm file, with the declaration of _asm_main:
Code:
.386
.model flat, C
.code
_asm_main PROC
mov eax, 10
ret
_asm_main ENDP
END
I'm assembling with TASM 5.0, using the Custom Build command 'C:\TASM\BIN\TASM.EXE $(InputPath)' and output 'extproc.obj' (the assembly file is called extproc.asm).
I get the infamous LNK1120 (unresolved externals). Here's the complete output, for the record:
Code:
--------------------Configuration: atest - Win32 Debug--------------------
Performing Custom Build Step on .\extproc.asm
Turbo Assembler Version 4.1 Copyright (c) 1988, 1996 Borland International
Assembling file: .\extproc.asm to extproc.OBJ
Error messages: None
Warning messages: None
Passes: 1
Remaining memory: 411k
Linking...
.\extproc.obj : warning LNK4033: converting object format from OMF to COFF
main.obj : error LNK2001: unresolved external symbol __asm_main
Debug/atest.exe : fatal error LNK1120: 1 unresolved externals
Error executing link.exe.
atest.exe - 3 error(s), 2 warning(s)
Help greatly appreciated :)
-
>__asm_main
Well it looks like it's adding a _ to the beginning of the name, so maybe change:
_asm_main();
to:
asm_main();
Or you could change the asm from:
_asm_main PROC
to:
__asm_main PROC
-
Hmm nope I get the same problem.
-
>Hmm nope I get the same problem.
Same exact error?
-
Code:
--------------------Configuration: atest - Win32 Debug--------------------
Linking...
.\extproc.obj : warning LNK4033: converting object format from OMF to COFF
main.obj : error LNK2001: unresolved external symbol __asm_main
Debug/atest.exe : fatal error LNK1120: 1 unresolved externals
Error executing link.exe.
atest.exe - 2 error(s), 1 warning(s)
Yeah, pretty much, except the unresolved external symbol is now __asm_main.
-
Sneaky suspicion...is that ASM file a part of your project/workspace?
-
Yes.
Isn't vae victus something to do with Caeser?
-
Your C code needs one less underscore at the start than your equivalent ASM function.
extern "C" _asm_main();
unresolved external symbol __asm_main
> .model flat, C
Or maybe because you've said it's 'C' here as well, then you should make them both the same.
-
Nope that made no difference. I've noticed there's a shortage of online material on this subject, it's quite annoying.
-
A quick google search and I came up with this website that addresses your problem I think?
http://www.cs.uakron.edu/~margush/30...Cplusplus.html
-
That's an excellent link. :)
>I chose to reassemble with the /Mx option.
It looks like that might do it.