Author Topic: Proper setup of newer MSVC compiler  (Read 2330 times)

Offline vid512

  • Multiple posting newcomer
  • *
  • Posts: 36
Proper setup of newer MSVC compiler
« on: November 01, 2021, 12:07:14 pm »
I am trying to use CodeBlocks (version 20.03 from 14th March 2020) with newer Microsoft Visual C/C++ compiler, and encountered several problems:

1. Under Settings->Compiler, I have created new compiler "Microsoft Visual C++ 2019" and set it as default compiler. I couldn't set 'Compiler installation directory', because C::B assumes all executables must be in 'bin' subdirectory of this path. This assumption is incorrect with newer MSVC compilers (for many years already, IIRC). Instead, I had to leave 'Compiler installation directory' empty, and add directories where required binaries are located to 'Additional paths'. Building with this compiler now works correctly.

My problem is that when starting CodeBlocks, I always get the "Compiler auto-detection" dialog, where it says that the default compiler "Microsoft Visual C++ 2019" is "not found". It says that "at least one compiler master path is empty and therefor invalid". Looks like the "Compiler auto-detection" dialog only considers "Compiler installation directory" and not "Addtitional paths"?

2. With every build using this compiler, I keep getting "Enviromental error" message "Can't find compiler executable in your seach path's for GNU GCC compiler". But I am not using GCC at all (my project does have targets for GCC compiler, but I am not building those).

So, how do I correctly set up newer MSVC in CodeBlocks? Can it be done without workarounds (like installing GCC just to shut up an invalid warning, or creating fake compiler directory with 'bin' subdirectories)?

Online sodev

  • Regular
  • ***
  • Posts: 452
Re: Proper setup of newer MSVC compiler
« Reply #1 on: November 01, 2021, 03:19:52 pm »
Use a valid directory for the compilers installation directory that does no harm. I use C:\Program Files (x86)\Microsoft Visual Studio\2019\Community\VC, this used to contain a bin directory with the compilers in the past, but now such directory doesn't exist, but CodeBlocks is happy with that directory. Make sure that all binaries on the Program Files tab are defined (no debugger is ok though).

About that environment error, are you sure that you are not building GCC targets? I don't get such error messages, the only message i can see in the logs is about an invalid debugger.

Offline vid512

  • Multiple posting newcomer
  • *
  • Posts: 36
Re: Proper setup of newer MSVC compiler
« Reply #2 on: November 01, 2021, 04:27:03 pm »
Using valid directory as a fake "compiler installation directory" helped with the initial "Compiler auto-detection". Thank you.

I would still consider this a sort-of workaround, though. Shouldn't this assumption about "bin" subdirectory, "compiler master directory", etc., be considered a CodeBlocks flaw, reported to devs somewhere, and fixed?

As for the GCC error, I dug deeper and found out what's the problem. In the .cbp project file, there is some sort of compiler setting for entire project, not just for each target. In my case it looks like this:
Code
<CodeBlocks_project_file>
<FileVersion major="1" minor="6" />
<Project>
<Option title="..." />
<Option compiler="gcc" />       <------ This line
<Build>
<Target title="wx31-gtk2-debug">
<Option platforms="Unix;" />
...
<Option compiler="gcc" />
...
</Target>
<Target title="wx31-gtk2-release">
<Option platforms="Unix;" />
...
<Option compiler="gcc" />
...
</Target>
<Target title="wx31-msw-debug">
<Option platforms="Windows;" />
...
<Option compiler="microsoft_visual_c_2019" />
...
</Target>
<Target title="wx31-msw-release">
<Option platforms="Windows;" />
...
<Option compiler="microsoft_visual_c_2019" />
...
</Target>
... etc ...

If I delete the line from project file, CodeBlocks puts it back there when I open the project. However, if I change the line to <Option compiler="microsoft_visual_c_2019"/>, then the error about missing GCC disappears.

I don't know what this line is supposed to mean, or how it can be edited via CodeBlocks GUI. Any idea what it is, and what to do about it?

Offline New Pagodi

  • Multiple posting newcomer
  • *
  • Posts: 38
Re: Proper setup of newer MSVC compiler
« Reply #3 on: November 01, 2021, 04:41:49 pm »
I wrote about how I use codeblocks with newer visual studio products in this thread.

Online sodev

  • Regular
  • ***
  • Posts: 452
Re: Proper setup of newer MSVC compiler
« Reply #4 on: November 01, 2021, 06:14:44 pm »
This might be the project global compiler, you can change that one by using Project | Build Options, select the root element of the tree and change its compiler.

Offline vid512

  • Multiple posting newcomer
  • *
  • Posts: 36
Re: Proper setup of newer MSVC compiler
« Reply #5 on: November 01, 2021, 07:49:55 pm »
Correct! Changing the "project global compiler" to *No Compiler*  (or "null" in .cbp file) solved the annoying GCC error. Thanks again.

What is the purpose of this "project global compiler" anyway? When is it used? I can't find any way to inherit this in any of targets, every target seems to need its own compiler set.

BTW, what's the current state of debugging MSVC-compiled code? I remember it was basically unsupported few years ago, and so far failed to make CDB work properly. Is there any trick, like using some MSVC-compatible debugger with GDB-like syntax, or anything?