1

I want to know the community's opinion on mixing different versions of C++ when building applications. I need to build a library that requires at least C++14 because of its dependency on a C++14 package. This library will then be used in the main application that has to be compiled with C++11, not with any newer versions. Is such a thing recommended to mix different C++ versions as in the following CMakeLists.txt?

It seems to me that the only way to combine them is to build the library as a shared library not static. Please let me know if this is what's recommended. Thanks for your help.

cmake_minimum_required(VERSION 3.5 FATAL_ERROR)
project(myproject LANGUAGES CXX)

set(CMAKE_WINDOWS_EXPORT_ALL_SYMBOLS ON)

add_library(MyCpp14Library
  SHARED
    MyCpp14Library.cpp
    MyCpp14Library.hpp
  )

set_target_properties(MyCpp14Library
  PROPERTIES
    CXX_STANDARD 14
    CXX_EXTENSIONS OFF
    CXX_STANDARD_REQUIRED ON
    POSITION_INDEPENDENT_CODE 1
  )

add_executable(MyCpp11Application MyCpp11Application.cpp)

set_target_properties(MyCpp11Application
  PROPERTIES
    CXX_STANDARD 11
    CXX_EXTENSIONS OFF
    CXX_STANDARD_REQUIRED ON
  )

target_link_libraries(MyCpp11Application MyCpp14Library)
cigien
  • 57,834
  • 11
  • 73
  • 112
afp_2008
  • 1,940
  • 1
  • 19
  • 46

0 Answers0