Author Topic: Project options ignored, default compiler options used instead  (Read 1728 times)

giocc

  • Guest
A very simple test program  (main.cpp plus a testClass.cpp and .h) has some compiler options set (e.g. -g and -m32)
in [project]/Properties/Project's build options.../Compiler settings (for both Debug/Release targets);
option "Policy" is "Use project options only" (for both compiler and linker).

However, when compiling, these settings are ignored and the general compiler settings are used regardless:
Code
-------------- Build: Debug in testAssign-MinGW32 (compiler: GNU GCC Compiler)---------------

mingw32-g++.exe   -c D:\CTest\testAssign\src\main.cpp -o build\obj\Debug\src\main.o
mingw32-g++.exe   -c D:\CTest\testAssign\src\TermID.cpp -o build\obj\Debug\src\TermID.o
mingw32-g++.exe  -o build\bin\Debug\testAssign.exe build\obj\Debug\src\main.o build\obj\Debug\src\TermID.o   
Output file is build\bin\Debug\testAssign.exe with size 47.12 KB
Process terminated with status 0 (0 minute(s), 0 second(s))
0 error(s), 0 warning(s) (0 minute(s), 0 second(s))

As per the compile log, the compiler matches the setting in Settings/Compiler.../Selected compiler and compilation succeeds; changing compilation options there also works.

How can I set project-specific option overrides?

There is a ticket, #600 (https://sourceforge.net/p/codeblocks/tickets/600/) open basically for this same issue (since 2018!), but it seems to have gone stale. I also updated it with this same report.
Is it possible that nobody noticed this blatant issue since?

Offline stahta01

  • Lives here!
  • ****
  • Posts: 7582
    • My Best Post
Re: Project options ignored, default compiler options used instead
« Reply #1 on: March 18, 2023, 09:28:33 pm »
Your problem is not the same as the issue 600, in that one the person wanted the Global Compiler setting to be ignored!

Edit: You do understand the the word "general" does not mean "global" to most people; if you wish the Global Setting to not be used then you are likely out of luck. I suggest trying "use target only" setting and the other options to see if one does what you want.

Ignoring the Global Compiler settings is stupid in my opinion; so, I can understand why it was never changed to that way.

Tim S.
« Last Edit: March 18, 2023, 11:01:58 pm by stahta01 »
C Programmer working to learn more about C++ and Git.
On Windows 7 64 bit and Windows 10 64 bit.
--
When in doubt, read the CB WiKi FAQ. http://wiki.codeblocks.org

Offline gd_on

  • Lives here!
  • ****
  • Posts: 796
Re: Project options ignored, default compiler options used instead
« Reply #2 on: March 19, 2023, 10:25:53 am »
I have the feeling that your problem does not come from a bug in C::B but from a bad configuration or misundertstanding.
I verified thay on a simple hello program, it worked as it should.
You can set compiler options at 3 different places:
1) in the menu Settings/compiler
2) at the project level
3) at the target level
In 1), you set default options for your differents compilers. It's only there that you can configure their paths. Personaly, I don't set any options there, but you can. It's your choice. Options set here are always applied. It's not a bug, but set by design as suggested stahta01.
For 2) and 3) you can set them via a right click on your project name. In your case you have 2 targets (or sub-projects), Debug and Release.
Example for a simple hello program:
Hello
  |
  |-Debug
  |-Release
When you click on Hello, you have access to the project options. They are applied or not, depending on "policy" choice.
When you click on Debug or Release, you have access to the targets options.  They are applied or not, depending on "policy" choice.

If you want to use compile options -m32 and -g, you can set -m32 in the project options, but, normally, -g is only for the Debug target. Putting -g in project options is not useful, may be a nonsense, because in that case there are no differences between Release and Debug targets, so no reasons to distinguish them.
You can also set only target options:
   -m32 -g for the Debug target
   only -m32 for the release target
   the global project option is empty in that case.

You can choose in the policy tab how to use your settings. There are 4 choices:
- Use project options only. To my advice, this is not a very useful option (exept for testing or if you have only 1 target), because there are no differences between targets;
- Use target options only;
- Prepend target options to project options;
- Append target options to project options.

Apparently, you have used the first one. So, if it's empty (as I suppose, but I'm not on your PC), it's normal than you see only default options.
You can use the second one, or better the 3rd or 4th one. Difference between both, is the order of the options and how the compiler use them. In some cases, the result may be different, especially if options affect the same kind (for example optimisations -O, -O2, ... or the search libraries options -L if you have more than 1 search path).

Probably, your bug report on ticket 600 is not right and could be deleted. As I said at the top, I can't reproduce it. For me, it works as expected.

gd_on
« Last Edit: March 19, 2023, 03:38:55 pm by gd_on »
Windows 11 64 bits (23H2), svn C::B (last version or almost!), wxWidgets 3.2.4 (tests with 3.3), Msys2 Compilers 13.2.0, 64 bits (seh, posix : gcc, g++ and gfortran in C:\msys64\mingw64) or 32 bits (dwarf2, posix  in C:\msys64\mingw32).