Author Topic: [SOLVED]How to define different custom compilers for 64bit only?  (Read 4100 times)

Offline cacb

  • Lives here!
  • ****
  • Posts: 536
[SOLVED]How to define different custom compilers for 64bit only?
« on: December 17, 2015, 03:17:15 pm »
I have a C++ library (not written by me) to be compiled using the MSVC compiler and which needs an *.asm file to be compiled when using the 64bit toolchain, but not when using the 32bit toolchain.

I have been able to define a C::B custom compiler that works for *.asm when compiling in 64bit mode (see attachment). However it also runs if I compile in 32bit mode, and I wonder if there is a way to prevent that happening as it causes conflicts in linking.

The way I control 32bit vs 64bit is by using C::B global variables to define the Toolchain search paths. Could I make it work by defining a TOOLCHAIN.ASM field and set it to ml64.exe for the 64bit case and something that does nothing in the 32bit case? Are the advanced compiler options able to understand user defined global variables? Or is there a better way?

Platform: Win7 C::B svn 10376
« Last Edit: December 19, 2015, 11:35:00 pm by cacb »

Offline scarphin

  • Lives here!
  • ****
  • Posts: 644
Re: How to define different custom compilers for 64bit only?
« Reply #1 on: December 19, 2015, 02:22:03 am »
Maybe you can define 2 different compilers (1 for 32bit, 1 for 64bit) and assign your targets with the corresponding compiler.

Offline cacb

  • Lives here!
  • ****
  • Posts: 536
Re: How to define different custom compilers for 64bit only?
« Reply #2 on: December 19, 2015, 03:49:54 pm »
Maybe you can define 2 different compilers (1 for 32bit, 1 for 64bit) and assign your targets with the corresponding compiler.

I don't differentiate between 32bit and 64bit targets explicitly in the project files. Instead I have global variable sets that are defined for 32bit and 64 bit toolchains. So switching between 64bit and 32bit is simply done just by selection the current global variable set and then recompile.

In this particular case, the *.asm file is to be compiled only for the 64bit case, not for the 32bit case. I will try my original idea and see if it works.

Offline cacb

  • Lives here!
  • ****
  • Posts: 536
Re: How to define different custom compilers for 64bit only?
« Reply #3 on: December 19, 2015, 07:00:00 pm »
I have tried various things and I cannot make it work. I can make it work for either 64 or 32 bit but not for both. The problem seems to be that
- in the 64bit case the *.asm file MUST be assembled using asm64.exe and the *.obj included in the static lib
- in the 32bit case the *.asm file MUST be excluded

Is there some way to conditionally compile/link a project file, based on the value of a global variable? Ideas welcome.

Offline MortenMacFly

  • Administrator
  • Lives here!
  • *****
  • Posts: 9694
Re: How to define different custom compilers for 64bit only?
« Reply #4 on: December 19, 2015, 07:13:52 pm »
Is there some way to conditionally compile/link a project file, based on the value of a global variable? Ideas welcome.
Why make it so complicated? Make 2 targets in the project, one for 64, one for 32 bit. Setup different compilers for them, then assign the files to be compiled as needed. Thus,. for the 32 bit exclude the ASM files, for 64 bit don't.
Compiler logging: Settings->Compiler & Debugger->tab "Other"->Compiler logging="Full command line"
C::B Manual: https://www.codeblocks.org/docs/main_codeblocks_en.html
C::B FAQ: https://wiki.codeblocks.org/index.php?title=FAQ

Offline cacb

  • Lives here!
  • ****
  • Posts: 536
Re: How to define different custom compilers for 64bit only?
« Reply #5 on: December 19, 2015, 08:15:31 pm »
Why make it so complicated? Make 2 targets in the project, one for 64, one for 32 bit. Setup different compilers for them, then assign the files to be compiled as needed. Thus,. for the 32 bit exclude the ASM files, for 64 bit don't.

Because it would break my existing setup. I was hoping to include this project into an existing workspace with 15-20 existing projects configured as explained. They can all be built together in debug or release (I have targets for that) in 64/32bit mode (controlled via global variables).

If I can't do a conditional compile, I may have to do what you suggest, but then I need to keep it in a different workspace so as to not mess up the existing builds. But it would be nice it it could be avoided.

Could virtual targets somehow be a solution? I haven't used them and I am not sure what they are for.

Offline cacb

  • Lives here!
  • ****
  • Posts: 536
Re: How to define different custom compilers for 64bit only?
« Reply #6 on: December 19, 2015, 11:17:50 pm »
Well, I found a solution that works and which does not break my configuration. Perhaps you think it is too complicated, but I think it simplifies things as the new project fits in my system. Here's what i did:

First, I wrote a very simple dummy compiler that understands the same command line parameters as ml64.exe in MSVC, i.e. like this:
ml64.exe  /c /nologo /W3 /Zi  /Fo$object $file
The /Fo option defines the required output object file (shown here with C::B  variables $object and $file). The dummy compiler simply creates a c++ file containing a dummy function and compiles it to the actual target object file name using the current c++ compiler (cl.exe). Then the linker and build system is happy.

Second, I defined a custom command to build the problem *.asm file, see attachment. The custom command refers to a global variable which takes different values for 32bit and 64bit. In the 64bit case it is obviously set to ml64.exe, and in the 32bit case it runs the dummy compiler.

Problem solved.


Offline MortenMacFly

  • Administrator
  • Lives here!
  • *****
  • Posts: 9694
Re: How to define different custom compilers for 64bit only?
« Reply #7 on: December 20, 2015, 10:41:23 am »
Problem solved.
Ok, good to know. Under this circumstances it seems a good solution.
Compiler logging: Settings->Compiler & Debugger->tab "Other"->Compiler logging="Full command line"
C::B Manual: https://www.codeblocks.org/docs/main_codeblocks_en.html
C::B FAQ: https://wiki.codeblocks.org/index.php?title=FAQ

Offline cacb

  • Lives here!
  • ****
  • Posts: 536
Re: How to define different custom compilers for 64bit only?
« Reply #8 on: December 20, 2015, 09:38:58 pm »
Ok, good to know. Under this circumstances it seems a good solution.

I have been using it today and it does the job just fine. If anyone needs something similar in C::B, I have attached the complete dummy compiler code code as a zip file. As it stands it is MSVC dependent, but can be adapted to other needs easily.