原因
其原因是在编译soci库时,没有使用最新的cpp标准
解决办法
打开soci的源码文件夹中的CMakeLists.txt
:
文件过长,这里只给出上半部分的文件
###############################################################################
#
# This file is part of CMake configuration for SOCI library
#
# Copyright (C) 2009-2013 Mateusz Loskot <mateusz@loskot.net>
# Distributed under the Boost Software License, Version 1.0.
# (See accompanying file LICENSE_1_0.txt or copy at
# http://www.boost.org/LICENSE_1_0.txt)
#
###############################################################################
# General settings
###############################################################################
cmake_minimum_required(VERSION 2.8 FATAL_ERROR)
project(SOCI)
###############################################################################
# Build features and variants
##############################################################################
option(SOCI_SHARED "Enable build of shared libraries" ON)
option(SOCI_STATIC "Enable build of static libraries" ON)
option(SOCI_TESTS "Enable build of collection of SOCI tests" ON)
option(SOCI_ASAN "Enable address sanitizer on GCC v4.8+/Clang v 3.1+" OFF)
option(SOCI_LTO "Enable link time optimization" OFF)
option(SOCI_VISIBILITY "Enable hiding private symbol using ELF visibility if supported by the platform" ON)
if (SOCI_LTO)
cmake_minimum_required(VERSION 3.9)
# Check and enable lto support
include(CheckIPOSupported)
check_ipo_supported(RESULT supported)
if (NOT supported)
message(STATUS "IPO / LTO not supported")
endif()
if (supported AND NOT SOCI_ASAN)
message(STATUS "IPO / LTO enabled")
然后在project(SOCI)
的下方添加一行set(CMAKE_CXX_STANDARD 20)
来指定编译该库时所用的cpp版本。(只要大于11即可)
更改后的CMakeLists.txt
文件(不全,不要直接复制使用):
###############################################################################
#
# This file is part of CMake configuration for SOCI library
#
# Copyright (C) 2009-2013 Mateusz Loskot <mateusz@loskot.net>
# Distributed under the Boost Software License, Version 1.0.
# (See accompanying file LICENSE_1_0.txt or copy at
# http://www.boost.org/LICENSE_1_0.txt)
#
###############################################################################
# General settings
###############################################################################
cmake_minimum_required(VERSION 2.8 FATAL_ERROR)
project(SOCI)
set(CMAKE_CXX_STANDARD 20)
###############################################################################
# Build features and variants
##############################################################################
option(SOCI_SHARED "Enable build of shared libraries" ON)
option(SOCI_STATIC "Enable build of static libraries" ON)
option(SOCI_TESTS "Enable build of collection of SOCI tests" ON)
option(SOCI_ASAN "Enable address sanitizer on GCC v4.8+/Clang v 3.1+" OFF)
option(SOCI_LTO "Enable link time optimization" OFF)
option(SOCI_VISIBILITY "Enable hiding private symbol using ELF visibility if supported by the platform" ON)
if (SOCI_LTO)
cmake_minimum_required(VERSION 3.9)
# Check and enable lto support
include(CheckIPOSupported)
check_ipo_supported(RESULT supported)
if (NOT supported)
message(STATUS "IPO / LTO not supported")
endif()
if (supported AND NOT SOCI_ASAN)
message(STATUS "IPO / LTO enabled")
set(CMAKE_INTERPROCEDURAL_OPTIMIZATION TRUE)
if (CMAKE_CXX_COMPILER_ID MATCHES "Clang")
# Check for lld as clang lto works best with its own linker
include(CheckCXXCompilerFlag)
check_cxx_compiler_flag("-fuse-ld=lld" HAS_LLD)
if (HAS_LLD)
SET(CMAKE_EXE_LINKER_FLAGS "${CMAKE_EXE_LINKER_FLAGS} -fuse-ld=lld")
SET(CMAKE_SHARED_LINKER_FLAGS "${CMAKE_SHARED_LINKER_FLAGS} -fuse-ld=lld")
SET(CMAKE_MODULE_LINKER_FLAGS "${CMAKE_MODULE_LINKER_FLAGS} -fuse-ld=lld")
endif()
endif()
elseif(supported)
message(STATUS "IPO / LTO is supported but conflicts with ASAN and not enabled")
endif()
endif()
if (SOCI_VISIBILITY)
# Test whether vis