Jeremiah Goerdt
208 posts / 1 project
Build a man a fire, and he'll be warm for a day. Set a man on fire, and he'll be warm for the rest of his life.
Unable to Build on Windows using cl at Command Line
Edited by Jeremiah Goerdt on Reason: Initial post
Most of my experience programming is in Linux, so I'm trying to figure out how to setup a decent development environment on Windows.

I'd like to build my game at the command line using cl. When I try to build the 'basic window' example code, I use this command:

This spits out a bunch of warnings and errors. Here's the gist:

/out:main.exe
main.obj
.\lib\raylib.lib
LINK : warning LNK4098: defaultlib 'MSVCRTD' conflicts with use of other libs; use /NODEFAULTLIB:library
raylib.lib(core.obj) : warning LNK4217: locally defined symbol fclose imported in function StorageSaveValue
raylib.lib(text.obj) : warning LNK4049: locally defined symbol fclose imported
raylib.lib(utils.obj) : warning LNK4049: locally defined symbol fclose imported
...
raylib.lib(win32_joystick.obj) : error LNK2019: unresolved external symbol __imp_GetRawInputDeviceInfoA referenced in function supportsXInput
raylib.lib(win32_joystick.obj) : error LNK2019: unresolved external symbol __imp_GetRawInputDeviceList referenced in function supportsXInput
raylib.lib(wgl_context.obj) : error LNK2019: unresolved external symbol __imp_ChoosePixelFormat referenced in function _glfwInitWGL
raylib.lib(wgl_context.obj) : error LNK2019: unresolved external symbol __imp_DescribePixelFormat referenced in function _glfwCreateContextWGL
raylib.lib(wgl_context.obj) : error LNK2019: unresolved external symbol __imp_SetPixelFormat referenced in function _glfwInitWGL
raylib.lib(wgl_context.obj) : error LNK2019: unresolved external symbol __imp_SwapBuffers referenced in function swapBuffersWGL
main.exe : fatal error LNK1120: 140 unresolved externals

Since I'm new to the Windows dev environment, I'm not exactly sure what's going on. It seems like there might be a problem with the crt that raylib was built with not being compatible with mine? Or maybe I'm not linking it correctly?

This is almost certainly something simple that I'm missing. Any direction would be appreciated. Thanks!
Marc Costa
65 posts
Unable to Build on Windows using cl at Command Line
You will need to at least add a couple of Windows libraries to your linker command line:

 1 cl main.c /LINK .\lib\raylib.lib user32.lib gdi32.lib 
Mārtiņš Možeiko
2406 posts / 2 projects
Unable to Build on Windows using cl at Command Line
Edited by Mārtiņš Možeiko on
There are two issues you are seeing.

First are the warnings (that sometimes lead to linker errors) which comes from fact that MSVC has multiple C runtime libraries. These libraries are not compatible with each other. So in case one part of source code or library (like raylib.lib) is compiled with one C runtime, but your code is compiled with different C runtime then you'll see these errors/warnings.

To avoid that you need to use exactly same runtime library as rest of your code (and libraries). Type of C runtime is selected with following flags:
* /MP - to use statically linked release runtime (release means it will avoid doing special debug asserts to validate some internal checks, like corruption of memory)
* /MPd - to use statically linked debug runtime
* /MD - to use dynamically linked release runtime (dynamically means your .exe will depend on msvcrXXX.dll and vcruntimeXX.dll and other C runtime dll files)
* /MDd - to use dynamically linked debug runtime

Also make sure you are using same visual studio as raylib.lib file was created with (2013 vs 2015 vs 2017). Different versions of Visual Studio uses different versions of C/C++ runtime libraries which are not compatible with each other.

Other are errors about unresolved externals. As marcc already explained, this is solved by adding import libraries for linker. How to know which libraries you need to add? MSDN will tell you that. For example, you see it cannot find __imp_GetRawInputDeviceInfoA symbol, that means you need to check documentation for GetRawInputDeviceInfo function. Scroll to the bottom to see which library you need to use (Library = User32.lib).
Ray
62 posts / 1 project
I like videogames/gametools development.
Unable to Build on Windows using cl at Command Line
Hi CaptainCraft!

