Conditional compilation

General FreeBASIC programming questions.
Post Reply
3oheicrw
Posts: 25
Joined: Mar 21, 2022 6:41

Conditional compilation

Post by 3oheicrw »

This piece of code: https://github.com/3oheicrw/SGL-FreeBAS ... l_test.bas

Currently I hard coded it to link with "sgl64". I want something like this:

if 32 bit windows then link with "sgl32"
if 64 bit windows then link with "sgl64"
else error not supported

Please help.
srvaldez
Posts: 3379
Joined: Sep 25, 2005 21:54

Re: Conditional compilation

Post by srvaldez »

in the FB help file search for __FB and you will get helpful information, for example

Code: Select all

#ifdef __FB_64BIT__
  '...instructions for 64bit OSes...
#else
  '...instructions for other OSes
#endif 
3oheicrw
Posts: 25
Joined: Mar 21, 2022 6:41

Re: Conditional compilation

Post by 3oheicrw »

I come up with something crazy like this. Hope someone could help me to optimize/simplify it.

Code: Select all

#ifdef __FB_WIN32__
   #ifdef __FB_X86__
      #ifdef __FB_64BIT__
         #inclib "sgl64"
      #else
         #inclib "sgl32"
      #endif
   #else
      #error Unsupported architecture
   #endif
#else
   #error Unsupported OS
#endif
Xusinboy Bekchanov
Posts: 789
Joined: Jul 26, 2018 18:28

Re: Conditional compilation

Post by Xusinboy Bekchanov »

3oheicrw wrote: Apr 04, 2022 3:54 I come up with something crazy like this. Hope someone could help me to optimize/simplify it.
So:

Code: Select all

#ifdef __FB_WIN32__
      #ifdef __FB_64BIT__
         #inclib "sgl64"
      #else
         #inclib "sgl32"
      #endif
#else
   #error Unsupported OS
#endif
3oheicrw
Posts: 25
Joined: Mar 21, 2022 6:41

Re: Conditional compilation

Post by 3oheicrw »

Xusinboy Bekchanov wrote: Apr 04, 2022 3:57
3oheicrw wrote: Apr 04, 2022 3:54 I come up with something crazy like this. Hope someone could help me to optimize/simplify it.
So:

Code: Select all

#ifdef __FB_WIN32__
      #ifdef __FB_64BIT__
         #inclib "sgl64"
      #else
         #inclib "sgl32"
      #endif
#else
   #error Unsupported OS
#endif
Is it enough? Windows now supports ARM too. __FB_64BIT__ only tells you it's 64 bit or not but it's not equivalent to x86_64, it could be arm64.
Xusinboy Bekchanov
Posts: 789
Joined: Jul 26, 2018 18:28

Re: Conditional compilation

Post by Xusinboy Bekchanov »

3oheicrw wrote: Apr 04, 2022 4:35 Is it enough? Windows now supports ARM too. __FB_64BIT__ only tells you it's 64 bit or not but it's not equivalent to x86_64, it could be arm64.
You can use your variant. I haven't heard this before.
marcov
Posts: 3462
Joined: Jun 16, 2005 9:45
Location: Netherlands
Contact:

Re: Conditional compilation

Post by marcov »

In general, only use the ELSE clause for the errors, never assume anything about the ELSE clause.
Name all other ones explicitly.

Code like above only inspires people to write a 16-bit port.
Post Reply