[英]Include soci in cmake on windows
I have a HelloWorld
project in JetBrains CLion and set up boost
so I can build it fine. 我在JetBrains CLion中有一个HelloWorld
项目,并设置了boost
以便可以很好地构建它。
I've managed to build soci
using cmake
and make
with mingw
outside the HelloWorld
project. 我已经成功地建立soci
使用cmake
,并make
与mingw
外面HelloWorld
项目。
For boost I used: 为了提高动力,我使用了:
include(FindBoost)
find_package(Boost 1.55.0 COMPONENTS system filesystem)
How do I include the soci
library in my cmake
? 如何在我的cmake
包含soci
库? Is there a similar method for including soci
? 有没有类似的方法可以包含soci
? I don't know where to start? 我不知道从哪里开始?
UPDATE 更新
A bit further I think. 我想再进一步。
I added the following to my cmake options: 我在我的cmake选项中添加了以下内容:
-D CMAKE_MODULE_PATH=D:\Development\Tools\lib\soci-3.2.2\cmake\modules
and this to my CMakeLists.txt
: 这到我的CMakeLists.txt
:
find_package(Soci)
if(${SOCI_FOUND})
target_link_libraries(HelloWorld ${SOCI_LIBRARY} ${SOCI_sqlite3_PLUGIN})
else()
message(WARNING "SOCI NOT FOUND")
endif()
I still get SOCI NOT FOUND
though but at least the soci
variables turns up in the cmake
cache. 我仍然得到SOCI NOT FOUND
虽然但至少soci
变量的轮番上涨cmake
缓存。
这显然很晚了,但是对我有用:
target_link_libraries(HelloWorld soci_core soci_mysql)
I must admit I shame for my country mates because they provide so crapy CMakeLists.txt for SOCI lib. 我必须承认我为我的队友感到羞耻,因为他们为SOCI库提供了如此糟糕的CMakeLists.txt。 In order to mitigate they bad works, I wrote following intsturctions how to use SOCI in CMake based projects. 为了减轻它们的不良影响,我编写了以下说明,介绍如何在基于CMake的项目中使用SOCI。 I do it on Linux KDE Neon 5.16.5 (based on: Ubuntu 18.04 LTS), but on Windows probably you have only fix paths. 我在Linux KDE Neon 5.16.5(基于:Ubuntu 18.04 LTS)上执行此操作,但是在Windows上可能只有修复路径。 This probalby will work. 这个probalby将起作用。 I am not 100% sure because I just start my project within I want to use SOCI. 我不确定100%,因为我只是在要使用SOCI的范围内启动项目。
This is obviously very late, but it probably works: I build and install soci like this: 这显然已经很晚了,但它可能有效:我像这样构建和安装soci:
cmake "/home/szyk/!-EnergoKod/!-Libs/3rdparty/soci" -DCMAKE_INSTALL_PREFIX=/usr/local -DCMAKE_PREFIX_PATH=/usr/lib/x86_64-linux-gnu -DCMAKE_BUILD_TYPE=Release
cmake "/home/szyk/!-EnergoKod/!-Libs/3rdparty/soci" -DCMAKE_INSTALL_PREFIX=/usr/local -DCMAKE_PREFIX_PATH=/usr/lib/x86_64-linux-gnu -DCMAKE_BUILD_TYPE=Debug
make -j$(nproc)
sudo make install
I add to my project CMakeLists.txt: 我将添加到我的项目CMakeLists.txt中:
set(SOCI_SOURCE_DIR "$ENV{HOME}/!-EnergoKod/!-Libs/3rdparty/soci")
set(CMAKE_MODULE_PATH ${SOCI_SOURCE_DIR}/cmake ${CMAKE_MODULE_PATH})
set(CMAKE_MODULE_PATH ${SOCI_SOURCE_DIR}/cmake/modules ${CMAKE_MODULE_PATH})
find_package(Soci)
list(APPEND LIBS ${SOCI_LIBRARY} ${SOCI_sqlite3_PLUGIN})
# Link libraries
target_link_libraries(${PROJECT_NAME} PRIVATE ${LIBS})
That is generates good looking output: 那会产生漂亮的输出:
Soci found: Looking for plugins
* Plugin mysql not found.
* Plugin odbc not found.
* Plugin postgresql not found.
* Plugin sqlite3 found /usr/local/lib/x86_64-linux-gnu/libsoci_sqlite3.so.
Found Soci: /usr/local/include/soci
声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.