Cannot find Oracle::OCI when using statically built Qt
-
I built and installed a statically built Qt to
/opt/qt-static
, then referring to https://doc.qt.io/qt-6/sql-driver.html#how-to-build-the-oci-plugin-on-unix-and-macos I want to use QOCI Oracle SQL driver in my app. I successfully built thelibqsqloci.a
inbuild-sqldrivers/plugins/sqldrivers
and installed to/opt/qt-static
by/opt/qt-static/bin/qt-cmake -G Ninja ~/qt-everywhere-src-6.8.1/qtbase/src/plugins/sqldrivers -DCMAKE_INSTALL_PREFIX=/opt/qt-static -DOracle_ROOT=/home/yihua/app/yihua/product/21.0.0/client_1 -DQT_GENERATE_SBOM=OFF
However, when I cmake configure my qt app, it shows error:
[cmake] -- Configuring done
[cmake] CMake Error at /opt/qt-static/lib/cmake/Qt6Core/Qt6CoreMacros.cmake:695 (add_executable):
[cmake] Target "MyApp" links to target "Oracle::OCI" but the target was not
[cmake] found. Perhaps a find_package() call is missing for an IMPORTED target, or
[cmake] an ALIAS target is missing?
[cmake] Call Stack (most recent call first):
[cmake] /opt/qt-static/lib/cmake/Qt6Core/Qt6CoreMacros.cmake:646 (_qt_internal_create_executable)
[cmake] /opt/qt-static/lib/cmake/Qt6Core/Qt6CoreMacros.cmake:945 (qt6_add_executable)
[cmake] CMakeLists.txt:69 (qt_add_executable)I checked that there is
libqsqloci.a
under/opt/qt-static/plugins/sqldrivers
. Why MyApp still cannot find Oracle::OCI? -
Hi,
How are you linking the static plugin ?
-
Originally using qt-static the project can be successfully built, just problematic when running MyApp that shows errors "QOCI driver not available." QSqlDatabase: QOCI driver not loaded; however, after I install libqsqloci.a to qt-static, the CMake configure fails as shown above
My CMakeLists.txt includes
find_package(Qt6 6.8 REQUIRED COMPONENTS Charts Core Gui Qml Quick Sql) qt_add_executable(MyApp WIN32 MACOSX_BUNDLE) target_link_libraries(MyApp PRIVATE Qt6::Charts Qt6::Core Qt6::Gui Qt6::Qml Qt6::Quick Qt6::Sql QXlsx::QXlsx )
-
Additionally, after generating done, CMake error is:
[cmake] -- Generating done [cmake] CMake Error: [cmake] Running [cmake] [cmake] '/usr/bin/ninja' '-C' '/home/yihua/MyApp/build/Desktop_Qt_6_8_1-Debug' '-t' 'recompact' [cmake] [cmake] failed with: [cmake] [cmake] ninja: error: build.ninja:35: loading 'CMakeFiles/rules.ninja': No such file or directory [cmake] [cmake] include CMakeFiles/rules.ninja [cmake] [cmake] ^ near here [cmake] [cmake] [cmake] [cmake] CMake Generate step failed. Build files cannot be regenerated correctly.
-
Please provide minimal
CMakelists.txt
that shows this behaviour. -
@SGaist This is my minimal CMakeLists.txt:
cmake_minimum_required(VERSION 3.22) option(LINK_INSIGHT "Link Qt Insight Tracker library" ON) option(BUILD_QDS_COMPONENTS "Build design studio components" ON) option(BUILD_TESTS "Enable building tests" OFF) project(MyApp VERSION 1.0.0 DESCRIPTION "..." HOMEPAGE_URL "..." LANGUAGES CXX) find_package(Qt6 6.8 REQUIRED COMPONENTS Charts Core Gui Qml Quick Sql) set(CMAKE_AUTOMOC ON) set(CMAKE_AUTOUIC ON) set(CMAKE_AUTORCC ON) find_package(Boost 1.83.0 REQUIRED) include_directories(${Boost_INCLUDE_DIRS}) include_directories(src) include_directories(src/material) include_directories(src/sql) if (Qt6_VERSION VERSION_GREATER_EQUAL 6.8) qt_standard_project_setup(REQUIRES 6.8) endif() qt_add_executable(MyApp WIN32 MACOSX_BUNDLE) qt_add_resources(MyApp "configuration" PREFIX "/" FILES qtquickcontrols2.conf ) add_subdirectory(src) include_directories(${ORACLE_INCLUDE_DIR}) include(FetchContent) FetchContent_Declare( QXlsx GIT_REPOSITORY https://github.com/QtExcel/QXlsx.git GIT_TAG v1.4.8 SOURCE_SUBDIR QXlsx ) FetchContent_MakeAvailable(QXlsx) set_target_properties(MyApp PROPERTIES MACOSX_BUNDLE_BUNDLE_VERSION ${PROJECT_VERSION} MACOSX_BUNDLE_SHORT_VERSION_STRING ${PROJECT_VERSION_MAJOR}.${PROJECT_VERSION_MINOR} MACOSX_BUNDLE TRUE WIN32_EXECUTABLE TRUE ) target_link_libraries(MyApp PRIVATE Qt6::Charts Qt6::Core Qt6::Gui Qt6::Qml Qt6::Quick Qt6::Sql QXlsx::QXlsx ) include(GNUInstallDirs) install(TARGETS MyApp BUNDLE DESTINATION . LIBRARY DESTINATION ${CMAKE_INSTALL_LIBDIR} RUNTIME DESTINATION ${CMAKE_INSTALL_BINDIR} ) if (BUILD_QDS_COMPONENTS) include(${CMAKE_CURRENT_SOURCE_DIR}/qmlcomponents) endif() include(${CMAKE_CURRENT_SOURCE_DIR}/qmlmodules) if (LINK_INSIGHT) include(${CMAKE_CURRENT_SOURCE_DIR}/insight) endif () set(QML_IMPORT_PATH ${PROJECT_BINARY_DIR}/qml CACHE PATH "Path to the custom QML components defined by the project") qt_generate_deploy_qml_app_script( TARGET MyApp OUTPUT_SCRIPT deploy_script MACOS_BUNDLE_POST_BUILD NO_UNSUPPORTED_PLATFORM_ERROR DEPLOY_USER_QML_MODULES_ON_UNSUPPORTED_PLATFORM ) install(SCRIPT ${deploy_script})
-
That's not exactly minimal.
If you want to debug that issue you should start with something really minimal that only uses the SQL module to ensure that nothing else is interfering and then add things gradually back.
-
That's not exactly minimal.
If you want to debug that issue you should start with something really minimal that only uses the SQL module to ensure that nothing else is interfering and then add things gradually back.
@SGaist Hi, the following CMakeLists.txt is minimal, just add sql module in find_package() and target_link_libraries() based on the default CMakeLists.txt template of Qt Creator
cmake_minimum_required(VERSION 3.16) project(QtTest VERSION 0.1 LANGUAGES CXX) set(CMAKE_CXX_STANDARD_REQUIRED ON) find_package(Qt6 6.5 REQUIRED COMPONENTS Quick Sql) qt_standard_project_setup(REQUIRES 6.5) qt_add_executable(appQtTest main.cpp ) qt_add_qml_module(appQtTest URI QtTest VERSION 1.0 QML_FILES Main.qml ) # Qt for iOS sets MACOSX_BUNDLE_GUI_IDENTIFIER automatically since Qt 6.1. # If you are developing for iOS or macOS you should consider setting an # explicit, fixed bundle identifier manually though. set_target_properties(appQtTest PROPERTIES # MACOSX_BUNDLE_GUI_IDENTIFIER com.example.appQtTest MACOSX_BUNDLE_BUNDLE_VERSION ${PROJECT_VERSION} MACOSX_BUNDLE_SHORT_VERSION_STRING ${PROJECT_VERSION_MAJOR}.${PROJECT_VERSION_MINOR} MACOSX_BUNDLE TRUE WIN32_EXECUTABLE TRUE ) target_link_libraries(appQtTest PRIVATE Qt6::Quick Qt6::Sql ) include(GNUInstallDirs) install(TARGETS appQtTest BUNDLE DESTINATION . LIBRARY DESTINATION ${CMAKE_INSTALL_LIBDIR} RUNTIME DESTINATION ${CMAKE_INSTALL_BINDIR} )