Author Topic: How to mix nasm with C++ code?  (Read 13083 times)

nobody

  • Guest
How to mix nasm with C++ code?
« on: April 04, 2005, 06:12:00 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 dev1.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++.

Online Frank Kotler

  • NASM Developer
  • Hero Member
  • *****
  • Posts: 2667
  • Country: us
Re: How to mix nasm with C++ code?
« Reply #1 on: April 04, 2005, 07:52:45 PM »
extern "C" int dev1();

... or something similar to that, should keep C++ from "decorating" function names.

Best,
Frank