Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Can't build with Qt 6.8.1 #174

Closed
perdrix52 opened this issue Dec 7, 2024 · 10 comments
Closed

Can't build with Qt 6.8.1 #174

perdrix52 opened this issue Dec 7, 2024 · 10 comments

Comments

@perdrix52
Copy link

perdrix52 commented Dec 7, 2024

Get this error:

CMake Error at CMakeLists.txt:3 (qt_add_library):
  Unknown CMake command "qt_add_library".

command used was:

cmake -B ../build -G Ninja -DQT_VERSION_MAJOR=6 -DCMAKE_INSTALL_PREFIX:STRING="/usr/local" -DCMAKE_MODULE_PATH:STRING="/usr/share/cmake-3.28/Modules" -D CMAKE_PREFIX_PATH:STRING="/opt/Qt/6.8.1/gcc_64"

PS I'd still greatly appreciate being able to build this as a static library. If I can find the time would you accept a pull request to allow that?

Cheers, David

@perdrix52
Copy link
Author

perdrix52 commented Dec 7, 2024

Arrgh trying to build using a set of instructions assuming the top level CMakeLists.txt file is in src dir, whereas it is NOW in the to level dir (since 3 days ago).

Still would like to know if you will accept a pull request.

@perdrix52 perdrix52 reopened this Dec 7, 2024
@attila-tokes
Copy link
Collaborator

attila-tokes commented Dec 9, 2024

Hi @perdrix52! 🙂 What is your use case for which static linking would work better?

The library is licensed under LGPL, so building it as a static library could just cause unnecessary licensing issues, while providing little or no benefits over dynamic linking.

@perdrix52
Copy link
Author

We have a lot of dependencies that we link statically, and that's much simpler to handle than shipping .so files in our installation and therefore having to handle issues with libpath etc..

D.

@perdrix52
Copy link
Author

The other reason for static linking is this:
error while loading shared libraries: libQt6Network.so.6: cannot open shared object file: No such file or directory

If I disable the calls to stuff in SmptMime.so and link the code it works. But if I enable the calls and rebuild I get the above error.

Do you know how to solve that?

@perdrix52
Copy link
Author

BTW I think there's an error in your CMakeLists.txt: It says:
set(CMAKE_INSTALL_RPATH “${ORIGIN}”)
but I think it should say:
set(CMAKE_INSTALL_RPATH "$ORIGIN")
See: https://discourse.cmake.org/t/help-with-shared-libraries-on-linux/13203

@perdrix52
Copy link
Author

I found out why the library isn't built with RPATH/RUNPATH set to $ORIGIN.

  1. It should be set(CMAKE_INSTALL_RPATH $ORIGIN)
  2. You should set this and the other related variables in the TOP level CMake file, not in the lower level files and they should be set before any targets are defined. Also remove them from the lower level CMake files.

See Craig Scott's (*) comments in the CMake discourse thread referenced in my previous comment.

So the top level CMakeList.txt should read:

cmake_minimum_required(VERSION 3.16)

project(SmtpMime
  VERSION 2.0
  LANGUAGES C CXX)

option(BUILD_TESTS "builds tests" ON)
option(BUILD_DEMOS "builds demos" ON)

set(CMAKE_CXX_STANDARD 17)
set(CMAKE_CXX_STANDARD_REQUIRED ON)
set(CMAKE_AUTOUIC OFF)
set(CMAKE_AUTOMOC ON)
set(CMAKE_AUTORCC OFF)

find_package(QT NAMES Qt6 COMPONENTS Core Network Test REQUIRED)
find_package(Qt${QT_VERSION_MAJOR} COMPONENTS Core Network Test REQUIRED)

set(LIBRARY_TARGET_NAME ${PROJECT_NAME})

message(USING Qt${QT_VERSION_MAJOR})

set(CMAKE_SKIP_BUILD_RPATH FALSE)
set(CMAKE_BUILD_WITH_INSTALL_RPATH TRUE)
set(CMAKE_INSTALL_RPATH $ORIGIN)

add_subdirectory(src)

if (BUILD_TESTS)
  add_subdirectory(test)
endif()

if (BUILD_DEMOS)
  add_subdirectory(demos)
endif()

With those changes the library is built correctly with $ORIGIN set in RUNPATH

(*) Craig Scott - author of Professional CMake.

@perdrix52
Copy link
Author

Do you want me to fork the project and create a PR for this or will you apply the changes yourself?

Thanks, David

@EgorWeders
Copy link
Contributor

EgorWeders commented Dec 23, 2024

The other reason for static linking is this: error while loading shared libraries: libQt6Network.so.6: cannot open shared object file: No such file or directory

If I disable the calls to stuff in SmptMime.so and link the code it works. But if I enable the calls and rebuild I get the above error.

Do you know how to solve that?

You need to find and link the Qt "Network" package to your project in a subdirectory (also put the .so next to the release executable). Because the .so calls to other libraries depend on your linking. Also try clearing the cmake cache.
Another problem might be that you built SmptMime.so with a different qt kit (or cmake config) than your project (Debug Release mix).

P.S. Just trying to help with the same error we encountered once

@perdrix52
Copy link
Author

That wasn't the problem - the problem was the cmake files and r(un)path settings.

bluetiger9 pushed a commit that referenced this issue Jan 15, 2025
@bluetiger9
Copy link
Owner

Fixed. Thx!

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

No branches or pull requests

4 participants