如何使用定义SQLITE_ENABLE_LOAD_EXTENSION编译Qt 6.4.1的Sqlite插件

mw3dktmi  于 2022-12-29  发布在  SQLite
关注(0)|答案(1)|浏览(305)

我正在尝试将我的应用升级到Qt版本6。为此,我需要编译MySql和Sqlite插件。Sqlite需要具有加载用户定义函数的功能,这是通过使用定义SQLITE_ENABLE_LOAD_EXTENSION编译Sqlite3来完成的
我发现该程序记录为here
我最初的方法是生成Sqlite插件来使用系统Sqlite库,我已经用SQLITE_ENABLE_LOAD_EXTENSION编译了该库。下面是我生成构建的命令:

qt-cmake -G "Unix Makefiles" ~/Qt/6.4.1/Src/qtbase/src/plugins/sqldrivers -DCMAKE_INSTALL_PREFIX=~/Qt/6.4.1 -DFEATURE_system_sqlite=ON -DCMAKE_INCLUDE_PATH=~/Projects/sqlite-amalgamation-3390300 -DCMAKE_LIBRARY_PATH=~/Projects/sqlite-amalgamation-3390300

不幸的是,构建插件失败:
艾伦@layout-pc2:~/Qt/6.4.1/源代码/构建-SQL驱动程序$cmake-构建。
[10%]目标QMYSQLDriverPlugin的自动MOC
[10%]构建目标QMYSQLDriverPlugin_autogen
合并编译器生成的目标QMYSQLDriverPlugin的依赖项
[50%]构建目标QMYSQLDriverPlugin
[60%]目标QSQLiteDriverPlugin的自动MOC
[60%]构建目标QSQLiteDriverPlugin_autogen
合并目标QSQLiteDriverPlugin的编译器生成依赖项
[70%]正在构建CXX对象sqlite/CMakeFiles/QSQLiteDriverPlugin. dir/QSQLiteDriverPlugin_autogen/mocs_compilation. cpp. o
[80%]正在构建CXX对象sqlite/CMakeFiles/QSQLite驱动程序插件目录/qsql_sqlite. cpp. o
[90%]构建CXX对象sqlite/CMakeFiles/QSQLiteDriverPlugin.目录/smain. cpp. o
[100%] Linking CXX shared module ../plugins/sqldrivers/libqsqlite.so /usr/bin/ld: CMakeFiles/QSQLiteDriverPlugin.dir/qsql_sqlite.cpp.o: in function QSQLiteResultPrivate::initColumns(bool)': /home/allen/Qt/6.4.1/Src/qtbase/src/plugins/sqldrivers/sqlite/qsql_sqlite.cpp:178: <br>undefined reference to sqlite3_column_table_name16'
collect2: error: ld returned 1 exit status gmake 2 :***[sqlite/CMakeFiles/QSQLiteDriverPlugin.dir/build.make:130: plugins/sqldrivers/libqsqlite.so] Error 1 gmake 1 :***[CMakeFiles/Makefile2:226: sqlite/CMakeFiles/QSQLiteDriverPlugin.dir/all] Error 2 gmake:***[Makefile:146: all] Error 2
我发现了关于此错误的帖子
I removed all occurrences of libsqlite3.so except the one I compiled but could not resolve the error. I then decided to go with the built in Sqlite plugin and changed my command to "-DFEATURE_system_sqlite=OFF" aftter removing CMakeCache.txt. This time I was able to build and install the plugins but my app failed when it could not install my user defined function.
然后,我研究了如何获得构建中包含的所需定义,并在sqlite的~/Qt/6.4.1/Src/qtbase/src/plugins/sqldrivers/sqlite/CMakeLists.txt中找到了构建的定义。我在定义列表中添加了定义SQLITE_ENABLE_LOAD_EXTENSION,并在另一个地方将其更改为SQLITE_OMIT_LOAD_EXTENSION。sqldrivers文件夹并运行我的configure命令,但即使构建成功,插件仍然失败,因为未配置加载扩展。
我到底做错了什么?
在检查输出时,我遇到了一个错误,大意是我使用的是"Unix MakeFiles"而不是"Ninja",我应该自己承担风险。所以,我决定从8.4.1的一个新副本开始我使用了以下命令:

./configure -sql-mysql -sql-sqlite -system-sqlite

我收到一个错误:

Configuring submodule 'qtbase'
  CMake Error: Error: generator : Ninja
  Does not match the generator used previously: Unix Makefiles
  Either remove the CMakeCache.txt file and CMakeFiles directory    or choose a different binary directory.

删除CMakeCache.txt文件和CMakeFiles目录没有解决这个问题,所以我拉了一个新的副本6.4.1和安装忍者:Install Ninja Build System on Ubuntu 22.04
我调出了6.4.1的一个新副本,再次运行配置。过了一会儿,配置结束了:

-- Configuring incomplete, errors occurred!
  See also "/home/allen/Qt/6.4.1/Src/CMakeFiles/CMakeOutput.log".
  See also "/home/allen/Qt/6.4.1/Src/CMakeFiles/CMakeError.log".
  CMake Error at qtbase/cmake/QtProcessConfigureArgs.cmake:965   (message):
    CMake exited with code 1.

然而,qtbase似乎已经配置好了,所以我将尝试使用sql驱动程序。
命令:

