Hello Fatih,
The reason that you did not receive many responses is that this is not
an officially supported way of building LibreOffice SDK examples, but
rather a proof of concept. I hope that I can submit patches and merge it
in the LibreOffice code repository soon.
You should also note that on Windows, the official tool for building
LibreOffice examples (and LibreOffice itself) is Visual Studio 2019 or
2022. With Visual Studio, you can build LibreOffice SDK examples using
cmake, with a slight change compared to the CMakeLists.txt that was
posted on the dev blog.
This is the LOROOT that I use, that refers to the LibreOffice folder
inside "C:\Program Files":
set(LOROOT C:/Progra~1/LibreOffice)
Other than that, you only need to change this part:
target_link_libraries(example
icppuhelper
ipurpenvhelper
icppu
isalhelper
isal
)
These are the names of .lib files that you can find in this folder:
C:\Program Files\LibreOffice\sdk\lib
For the definitions, WIN32 works, but LINUX also works for me.
add_definitions(-DWIN32)
For the cppumaker, the problem might be that you don't have the required
directories in your system path. Try adding these directories to the
Windows system path before opening Visual Studio or its command line:
C:\Program Files\LibreOffice\program
C:\Program Files\LibreOffice\sdk\bin
You should test cppumaker in the command prompt shown by selecting "x64
Native Tools Command Prompt for VS 2022" before invoking cmake. Then,
you should be able to see that two folders named "com" and "org" are
created for you after running cmake.
After opening the solution in Visual Studio, you can easily build and
run the project "example". The binary file "example.exe" should be built
and run fine, and work as intended.
The CMakeLists.txt that I have used is attached.
I have also tested MSYS2, but the best that I could achieve was getting
this error:
[2/2] Linking CXX executable example.exe
FAILED: example.exe
cmd.exe /C "cd . && C:\msys64\usr\bin\c++.exe
CMakeFiles/example.dir/main.cpp.obj -o example.exe
-Wl,--out-implib,libexample.dll.a
-Wl,--major-image-version,0,--minor-image-version,0
-LC:/Progra~1/LibreOffice/program -LC:/Progra~1/LibreOffice/sdk/lib
-licppuhelper -lipurpenvhelper -licppu -lisalhelper -lisal
-lkernel32 -luser32 -lgdi32 -lwinspool -lshell32 -lole32 -loleaut32
-luuid -lcomdlg32 -ladvapi32 && cd ."
/usr/lib/gcc/x86_64-pc-msys/11.3.0/../../../../x86_64-pc-msys/bin/ld:
CMakeFiles/example.dir/main.cpp.obj:main.cpp:(.text+0x36): undefined
reference to `cppu::bootstrap()'
collect2: error: ld returned 1 exit status
ninja: build stopped: subcommand failed.
Please note that I have used LINUX in the definitions, because otherwise
it is assumed that on WIN32, Visual Studio is used:
add_definitions(-DLINUX)
I think using Visual Studio for now would be the available option.
Regards,
Hossein
On 29.07.2022 05:58, Fatih Yegin wrote:
Doctor, is there any hope?
As an aside, here's how I setup my configuration:
1. Install LO and sdk to default installation paths*
2. Move them to "C:\"
3. Install msys, and don't forget to update the msys and msys mingw64
terminals with `pacman -Syu`**
4. (Optional) Make msys shortcuts on "USER_NAME\Desktop" (especially
mingw64 one)
5. Install cmake according to this link:
https://www.msys2.org/docs/cmake/
6. Run setupsdkenv<...>.batch, ideally from cmd***
7. Run msys's mingw64 environment from this terminal with `cmd /C ...`,
preferably from the desktop shortcut****
8. Configuration should be ready now.
While writing these, it gave me an idea by the way. I have never tried
to move the LO & sdk to msys root (C:\msys64\). In theory, if I setup
the environment variables correctly, I should be able to compile the
examples from msys & infer from their compile commands.
I can't try this rightaway, however I will try to send a follow up e-
mail when I have spare time.
Kind regards,
Fatih Yegin
*This is important as otherwise installation will break with bunch of
missing dll errors due to the ancient installer (My heartfelt apologies
for not mentioning earlier, it was completely out of my mind). The
reason I did this was to compile the examples, however it didn't work
out.
**For installation steps:
https://www.msys2.org/#installation
***For unix tools use "C:\msys64\usr\bin", "msys64" part can change
depending on your installation (This allows the execution of unix
commands as part of msys from cmd as well, beware!).
****This is also important. This way we can access the environment
variables we had set up before (e.g. "$OO_SDK_HOME"). You can see these
variables with `set` from msys.
On Tue, 2022-07-26 at 21:08 +0300, Fatih Yegin wrote:
I'm sorry, I have forgotten to mention that cmake doesn't generate
the
needed headers in Windows either. We must run the necessary cppumaker
command manually in the necessary directory.
Any ideas about how can solve these issues?
Thank you again, before hand.
On Tue, 2022-07-26 at 15:52 +0300, Fatih Yegin wrote:
> Hello,
>
> I am experimenting with LO SDK and using cmake to compile according
> to
> this page:
> https://dev.blog.documentfoundation.org/2022/04/19/using-cmake-to-build-libreoffice-cpp-sdk-examples/
>
> This works great on Linux.
>
> However, I am having build errors on Windows.
>
> I believe, root cause of this problem is unkown platform error from
> sal
> library. Yet, I can't solve this even though I explicitly specify
> the
> OS within compile commands.
>
> I have added these errors briefly on the attachements in
> Build_errors.txt with the addition of CMakeLists.txt file and
> compile_commands.json file.
>
> For the build environment, I use MSYS's MINGW64 environment
> (additional
> info can be found at: https://www.msys2.org/docs/environments/).
>
> I can share my configuration steps with a secondary e-mail if
> needed.
>
> Thank you.
>
> Best Regards,
> Fatih Yeğin
>
--
Hossein Nourikhah, Ph.D.
Developer Community Architect
The Document Foundation (TDF)
Email: hossein@xxxxxxxxxxxxxxx
Wiki: https://wiki.documentfoundation.org/User:Hossein
IRC: hossein at libreoffice-dev room in LiberaChat Network
irc://irc.libera.chat/#libreoffice-dev
cmake_minimum_required(VERSION 3.5)
project(example LANGUAGES CXX)
set(CMAKE_CXX_STANDARD 17)
set(CMAKE_CXX_STANDARD_REQUIRED ON)
set(LOROOT C:/Progra~1/LibreOffice)
add_executable(example main.cpp)
SET(CMAKE_INCLUDE_CURRENT_DIR ON)
include_directories(
${CMAKE_SOURCE_DIR}
${CMAKE_CURRENT_BINARY_DIR}/com/sun/star
${LOROOT}/sdk/include
)
target_link_directories(example PRIVATE
${LOROOT}/program
${LOROOT}/sdk/lib
)
target_link_libraries(example
icppuhelper
ipurpenvhelper
icppu
isalhelper
isal
)
add_definitions(-DWIN32)
execute_process(COMMAND ${LOROOT}/sdk/bin/cppumaker -Gc -O. ${LOROOT}/program/types.rdb ${LOROOT}/program/types/offapi.rdb)
hossein@WINDOWS MINGW64 ~/example/build
$ cmake ..
-- Configuring done
-- Generating done
-- Build files have been written to: C:/msys64/home/hossein/example/build
hossein@WINDOWS MINGW64 ~/example/build
$ ninja
[1/2] Building CXX object CMakeFiles/example.dir/main.cpp.obj
In file included from C:/msys64/home/hossein/example/build/com/sun/star/beans/PropertyVetoException.hpp:8,
from C:/msys64/home/hossein/example/build/com/sun/star/beans/XPropertySet.hpp:8,
from C:/msys64/home/hossein/example/main.cpp:24:
C:/msys64/home/hossein/example/build/com/sun/star/uno/Exception.hpp: In copy constructor â??com::sun::star::uno::Exception::Exception(const com::sun::star::uno::Exception&)â??:
C:/msys64/home/hossein/example/build/com/sun/star/uno/Exception.hpp:54:108: warning: visibility attribute not supported in this configuration; ignored [-Wattributes]
54 | Exception::Exception(Exception const & the_other): Message(the_other.Message), Context(the_other.Context) {}
| ^
C:/msys64/home/hossein/example/build/com/sun/star/uno/Exception.hpp: In destructor â??com::sun::star::uno::Exception::~Exception()â??:
C:/msys64/home/hossein/example/build/com/sun/star/uno/Exception.hpp:56:26: warning: visibility attribute not supported in this configuration; ignored [-Wattributes]
56 | Exception::~Exception() {}
| ^
[2/2] Linking CXX executable example.exe
FAILED: example.exe
cmd.exe /C "cd . && C:\msys64\usr\bin\c++.exe CMakeFiles/example.dir/main.cpp.obj -o example.exe -Wl,--out-implib,libexample.dll.a -Wl,--major-image-version,0,--minor-image-version,0 -LC:/Progra~1/LibreOffice/program -LC:/Progra~1/LibreOffice/sdk/lib -licppuhelper -lipurpenvhelper -licppu -lisalhelper -lisal -lkernel32 -luser32 -lgdi32 -lwinspool -lshell32 -lole32 -loleaut32 -luuid -lcomdlg32 -ladvapi32 && cd ."
/usr/lib/gcc/x86_64-pc-msys/11.3.0/../../../../x86_64-pc-msys/bin/ld: CMakeFiles/example.dir/main.cpp.obj:main.cpp:(.text+0x36): undefined reference to `cppu::bootstrap()'
collect2: error: ld returned 1 exit status
ninja: build stopped: subcommand failed.