To develop on Windows I distribute a ready-to-use package with MinGW-w64 and Notepad++ already pre-configured to start developing with raylib in seconds: raylib_installer_v2.0.exe.

Also, even if you use the installer or download raylib from GitHub, you have a raylib/projects folder with already preconfigured project for several environments, including VS2015 and VS2017.

Let me know if it works! :)
Jeremiah Goerdt
208 posts / 1 project
Build a man a fire, and he'll be warm for a day. Set a man on fire, and he'll be warm for the rest of his life.
Unable to Build on Windows using cl at Command Line
Thanks everyone. After linking the shell32 lib, it runs!

raysan5
Hi CaptainCraft!

To develop on Windows I distribute a ready-to-use package with MinGW-w64 and Notepad++ already pre-configured to start developing with raylib in seconds: raylib_installer_v2.0.exe.

Also, even if you use the installer or download raylib from GitHub, you have a raylib/projects folder with already preconfigured project for several environments, including VS2015 and VS2017.

Let me know if it works! :)

Ray! CaptainKraft here (cough cough) ;-)

Depending on how all this setup goes, I intend to check out your installer and potentially use your configurations. However, the goal last night was to become familiar with building things by hand on Windows. I'm looking forward to getting it all up and running, because it appears as though you've built a great set of libraries for making games.

Thanks again for all the help everyone.
Ray
62 posts / 1 project
I like videogames/gametools development.
Unable to Build on Windows using cl at Command Line
Well done CaptainKraft! :D

Did you mind sharing the complete compilation command line using cl? Just to compare with the VS generated one...

Thanks! :)
Jeremiah Goerdt
208 posts / 1 project
Build a man a fire, and he'll be warm for a day. Set a man on fire, and he'll be warm for the rest of his life.
Unable to Build on Windows using cl at Command Line
I used this command:

cl /MDd main.c /LINK lib/raylib.lib user32.lib gdi32.lib shell32.lib

But, there are a few hiccups still. First of all, I get the warning:

cl : Command line warning D9002 : ignoring unknown option '/LINK'

It still links the libraries and builds the executable, so I'm not sure why it is complaining. Also, it takes around 5 seconds to start the window. Maybe that is normal for a game built using Raylib?

So far, I'm not comfortable with building on Windows, so I have some more work to do. I must admit, it hasn't been fun :-P
Mārtiņš Možeiko
2406 posts / 2 projects
Unable to Build on Windows using cl at Command Line
Ray
62 posts / 1 project
I like videogames/gametools development.
Unable to Build on Windows using cl at Command Line

5 secods to start de program is not normal at all...
Jeremiah Goerdt
208 posts / 1 project
Build a man a fire, and he'll be warm for a day. Set a man on fire, and he'll be warm for the rest of his life.
Unable to Build on Windows using cl at Command Line
mmozeiko

Thanks!

raysan5

5 secods to start de program is not normal at all...

It will say "INFO: Initializing raylib 2.0" for 5 to 10 seconds before bringing up the window. No clue why.
Jeremiah Goerdt
208 posts / 1 project
Build a man a fire, and he'll be warm for a day. Set a man on fire, and he'll be warm for the rest of his life.
Unable to Build on Windows using cl at Command Line
It turns out that anything I build with subsystem set to CONSOLE takes forever to start. If I set the subsystem to WINDOWS, it runs right away. No clue why...
Ray
62 posts / 1 project
I like videogames/gametools development.
Unable to Build on Windows using cl at Command Line
That's weird... never heard of that issue before... do you have any antivirus running in background?
Mārtiņš Možeiko
2406 posts / 2 projects
Unable to Build on Windows using cl at Command Line
Or using some custom console replacements (conemu, cmder, etc..) ?
Jeremiah Goerdt
208 posts / 1 project
Build a man a fire, and he'll be warm for a day. Set a man on fire, and he'll be warm for the rest of his life.
Unable to Build on Windows using cl at Command Line
No antivirus, but I do have ConEmu installed. Whether I launch the program from cmd, ConEmu, or Visual Studio, I get the same result.