INCBIN and VS2022 with clang

Discussion of chess software programming and technical issues.

Moderator: Ras

chrisw
Posts: 4624
Joined: Tue Apr 03, 2012 4:28 pm
Location: Midi-Pyrénées
Full name: Christopher Whittington

Re: INCBIN and VS2022 with clang

Post by chrisw »

Joost Buijs wrote: Wed May 24, 2023 3:28 pm
chrisw wrote: Wed May 24, 2023 8:28 am
chrisw wrote: Tue May 23, 2023 9:21 pm C? I’ll give that a try. Right now the entire everything is sort of disintegrating, debug mode and optimisations off won’t turn optimisations off, so single stepping keeps jumping over code and variables say they’re optimised away. Some code isn’t being executed even. Chaos. Reboot and try again tomorrow.
Same error in C

Build started...
1>------ Build started: Project: incbin-test, Configuration: Debug x64 ------
1>lld-link : error : undefined symbol: gbookbinSize
1>>>> referenced by C:\Users\chris\source\repos\incbin-test\incbin-test\incbin.c:14
1>>>> x64\Debug\incbin.obj:(main)
1>
1>lld-link : error : undefined symbol: gbookbinData
1>>>> referenced by C:\Users\chris\source\repos\incbin-test\incbin-test\incbin.c:15
1>>>> x64\Debug\incbin.obj:(main)
1>
1>lld-link : error : undefined symbol: gbookbinEnd
1>>>> referenced by C:\Users\chris\source\repos\incbin-test\incbin-test\incbin.c:16
1>>>> x64\Debug\incbin.obj:(main)
1>Done building project "incbin-test.vcxproj" -- FAILED.
Very strange. Over here I can build and link it with a "binary.bin" file without any problems. It only works with the CLang "C" compiler though, with the C++ compiler I get undefined symbols, C++ name mangling is probably the cause of this.

It builds without a hitch:

Code: Select all

Rebuild started...
1>------ Rebuild All started: Project: incbin, Configuration: Release x64 ------
1>incbin.vcxproj -> D:\incbin\x64\Release\incbin.exe
========== Rebuild All: 1 succeeded, 0 failed, 0 skipped ==========
========== Rebuild started at 3:23 PM and took 00,508 seconds ==========
The output looks fine too:

Code: Select all

start = 00007FF699282000
end = 00007FF69A2B9E48
size = 17006152
first byte = 0x00

D:\incbin\x64\Release\incbin.exe (process 9672) exited with code 0.
Press any key to close this window . . .
I used the clang that comes as part of VS download. Is there another version somewhere?

Actually clang is giving me much grief since I made the switch a few weeks ago, it insists on optimising when in debug-optimisations-off mode, and stuff gets impossible to single step or view. So, gave up and reverted to the VS compiler. I guess it I could get incbin to work, then clang could just be used for final builds.
Joost Buijs
Posts: 1632
Joined: Thu Jul 16, 2009 10:47 am
Location: Almere, The Netherlands

Re: INCBIN and VS2022 with clang

Post by Joost Buijs »

chrisw wrote: Wed May 24, 2023 5:28 pm Actually clang is giving me much grief since I made the switch a few weeks ago, it insists on optimising when in debug-optimisations-off mode, and stuff gets impossible to single step or view. So, gave up and reverted to the VS compiler. I guess it I could get incbin to work, then clang could just be used for final builds.
I tried with the CLang compiler that comes with Visual Studio (version 15.0.1), and as I showed before it works. You can download the latest LLVM version from github (16.0.4): https://github.com/llvm/llvm-project/re ... org-16.0.4

You can install this alongside the other version, no problem, but if you want to use it you have to put a manifest file in your project directory which should be called "Directory.build.props"

It should contain:

Code: Select all

<Project>
  <PropertyGroup>
    <LLVMInstallDir>C:\Program Files\LLVM</LLVMInstallDir>
    <LLVMToolsVersion>16.0.4</LLVMToolsVersion>
  </PropertyGroup>
</Project>
When you have done this you have to alter the LLVM version in your project to 16. You can find this under 'Configuration Properties/Advanced/Platform Toolset'.

The problem with CLang is that it is not 100% compatible with IntelliSense, so using it only for the final build is a good idea.