raylib » Forums » Unable to Build on Windows using cl at Command Line
CaptainKraft
Jeremiah Goerdt
212 posts / 2 projects

Stay-at-home Dad, Programmer, and Linux apologist.

#15861 Unable to Build on Windows using cl at Command Line
3 months, 3 weeks ago Edited by Jeremiah Goerdt on July 24, 2018, 2:36 a.m. 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:

cl main.c /LINK .\lib\raylib.lib

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!

Build a man a fire, he'll be warm for a day.
Set a man on fire, he'll be warm for the rest of his life.
marcc
Marc Costa
32 posts
#15862 Unable to Build on Windows using cl at Command Line
3 months, 3 weeks ago

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
mmozeiko
Mārtiņš Možeiko
1826 posts / 1 project
#15863 Unable to Build on Windows using cl at Command Line
3 months, 3 weeks ago Edited by Mārtiņš Možeiko on July 24, 2018, 5:15 a.m.

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).
raysan5
Ray
46 posts / 1 project

I love videogames development.

#15864 Unable to Build on Windows using cl at Command Line
3 months, 3 weeks ago

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! :)
CaptainKraft
Jeremiah Goerdt
212 posts / 2 projects

Stay-at-home Dad, Programmer, and Linux apologist.

#15866 Unable to Build on Windows using cl at Command Line
3 months, 3 weeks ago

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.

Build a man a fire, he'll be warm for a day.
Set a man on fire, he'll be warm for the rest of his life.
raysan5
Ray
46 posts / 1 project

I love videogames development.

#15870 Unable to Build on Windows using cl at Command Line
3 months, 3 weeks ago

Well done CaptainKraft! :D

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

Thanks! :)
CaptainKraft
Jeremiah Goerdt
212 posts / 2 projects

Stay-at-home Dad, Programmer, and Linux apologist.

#15873 Unable to Build on Windows using cl at Command Line
3 months, 3 weeks ago

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

Build a man a fire, he'll be warm for a day.
Set a man on fire, he'll be warm for the rest of his life.
mmozeiko
Mārtiņš Možeiko
1826 posts / 1 project
#15875 Unable to Build on Windows using cl at Command Line
3 months, 3 weeks ago

raysan5
Ray
46 posts / 1 project

I love videogames development.

#15876 Unable to Build on Windows using cl at Command Line
3 months, 3 weeks ago


5 secods to start de program is not normal at all...
CaptainKraft
Jeremiah Goerdt
212 posts / 2 projects

Stay-at-home Dad, Programmer, and Linux apologist.

#15877 Unable to Build on Windows using cl at Command Line
3 months, 3 weeks ago

mmozeiko
/link is lowercase: https://msdn.microsoft.com/en-us/library/5y4fae15.aspx


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.

Build a man a fire, he'll be warm for a day.
Set a man on fire, he'll be warm for the rest of his life.
CaptainKraft
Jeremiah Goerdt
212 posts / 2 projects

Stay-at-home Dad, Programmer, and Linux apologist.

#15885 Unable to Build on Windows using cl at Command Line
3 months, 3 weeks ago

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...

Build a man a fire, he'll be warm for a day.
Set a man on fire, he'll be warm for the rest of his life.
raysan5
Ray
46 posts / 1 project

I love videogames development.

#15890 Unable to Build on Windows using cl at Command Line
3 months, 2 weeks ago

That's weird... never heard of that issue before... do you have any antivirus running in background?
mmozeiko
Mārtiņš Možeiko
1826 posts / 1 project
#15891 Unable to Build on Windows using cl at Command Line
3 months, 2 weeks ago

Or using some custom console replacements (conemu, cmder, etc..) ?
CaptainKraft
Jeremiah Goerdt
212 posts / 2 projects

Stay-at-home Dad, Programmer, and Linux apologist.

#15895 Unable to Build on Windows using cl at Command Line
3 months, 2 weeks ago

No antivirus, but I do have ConEmu installed. Whether I launch the program from cmd, ConEmu, or Visual Studio, I get the same result.

Build a man a fire, he'll be warm for a day.
Set a man on fire, he'll be warm for the rest of his life.