Handmade Hero » Forums » Code » Day 21 - Help with Weirdness on Struct Syntax Errors and Multiple .OBJ Defines?
echu
5 posts
#16550 Day 21 - Help with Weirdness on Struct Syntax Errors and Multiple .OBJ Defines?
1 month, 1 week ago Edited by echu on Oct. 14, 2018, 6:20 p.m. 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.
William
5 posts
#16551 Day 21 - Help with Weirdness on Struct Syntax Errors and Multiple .OBJ Defines?
1 month, 1 week ago

I think the build errors are from not having 'HANDMADE_INTERNAL' set.
echu
5 posts
#16552 Day 21 - Help with Weirdness on Struct Syntax Errors and Multiple .OBJ Defines?
1 month, 1 week ago Edited by echu on Oct. 14, 2018, 9:05 p.m.

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.
mrmixer
Simon Anciaux
481 posts
#16553 Day 21 - Help with Weirdness on Struct Syntax Errors and Multiple .OBJ Defines?
1 month, 1 week ago

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
echu
5 posts
#16554 Day 21 - Help with Weirdness on Struct Syntax Errors and Multiple .OBJ Defines?
1 month, 1 week ago Edited by echu on Oct. 15, 2018, 3:41 a.m. 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
echu
5 posts
#16555 Day 21 - Help with Weirdness on Struct Syntax Errors and Multiple .OBJ Defines?
1 month, 1 week ago Edited by echu on Oct. 15, 2018, 4:17 a.m.

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.
mmozeiko
Mārtiņš Možeiko
1826 posts / 1 project
#16561 Day 21 - Help with Weirdness on Struct Syntax Errors and Multiple .OBJ Defines?
1 month ago Edited by Mārtiņš Možeiko on Oct. 15, 2018, 2:47 p.m.

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).
echu
5 posts
#16562 Day 21 - Help with Weirdness on Struct Syntax Errors and Multiple .OBJ Defines?
1 month ago Edited by echu on Oct. 15, 2018, 5:42 p.m.

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!