c++cmakerangeduplicate-symbol

Including header library in a new project shows duplicate 'constexpr' error


I have two separate projects. The first project uses the range-v3 header only library and I want to use the range library in my new project too, but including the library shows the duplicate constexpr error. I don't have any duplicate error in my first project.

In summary:

Why does my compiler throw the duplicate symbol error message when using the range library in a completely new project and how can I resolve the problem?

CLion 2019.3 (project enable C++20 option)

GCC 9.2

ranges-v3 library by ericniebler

project structure

-cmake_build-debug
CMakeLists.txt
main.cpp

my main:

#include <vector>
#include <range/v3/view/transform.hpp> //throws error

int main() {

    std::vector<int> myvec{1,2,3,4};
    return 0;
}

The CMake code, which works in my old project:

cmake_minimum_required(VERSION 3.15)

project(codingchallange C CXX)

set(CMAKE_CXX_STANDARD 20)

set(SOURCE_FILES main.cpp)

add_library(range_v3 INTERFACE IMPORTED) set_target_properties(range_v3 PROPERTIES
        INTERFACE_INCLUDE_DIRECTORIES /home/myname/CLionProjects/Libraries2/range-v3/range-v3-master/include)

add_executable(codingchallange ${SOURCE_FILES})

target_link_libraries(codingchallange range_v3) #link libraries to exe

The error message thrown by my compiler:

Scanning dependencies of target codingchallange
[ 50%] Building CXX object CMakeFiles/codingchallange.dir/main.cpp.o
In file included from /home/myname/CLionProjects/Libraries2/range-v3/range-v3-master/include/range/v3/range_fwd.hpp:22,
                 from /home/myname/CLionProjects/Libraries2/range-v3/range-v3-master/include/range/v3/view/transform.hpp:23,
                 from /home/myname/CLionProjects/codingchallange/main.cpp:4:
/home/myname/CLionProjects/Libraries2/range-v3/range-v3-master/include/range/v3/range/conversion.hpp:207:19: error: duplicate ‘constexpr’
  207 |         constexpr CPP_concept_bool has_allocator_type =
      |                   ^~~~~~~~~~~~~~~~
/home/myname/CLionProjects/Libraries2/range-v3/range-v3-master/include/range/v3/range/conversion.hpp:211:19: error: duplicate ‘constexpr’
  211 |         constexpr CPP_concept_bool range_and_not_view =
      |                   ^~~~~~~~~~~~~~~~
/home/myname/CLionProjects/Libraries2/range-v3/range-v3-master/include/range/v3/range/conversion.hpp:223:19: error: duplicate ‘constexpr’
  223 |         constexpr CPP_concept_bool convertible_to_cont_impl_ =
      |                   ^~~~~~~~~~~~~~~~
/home/myname/CLionProjects/Libraries2/range-v3/range-v3-master/include/range/v3/view/transform.hpp:74:19: error: duplicate ‘constexpr’
   74 |         constexpr CPP_concept_bool iter_transform_1_readable =
      |                   ^~~~~~~~~~~~~~~~
/home/myname/CLionProjects/Libraries2/range-v3/range-v3-master/include/range/v3/view/transform.hpp:93:19: error: duplicate ‘constexpr’
   93 |         constexpr CPP_concept_bool iter_transform_2_readable =

SOLVED: my old CMake has a specific compiler option I forgot to use(see answer).


Solution

  • I had to add a specific compiler option:

    add_compile_options(-fconcepts) #enables concepts(unstable). 
    #Stable versions will be released with gcc/g++ 10
    

    Now it works fine.