Error in #include <sal/main.h> when including in a c++ header

Hello to everyone

I’m working on a project to read/write to LibreOffice calc sheets in a c++ application. The code I’m writing include the line #include <sal/main.h>
In order to get the component context and so on to read/write to the .ods files.

I’m using Fedora Linux 34 with gnome 40 Wayland and code::blocks 20.03. In the project I used the paths /usr/lib64/libreoffice/sdk/include and /usr/lib64/libreoffice/sdk/lib for the headers and libraries respectively. When I try to compile, the project which has nothing more than the include lines, the compiler throws an error saying that there is an error in the types.h header in the line where #if defined(_MSC_VER) evaluates to false.

How to overcome this if I’m using Linux? I installed the SDK in a Linux distro so why the SDK gives this error checking the platform?

Thanks you in advance for the help.

Please state exact error message instead of just saying “compiler throws an error”. You probably saw

/usr/lib64/libreoffice/sdk/include/sal/types.h:264:5: error: #error ("unknown platform")

Make sure that in your shell you sourced the SDK setup, i.e.

source /usr/lib64/libreoffice/sdk/setsdkenv_unix.sh

and on the compiler command line define the LINUX preprocessor macro to indicate the platform (see /usr/lib64/libreoffice/sdk/include/sal/config.h for possible values), so the command line should be

g++ -I${OO_SDK_HOME}/include -DLINUX yoursource.cxx

However, you get that and more automatically (still with setsdkenv_unix.sh sourced) if you adapt a skeleton makefile and set the PRJ variable to the OO_SDK_HOME directory and include settings.mk and std.mk, see this SDK example, i.e.

PRJ=$(OO_SDK_HOME)
SETTINGS=$(PRJ)/settings
include $(SETTINGS)/settings.mk
include $(SETTINGS)/std.mk

And then use the example makefile rule that provides, among others, $(CC_INCLUDES) and $(CC_DEFINES) to build your source. Using that all output files go under the environment’s ${OO_SDK_OUT} directory to $(OO_SDK_OUT)/$(OS)example.out subdirectories, see /usr/lib64/libreoffice/sdk/settings/std.mk

Your solution defining the LINUX preprocessor macro works and solve the problem…thank you for the help.