Const and If TargetWindows Then

Hi, I have this code:

If TargetWindows Then
Const kCFITSIO = “cfitsio.dll”
ElseIf TargetLinux Then
Const kCFITSIO = “libcfitsio.so”
ElseIf TargetMacOS Then
Const kCFITSIO = “libcfitsio.dylib”
End If

and then I’m calling a function from within the sharedlib/dll like this:

Soft Declare Function ffopen Lib kCFITSIO (ByRef fptr As Ptr, filename As CString, mode As Int32, ByRef status As Int32) As Int32

XOJO won’t compile this telling me that the const kCFITSIO is the wrong type expected.

If I ignore the If Target loop and just declare
Const kCFITSIO = “cfitsio.dll”
directly for each platform, it’s fine..

Why won’t this compile as a single codebase (because I have to each build individually otherwise)?
Thanks hivemind!
Jason.

 #If TargetWindows Then

    Const kCFITSIO = “cfitsio.dll”

#ElseIf  TargetLinux Then

    Const kCFITSIO = “libcfitsio.so”

#ElseIf TargetMacOS Then

    Const kCFITSIO = “libcfitsio.dylib”

#EndIf 
1 Like

Because the IF needs # to be a conditional compilation, as shown by Brian:

2 Likes

Thanks both. It’s my first time trying to get a multiplatform build, so I’ve not come across that syntax before.
That was a remarkably simple solution and serves me right for not RTM enough!
Cheers,
Jason.

@Jason_Hyde
:+1:

Thanks also @AlbertoD , including the Docs helps to study the material

1 Like

If you add a String constant to a module, you can use the IDE to define what should be used for each OS:

6 Likes