qt-cmake -G Ninja ~/Qt/6.4.1/Src/qtbase/src/plugins/sqldrivers -DCMAKE_INSTALL_PREFIX=~/Qt/6.4.1

退回

Qt Sql Drivers:
    DB2 (IBM) .............................. no
    InterBase .............................. no
    MySql .................................. yes
    OCI (Oracle) ........................... no
    ODBC ................................... no
    PostgreSQL ............................. no
    SQLite ................................. yes
      Using system provided SQLite ......... no

添加-DFeature_system_sqlite不起作用:

allen@layout-pc2:~/Qt/6.4.1/Src/build_sqldrivers$ qt-cmake -G Ninja ~/Qt/6.4.1/Src/qtbase/src/plugins/sqldrivers -DCMAKE_INSTALL_PREFIX=~/Qt/6.4.1 -DFEATURE_system_sqlite=YES

"system_sqlite"从"关闭"更改为"是"在/home/allen/Qt/6.4.1/gcc_64/lib/cmake/Qt6/QtSetup中生成警告。cmake:325(消息):

Re-configuring in existing build folder.  Some features will be
  re-evaluated automatically.
Call Stack (most recent call first):
  /home/allen/Qt/6.4.1/gcc_64/lib/cmake/Qt6BuildInternals/Qt6BuildInternalsConfig.cmake:237 (include)
  /home/allen/Qt/6.4.1/gcc_64/lib/cmake/Qt6BuildInternals/Qt6BuildInternalsConfig.cmake:333 (qt_build_internals_set_up_private_api)
  CMakeLists.txt:18 (qt_prepare_standalone_project)

CMake Warning at /home/allen/Qt/6.4.1/gcc_64/lib/cmake/Qt6/QtFeature.cmake:246 (message):
  Reset FEATURE_system_sqlite value to OFF, because it doesn't meet its
  condition after reconfiguration.
Call Stack (most recent call first):
  /home/allen/Qt/6.4.1/gcc_64/lib/cmake/Qt6/QtFeature.cmake:396 (qt_feature_check_and_save_user_provided_value)
  /home/allen/Qt/6.4.1/gcc_64/lib/cmake/Qt6/QtFeature.cmake:606 (qt_evaluate_feature)
  CMakeLists.txt:36 (qt_feature_module_end)
-- Configuration summary shown below. It has also been written to /home/allen/Qt/6.4.1/Src/build_sqldrivers/config.summary
-- Configure with --log-level=STATUS or higher to increase       CMake's message verbosity. The log level does not persist across reconfigurations.

-- Configure summary:

Qt Sql Drivers:
  DB2 (IBM) .............................. no
  InterBase .............................. no
  MySql .................................. yes
  OCI (Oracle) ........................... no
  ODBC ................................... no
  PostgreSQL ............................. no
  SQLite ................................. yes
    Using system provided SQLite ......... no

-- Configuring done
-- Generating done
-- Build files have been written to: /home/allen/Qt/6.4.1    /Src/build_sqldrivers

In reviewing entries in CMakeCache.txt in found several references to SQLite. After insuring that the location of my libsqlite3.so and the l include directory were correct, the configure completed successfully but when the build was done, it failed with:
allen@layout-pc2:~/Qt/6.4.1/Src$ cmake --build . [715/10017] Linking CXX shared module qtbase/plugins/sqldrivers/libqsqlite.so FAILED: qtbase/plugins/sqldrivers/libqsqlite.so : && /usr/bin/c++ -fPIC -DNDEBUG -O2 -Wl,--no-undefined -Wl,--version-script,/home/allen/Qt/6.4.1/Src/qtbase/src/plugins/sqldrivers/sqlite/QSQLiteDriverPlugin.version -Wl,--enable-new-dtags -shared -o qtbase/plugins/sqldrivers/libqsqlite.so qtbase/src/plugins/sqldrivers/sqlite/CMakeFiles/QSQLiteDriverPlugin.dir/QSQLiteDriverPlugin_autogen/mocs_compilation.cpp.o qtbase/src/plugins/sqldrivers/sqlite/CMakeFiles/QSQLiteDriverPlugin.dir/qsql_sqlite.cpp.o qtbase/src/plugins/sqldrivers/sqlite/CMakeFiles/QSQLiteDriverPlugin.dir/smain.cpp.o -Wl,-rpath,/usr/local/lib:/home/allen/Qt/6.4.1/Src/qtbase/lib: /usr/local/lib/libsqlite3.so qtbase/lib/libQt6Sql.so.6.4.1 qtbase/lib/libQt6Core.so.6.4.1 && : /usr/bin/ld: qtbase/src/plugins/sqldrivers/sqlite/CMakeFiles/QSQLiteDriverPlugin.dir/qsql_sqlite.cpp.o: in function QSQLiteResultPrivate::initColumns(bool)': qsql_sqlite.cpp:(.text+0x2496): undefined reference to sqlite3_column_table_name16' collect2: error: ld returned 1 exit status [720/10017] Building CXX object qtbase.../CMakeFiles/Test.dir/cmake_pch.hxx.gch ninja: build stopped: subcommand failed.

piztneat

piztneat1#

sqlite3_column_table_name16上未解决的错误是由于未使用DSQLITE_ENABLE_COLUMN_METADATA定义编译sqlite库造成的。使用该定义重新编译Sqlite导致成功编译Sqlite插件。因此,我相信问题已解决。

相关问题