First SDL3 build using cl in Windows 11

Hello.
Sorry if posted before.
New to C.
I installed VS Community and using cl to build one of the examples for SDL(lines.c)
Example here:
examples/renderer/lines

I downloaded SDL3 from here:
Release 3.2.16 · libsdl-org/SDL · GitHub Source code

I call cl like this in dev console:
cl lines.c /I"C:\Temp\Ccode\test grounds\SDL-release-3.2.16\include" /link /subsystem:WINDOWS

Output:
Microsoft (R) C/C++ Optimizing Compiler Version 19.44.35209 for x86
Copyright (C) Microsoft Corporation. All rights reserved.

lines.c
Microsoft (R) Incremental Linker Version 14.44.35209.0
Copyright (C) Microsoft Corporation. All rights reserved.

/out:lines.exe
/subsystem:WINDOWS
lines.obj
lines.obj : error LNK2019: unresolved external symbol _SDL_rand referenced in function _SDL_AppIterate
lines.obj : error LNK2019: unresolved external symbol _SDL_cosf referenced in function _SDL_AppIterate
lines.obj : error LNK2019: unresolved external symbol _SDL_sinf referenced in function _SDL_AppIterate
lines.obj : error LNK2019: unresolved external symbol _SDL_GetError referenced in function _SDL_AppInit
lines.obj : error LNK2019: unresolved external symbol _SDL_Init referenced in function _SDL_AppInit
lines.obj : error LNK2019: unresolved external symbol _SDL_SetAppMetadata referenced in function _SDL_AppInit
lines.obj : error LNK2019: unresolved external symbol _SDL_Log referenced in function _SDL_AppInit
lines.obj : error LNK2019: unresolved external symbol _SDL_CreateWindowAndRenderer referenced in function _SDL_AppInit
lines.obj : error LNK2019: unresolved external symbol _SDL_SetRenderDrawColor referenced in function _SDL_AppIterate
lines.obj : error LNK2019: unresolved external symbol _SDL_RenderClear referenced in function _SDL_AppIterate
lines.obj : error LNK2019: unresolved external symbol _SDL_RenderLine referenced in function _SDL_AppIterate
lines.obj : error LNK2019: unresolved external symbol _SDL_RenderLines referenced in function _SDL_AppIterate
lines.obj : error LNK2019: unresolved external symbol _SDL_RenderPresent referenced in function _SDL_AppIterate
lines.obj : error LNK2019: unresolved external symbol _SDL_RunApp referenced in function _main
lines.obj : error LNK2019: unresolved external symbol _SDL_EnterAppMainCallbacks referenced in function _SDL_main
lines.exe : fatal error LNK1120: 15 unresolved externals

I am very confused how to use linker, examples I found refer to *.lib files which SDL3 I got does not have. I am sure I am doing something very wrong(I am trying to use Windows), but after two days of trying various things, I am out of ideas.

And suggestions would be greatly appreciated.

Thank you and have a great day,
Alex.

I haven’t done a windows build in a long time and I may have been using mingw when I did. If you get the window DLLs (the x64 zip) you can probably add the dll at the end of the line and it might work. It depends on how that dll was built. I think the last time I compiled for windows I didn’t want to deal with MS and I used the zig compile (zig cc or zig c++) to compile my C and C++ code

This thread might be useful but I’m not sure Building w/MingW

1 Like

Hello.

Thank you very much!

Your reply helped me to figure out what I was doing wrong.

In case relevant for someone else:
I downloaded this instead: SDL3-devel-3.2.16-VC.zip

That download contains 3 architectures. I my case I was building x86, so the build string became this:

cl lines.c /I"C:\Temp\Ccode\test grounds\SDL3-3.2.16\include" /link “C:\Temp\Ccode\test grounds\SDL3-3.2.16\lib\x86\SDL3.lib” /subsystem:windows

This generated desired exe, but it still relies on SDL3.dll to be on path.

Copying SDL3.dll from the include folder into current folder made everything work.

Thank you again.

1 Like