Author Topic: Link error with Visual C++  (Read 6893 times)

xzyx987x

  • Guest
Link error with Visual C++
« on: April 21, 2005, 01:53:29 AM »
This is probably a really stupid question, but I can't seem to figure it out. I put together a test file to get NASM to work based on the documentation. Here are the contents:

;Macros;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;

;Keep from having to prefix an underscore to functions

%macro  cglobal 1

global  _%1
  %define %1 _%1

%endmacro

%macro  cextern 1

extern  _%1
  %define %1 _%1

%endmacro

;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;



;Opcode functions;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;

cglobal  myfunc

myfunc:
        push    ebp
        mov     ebp,esp
        sub     esp,0x40        ; 64 bytes of local stack space
        mov     ebx,[ebp+8]     ; first parameter to function

; some more code

leave                   ; mov esp,ebp / pop ebp
        ret

;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;

It assembles fine, but when I get to the link phase I end up with: error LNK2001: unresolved external symbol _myfunc. Here's the commandline setup I was using: nasmw -f win32 -o "$(IntDir)\$(InputName).obj" "$(InputPath)". I know I must be missing something obvious here, but I'm new to NASM so would someone mind telling me what I'm doing wrong?

xzyx987x

  • Guest
Re: Link error with Visual C++
« Reply #1 on: April 21, 2005, 07:07:16 PM »
Ah... ok, I found the problem. When I opened up my obj file in IDA, I noticed that the section my function's code was being labled as text. It didn't take me much from there to figure out I was suposed to label the code section with section .data.

xzyx987x

  • Guest
Re: Link error with Visual C++
« Reply #2 on: April 21, 2005, 07:13:11 PM »
Make that section .exec :P.