How to Compile outside of Notepad++?

Sorry if this is a dumb question, but how do you compile an executable using the terminal or .bat file on Windows 10?


The following command works whenever I run it in the Notepad++ script:
g++ -o MyGame.exe *.cpp -std=gnu++11 -s "C:\Users\MyName\Desktop\Raylib_Game\raylib\raylib\raylib_icon" -Iexternal -lraylib -lglfw3 -lopengl32 -lgdi32 -lopenal32 -lwinmm -Wl,-allow-multiple-definition -Wl,--subsystem,windows


However, when I run in the terminal, it results in this error:
/usr/lib/gcc/i686-pc-cygwin/5.4.0/../../../../i686-pc-cygwin/bin/ld: cannot find -lraylib
/usr/lib/gcc/i686-pc-cygwin/5.4.0/../../../../i686-pc-cygwin/bin/ld: cannot find -lglfw3
/usr/lib/gcc/i686-pc-cygwin/5.4.0/../../../../i686-pc-cygwin/bin/ld: cannot find -lopenal32
collect2: error: ld returned 1 exit status


I've tried moving the listed libraries into the source folder and bin folder, but with no success.
I've also made sure to set the path properly to the MinGW/bin folder as it's done in the Notepad++ script, fyi.

Thank you for reading, and I hope you can help. ^^

Comments

  • Hi Skelptr,

    It seems the compiler can not find the required libraries -lraylib -lglfw3 -lopenal32, just add the libraries path to compile line using -LC:\raylib\MinGW\libs.
  • Thank you for your response! However, I am now receiving this error:

    C:/raylib/MinGW/lib/libraylib.a(textures.o):textures.c:(.text+0x581): undefined reference to `_assert'
    C:/raylib/MinGW/lib/libraylib.a(textures.o):textures.c:(.text+0x605): undefined reference to `_assert'
    C:/raylib/MinGW/lib/libraylib.a(textures.o):textures.c:(.text+0x66f): undefined reference to `_assert'
    C:/raylib/MinGW/lib/libraylib.a(textures.o):textures.c:(.text+0x76a): undefined reference to `_assert'
    C:/raylib/MinGW/lib/libraylib.a(textures.o):textures.c:(.text+0x820): undefined reference to `_assert'
    C:/raylib/MinGW/lib/libraylib.a(textures.o):textures.c:(.text+0x850): more undefined references to `_assert' follow
    C:/raylib/MinGW/lib/libraylib.a(textures.o):textures.c:(.text+0xed7a): undefined reference to `__strtod'
    C:/raylib/MinGW/lib/libraylib.a(text.o):text.c:(.text+0xacf): undefined reference to `_assert'
    C:/raylib/MinGW/lib/libraylib.a(text.o):text.c:(.text+0xba3): undefined reference to `_assert'
    C:/raylib/MinGW/lib/libraylib.a(text.o):text.c:(.text+0xbd6): undefined reference to `_assert'
    C:/raylib/MinGW/lib/libraylib.a(text.o):text.c:(.text+0xc45): undefined reference to `_assert'
    C:/raylib/MinGW/lib/libraylib.a(text.o):text.c:(.text+0xc7a): undefined reference to `_assert'
    C:/raylib/MinGW/lib/libraylib.a(text.o):text.c:(.text+0xd4d): more undefined references to `_assert' follow
    C:/raylib/MinGW/lib/libraylib.a(text.o):text.c:(.text+0x72fb): undefined reference to `__mingw_vsprintf'
    C:/raylib/MinGW/lib/libraylib.a(utils.o):utils.c:(.text+0x11be): undefined reference to `_assert'
    C:/raylib/MinGW/lib/libraylib.a(utils.o):utils.c:(.text+0x18cc): undefined reference to `__mingw_vsprintf'
    C:/raylib/MinGW/lib/libraylib.a(utils.o):utils.c:(.text+0x1923): undefined reference to `_assert'
    C:/raylib/MinGW/lib/libraylib.a(utils.o):utils.c:(.text+0x1c29): undefined reference to `_assert'
    C:/raylib/MinGW/lib/libraylib.a(utils.o):utils.c:(.text+0x1c95): undefined reference to `_assert'
    C:/raylib/MinGW/lib/libraylib.a(utils.o):utils.c:(.text+0x2528): undefined reference to `_assert'
    C:/raylib/MinGW/lib/libraylib.a(utils.o):utils.c:(.text+0x305e): undefined reference to `_assert'
    C:/raylib/MinGW/lib/libraylib.a(utils.o):utils.c:(.text+0x57cf): undefined reference to `__mingw_vprintf'
    collect2: error: ld returned 1 exit status
  • It seems some basic C libraries are not linked properly... do you have multiple MinGW packages installed in your system? Try adding -static to compilation to link libc library statically.
  • edited December 9
    Ah, you're right! I was using the wrong g++. I went ahead a specifically called "C:\raylib\MinGW\bin\g++.exe" for the command. I think it did the trick (at least for that problem)!

    However, once again, it appears nothing will be easy. I'm now receiving this error:

    /usr/bin/ld: c:/raylib/mingw/bin/../lib/gcc/mingw32/5.3.0/../../../crt2.o: lseek: Bad file descriptor
    collect2.exe: error: ld returned 1 exit status

    I've tried researching as much as I can before returning here a third time, but I have had no success. If you can find it in your heart to provide another suggestion, I would greatly appreciate it. >.<
  • It seems there is some conflict with multiple MinGW versions installed in your system, check Environment Variable path to see which version is used on compilation.

    You can be calling one g++.exe but maybe libraries used are from the other MinGW version and so the conflicts.
  • Oh! That's it! Why didn't I think of doing this sooner! >.<
    You're right, I have multiple libraries in my environment vars, but the proper way to resolve this is to temporarily set the PATH variable to only the bin directory.

    This is what NotePad++ does in its script, but I completely looked over it and tried appending the PATH to its existing version.

    For any future people reading this, this is what I did in the terminal:

    set PATH=C:\raylib\MinGW\bin

    g++ -o MyGame.exe *.cpp -std=gnu++11 -s "C:\Users\MyName\Desktop\Raylib_Game\raylib\raylib\raylib_icon" -LC:\raylib\MinGW\lib -Iexternal -lraylib -lglfw3 -lopengl32 -lgdi32 -lopenal32 -lwinmm -Wl,-allow-multiple-definition -Wl,--subsystem,windows


    Thanks for all your help! Signing on as a patron now ^^
  • Hi Skelptr! Glad to read you manage to get it! :smiley:

    Also, thank you very much for your pledge as a patron.

    Feel free to ask any doubt you have!
  • Thanks! ^^
Sign In or Register to comment.