使用soci库时,出现“#error “SOCI must be configured with C++11 support when using C++11“”的解决办法

原因

其原因是在编译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
  • 2
    点赞
  • 0
    收藏
    觉得还不错? 一键收藏
  • 0
    评论

“相关推荐”对你有帮助么?

  • 非常没帮助
  • 没帮助
  • 一般
  • 有帮助
  • 非常有帮助
提交
评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

当前余额3.43前往充值 >
需支付:10.00
成就一亿技术人!
领取后你会自动成为博主和红包主的粉丝 规则
hope_wisdom
发出的红包
实付
使用余额支付
点击重新获取
扫码支付
钱包余额 0

抵扣说明:

1.余额是钱包充值的虚拟货币,按照1:1的比例进行支付金额的抵扣。
2.余额无法直接购买下载,可以购买VIP、付费专栏及课程。

余额充值