After watching some Handmade Hero I thought I'd try getting used to Windows command prompt. I've been working on a 2D game in C that was originally being developed on MacOS and Linux. It also worked on Windows but you needed MinGW installed.
I decided to switch to MSVC and batch files to build my game, and it's been a struggle getting anything working.
Here is the Batch file:
@echo off cls mkdir build\ pushd build\ cl /W4 /FC /Zi ^ /I..\sdl2\include /I..\..\include /I..\..\include\adt /Isdl2\include ^ ..\..\src\adt\*.c ..\..\src\*.c ^ /link ..\sdl2\lib\SDL2.lib ..\sdl2\lib\SDL2main.lib ..\sdl2\lib\SDL2_image.lib ^ /o:game.exe ^ /SUBSYSTEM:WINDOWS /DEBUG popd
Using MSVC on developer command prompt was a bit of a challenge. The syntax is different than GCC, and wasn't sure about some of the commands/arguments. But the idea is to compile, then link into a
/assets /bin (output files from MacOS/Linux) /include *.h (other header files related to game) /adt LinkedListAPI.h HashTableAPI.h /src *.c (other source files related to game) /adt LinkedListAPI.c HashTableAPI.c /windows /build (where the .exe is placed) SDL2.dll SDL2main.dll /sdl2 /include /lib build.bat
#ifndef GRAPHICS_H #define GRAPHICS_H #include "HashTableAPI.h" #include <stdio.h> #include <stdbool.h> #include <stdarg.h> #ifdef __linux__ #include <SDL2/SDL.h> #include <SDL2/SDL_image.h> #elif _WIN32 #include "SDL.h" #include "SDL_image.h" // Complains this file is missing, even though it's in the same folder as SDL.h #endif
The first C file compiled is
HashTableAPI.c. There is always an executable created named
HashTableAPI.exe, even if I use the
My program compiles with no warnings (except all the GCC function warnings), but the program crashes immediately after starting. The only valuable pieces of info I get from the output are:
'HashTableAPI.exe' (Win32): Loaded 'C:\Users\17058\Desktop\git-repos\Dog-Gone-Wild\windows\build\SDL2_image.dll'. Module was built without symbols 'HashTableAPI.exe' (Win32): Loaded 'C:\Users\17058\Desktop\git-repos\Dog-Gone-Wild\windows\build\SDL2.dll'. Module was built without symbols. The program ' HashTableAPI.exe' has exited with code -1 (0xffffffff).
Does anyone have insight why it's not working? Clearly I am doing something wrong
Am I missing a
WinMain() function? I have an
int main(int argc, char* argv).
How should I organize my project structure if I will be supporting multiple operating systems? I feel a little confused what should go where.
Thank you so much for your time!
User contributions licensed under CC BY-SA 3.0