0

When I try to use the InitWindow function from raylib using this code:

global _main


extern InitWindow
extern _ExitProcess@4

section .data
    title db "Window Title",0

section .text

_main:
    push title
    push 600
    push 800
    call InitWindow
    add esp, 12

    push 0
    call _ExitProcess@4

and compiling with these commands:

nasm -f win32 example.asm -o example.o
gcc example.o -o example.exe -lraylib -lopengl32 -lgdi32 -lwinmm

it's always giving me this error:

example.o:example.asm:(.text+0x10): undefined reference to `InitWindow'
collect2.exe: error: ld returned 1 exit status

Same happens when I try to use other functions of the raylib lib.

I also tried editing the function name to this _InitWindow@12 or this _InitWindow but that didnt work either. I also tried to link the object file with the direct path to the raylib directory but that didnt work too.

4
  • I expected _InitWindow to work, assuming of course that -lraylib finds a 32-bit library. I think you'd get other errors if your GCC defaulted to -m64, so I'm assuming its Mingw32 GCC or something with -m32 as the default. (Since that's necessary for nasm -f win32). Commented Jul 29 at 23:37
  • What does nm on the library show, in terms of the symbols it defines? 32-bit x86 on Windows always decorates symbols with a leading _, so it's either _InitWindow if cdecl (like how you're calling it with an add esp, 12 after: caller pops), or _InitWindow@12 if it's stdcall (caller pops, returning with ret 12, number of arg bytes indicated with @12 so ABI mismatch is a link error rather than stack corruption. In this case you shouldn't add esp,12 after.) Commented Jul 29 at 23:40
  • Anyway, see what symbol names the DLL defines that contain the string InitWindow. And/or look at C compiler output for a simple C program that calls these functions and exits. It's possible that some "functions" are actually macros or inline wrappers, or these's something else going on. Commented Jul 29 at 23:42
  • 2
    Please note that if you don't respond to comments you get, it's unlikely that you'll get an answer. Commented Jul 30 at 11:10

0

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge you have read our privacy policy.

Start asking to get answers

Find the answer to your question by asking.

Ask question

Explore related questions

See similar questions with these tags.