Hi,
I'm trying to compile crafty 25.6 using VS2019.
I removed the includes in crafty.c and added all .h and .c files except probe.c, tb*.c and stdendian.h
I gives a linker error:
lock.h establishes the function Pause() as global symbol in line 33. Originally, that wasn't a problem because evverything was included into one C file so that this function appeared only once. And that was because there's probably some header guards that guard against multiple inclusion in the same file. When you include C files, you have several files on disk, but it's only one compilation unit.
But now you have several compilation units, so this include guards now works per file, and that's why the Pause() function is established in several files.
Actually, the whole way how Crafty organises the code is not favoured anymore these days. You generally don't include C files that have actual code, and you don't define functions in header files. However, back when Crafty was created, there was no link time optimisation yet, so that was the only way to make the compiler see and optimise all code at once, which gave a de facto link time optimisation even without compiler support. Certainly hacky even back then, but justified when squeezing the last drop of performance.
Cardoso wrote: ↑Thu Apr 09, 2020 3:25 pmI added "#pragma once" in lock.h but it didn't help.
What am I missing?
You're compiling the C files as individual translation units. When one file includes lock.h, your pragma guards against a second inclusion in that same C file, but not against an inclusion in another C file. You can compile all C files, but when linking, the linker finds the same function name in two different object files.
Before, since all the C file were included directly, the actual compiler run would only see a single huge C file, i.e. a single translation unit.
There is still a "crafty.c" file that #includes all source files. That should avoid this at the expense of increased compile time with the gain of better function inlining/unrolling.