Page 1 of 1

Is 64bit

Posted: Tue Dec 02, 2014 5:05 pm
by danielheth
I'm creating a cross platform application and thus compiling on Windows, Mac, Linux 32bit and Linux 64bit. The windows and mac version is compiled as 32bit... and the only reason to have a linux 64bit is so i don't have to force my users to install 32bit libraries on their linux 64bit machines. Now onto my question...

In order to differentiate between my apps when i call for the version, i'm using compiler flags:

Code: Select all

CompilerIf #PB_Compiler_OS = #PB_OS_Windows
  vName = vName + "for Windows"
CompilerElseIf #PB_Compiler_OS = #PB_OS_Linux
  CompilerIf #PB_Processor_x64
    vName = vName + "for Linux 64bit"
  CompilerElse
    vName = vName + "for Linux 32bit"
  CompilerEndIf
CompilerElseIf #PB_Compiler_OS = #PB_OS_MacOS
  vName = vName + "for Mac"
CompilerEndIf
The problem is if i run my 32bit linux version on a system with a 64bit processor, it identifies as a 64bit... Is there a different flag or way to tell if my app is compiled as 32bit or 64bit at runtime?

Re: Is 64bit

Posted: Tue Dec 02, 2014 5:09 pm
by danielheth
Found my answer in another thread...http://www.forums.purebasic.com/english ... 19&t=58314

Code: Select all

    CompilerIf #PB_Compiler_OS = #PB_OS_Windows
      vName = vName + "for Windows"
    CompilerElseIf #PB_Compiler_OS = #PB_OS_Linux
      CompilerIf #PB_Compiler_Processor = #PB_Processor_x86
        vName = vName + "for Linux 32bit"
      CompilerElse
        vName = vName + "for Linux 64bit"
      CompilerEndIf
    CompilerElseIf #PB_Compiler_OS = #PB_OS_MacOS
      vName = vName + "for Mac"
    CompilerEndIf

Re: Is 64bit

Posted: Thu Dec 11, 2014 8:59 pm
by luis
danielheth wrote: The problem is if i run my 32bit linux version on a system with a 64bit processor, it identifies as a 64bit
To clarify the reason behind it:

#PB_Compiler_Processor is set to 2 on x86 and to 4 on x64.
#PB_Processor_x86 is always set to 2.
#PB_Processor_x64 is always set to 4.

#PB_Compiler_Processor is intended to be compared to #PB_Processor_x86 or #PB_Processor_x64.

You wrote

Code: Select all

  CompilerIf #PB_Processor_x64
    vName = vName + "for Linux 64bit"
  CompilerElse
    vName = vName + "for Linux 32bit"
  CompilerEndIf


which in turn means

Code: Select all

   CompilerIf 4
    vName = vName + "for Linux 64bit"
  CompilerElse
    vName = vName + "for Linux 32bit"
  CompilerEndIf
4 is #True, so it was compiling the first code branch independently from the architecture you compiled the program on.


But for some reason you used the right approach for the OS instead ... :)

Code: Select all

CompilerIf #PB_Compiler_OS = #PB_OS_Windows