Handmade Hero»Forums»Code
19 posts
Day 21 - Help with Weirdness on Struct Syntax Errors and Multiple .OBJ Defines?
Edited by echu on Reason: Fixed broken image links.
I'm trying to follow along with Day 021 as of ~47:30, and everything up to this point has been going decently well. However, I'm suddenly running into tons of errors that prevent building and I've spent hours trying to debug - see the image below. I've also attached my current commented source files project properties in VS 2017.

build errors
VS project properties

handmade.h
win32_handmade.h
handmade.cpp
win32_handmade.cpp

I don't understand how I'm getting errors, but I'm suspecting it's something to do with my headers/includes, my VS 2017 properties, or my build.bat.

If someone could post their VS 2017 properties and build file, or otherwise help me get back on track, I'd be grateful.
18 posts
Day 21 - Help with Weirdness on Struct Syntax Errors and Multiple .OBJ Defines?
I think the build errors are from not having 'HANDMADE_INTERNAL' set.
19 posts
Day 21 - Help with Weirdness on Struct Syntax Errors and Multiple .OBJ Defines?
Edited by echu on
William, where do I set HANDMADE_INTERNAL in the project properties? I seem to recall something like that being set on Day 001, but I'm on the 2017 version and would like a bit more direction.

Thanks for your help.
Simon Anciaux
1337 posts
Day 21 - Help with Weirdness on Struct Syntax Errors and Multiple .OBJ Defines?
In "C/C++" > "Preprocessor" > "Preprocessor definitions".

If you use the build.bat file to build it should contain -DHANDMADE_INTERNAL on the cl line. For example

1
cl win32_handmade.cpp -DHANDMADE_INTERNAL -link user32.lib gdi32.lib winmm.lib
19 posts
Day 21 - Help with Weirdness on Struct Syntax Errors and Multiple .OBJ Defines?
Edited by echu on Reason: build errors changed
After changing preprocessor definitions as shown below in the C/C++ section and rewriting my batch file to take out all but the necessary flags, I get somewhat fewer build errorsas when I try to build from the batch file. It's a step in the right direction!

Now, the issue seems to exclusively be with the dynamic linking that Casey does with the function pointers, and Visual Studio not liking that. There's also weird errors from VS and batch still complaining about multiple function defines and unresolved externals.

No changes to the source files included in the first post have been made.

errors, VS C++ preprocessor settings, and my build.bat
19 posts
Day 21 - Help with Weirdness on Struct Syntax Errors and Multiple .OBJ Defines?
Edited by echu on
I decided my settings/batch were too polluted to continue effectively, so I restored from the Day 022 source provided by Casey and compiled from the batch with no problems.

In the end, Visual Studio 2017 still refused to provide a clean compile, complaining about the multiple defines I linked in my last post.
Mārtiņš Možeiko
2559 posts / 2 projects
Day 21 - Help with Weirdness on Struct Syntax Errors and Multiple .OBJ Defines?
Edited by Mārtiņš Možeiko on
For "already defined" error it seems you are linking together win32_handmade.cpp and handmade.cpp files. That's not how Casey is building HH. Check the build.bat - he is creating two output files - win32_handmade.exe where win32_handmade.cpp is compiled into and handmade.dll file where handmade.cpp is compiled into. You'll need to create two projects in VS solution.

Unresolved external errors comes from fact that you are not passing import libraries to linker. Why this happens? Because you are using space after "linker_flags" variable name when setting its value. This makes bat file processor to set completely different variable. Remove spaces around = sign.
Basically "set abc=def" sets variable %abc% to value "def". But "set abc = def" sets variable %abc % to value " def".

VS2017 generates a bit more warnings (which are treated as errors), so you'll need to fix few of them - mostly "X hides declaration of Y". Or you can use extra compiler argument "/Wv:18" - it will try to be compatible with VS2013 version.

If you want to use VS build, I have a post here that explains how to create one: https://hero.handmade.network/for...ll_compiler_nightmare_week_5#6104 The formatting was lost during forum upgrades, but I think it should be pretty clear what to do. It was written for ~week 5 code, so there are some steps which are unnecessary for you (like simple_preprocessor project / handmade_generated.h file).
19 posts
Day 21 - Help with Weirdness on Struct Syntax Errors and Multiple .OBJ Defines?
Edited by echu on
Wow, this is extremely helpful! Thanks for the great writeup, I will definitely try and do a deep dive into what you’ve written. I know I can build from batch as is, but I want to understand why VS is throwing errors and you’ve provided a great resource into doing so!