NASM - The Netwide Assembler
NASM Forum => Using NASM => Topic started by: nobody on April 04, 2005, 12:46:21 PM
-
I am using MS Visual C++ 6, with this code in "main.c":
#include
int dev1(); //asm function
void main(void)
{
int a=0;
a=dev1();
printf("%d",a);
}
and the "dev1.asm" compiled to "dev1.obj" with "nasm -fwin32 de1.asm":
BITS 32
global _dev1
section .text
_dev1:
enter 0,0
mov eax,1
leave
ret
- It works OK, but if I change the "main.c" to "main.cpp" it fails:
Linking...
main.obj : error LNK2001: unresolved external symbol "int __cdecl dev1(void)" (?dev1@@YAHXZ)
Debug/nasm.exe : fatal error LNK1120: 1 unresolved externals
Error executing link.exe.
- Then, how can I mix ASM with C++? It is important to use ASM with Classes, that are C++.
-
C++ decorates function names differently than C. See that ?dev1@@YAHXZ? That's your function name. You'll probably want to declare your assembly functions as extern "C" __cdecl, which makes it use C-style __cdecl decorating (which is what you wrote your ASM function as, given the name you use). C++ decoration is compiler-dependant, whereas C isn't.