1

I am trying to do an application in boost with cmake. I dont know why, but it keep throwing an lot of errors. I am using cmake 3.10, boost 1.68.

error log is too long, so i posted it here:

https://pastebin.com/E91KHfpD

my cmake config:

    cmake_minimum_required(VERSION 3.10)
project(testProject)

set(CMAKE_CXX_STANDARD 11)

add_executable(testProject main.cpp)
set_target_properties(testProject PROPERTIES COMPILE_FLAGS "-m32" LINK_FLAGS "-m32")
target_link_libraries(testProject F:/c++libs/boost_1_68_0/stage/lib/libboost_filesystem-mgw51-mt-s-x32-1_68.a)
target_include_directories(testProject PRIVATE F:/c++libs/boost_1_68_0)

Second think what i was trying was with findboost. my second cmake config:

cmake_minimum_required(VERSION 3.12.1)
project(testProject)

set(CMAKE_CXX_STANDARD 11)

set(BOOST_ROOT "F:/c++libs/boost_1_68_0")
set(BOOST_LIBRARYDIR ${BOOST_ROOT}/stage/lib/)
set(BOOST_INCLUDEDIR "F:/c++libs/boost_1_68_0/boost")
set(Boost_USE_STATIC_LIBS ON)
set(Boost_MULTITHREADED ON)
set(Boost_USE_STATIC_RUNTIME ON)
add_definitions(-DBOOST_ERROR_CODE_HEADER_ONLY)

find_package(Boost 1.68 COMPONENTS system filesystem REQUIRED)

add_executable(testProject main.cpp)
target_link_libraries(testProject ${Boost_LIBRARIES})
target_include_directories(testProject PRIVATE ${Boost_INCLUDE_DIRS})
set_target_properties(testProject PROPERTIES COMPILE_FLAGS "-m32" LINK_FLAGS "-m32")

This throw this error:

F:/c++libs/boost_1_68_0/stage/lib/libboost_filesystem-mgw51-mt-sd-1_68.a(codecvt_error_category.o): duplicate section `.rdata$_ZTIN5boost6system14error_category12std_categoryE[__ZTIN5boost6system14error_category12std_categoryE]' has different size
F:/c++libs/boost_1_68_0/stage/lib/libboost_filesystem-mgw51-mt-sd-1_68.a(codecvt_error_category.o): duplicate section `.rdata$_ZTVN5boost6system14error_category12std_categoryE[__ZTVN5boost6system14error_category12std_categoryE]' has different size
Bequiny
  • 41
  • 1
  • 5
  • Check you are using the same -std=c++14 or -std=c++11 etc flag for the build of boost and and test project. Example here of similar issue: https://stackoverflow.com/questions/11635485/regex-boost-library-linking-in-release-mode-warns-duplicate-section-has-differe – Richard Critten Aug 26 '18 at 16:17
  • Hi ! And thank you for answer. I just want to ask you one thing, i didnt specify this argument. So what is the default ? – Bequiny Aug 26 '18 at 16:18
  • 1
    Don't know what exactly goes wrong with your example here, but you can try the approach proposed [here](https://rix0r.nl/blog/2015/08/13/cmake-guide/) (not my blog). First up, you should definitely use `find_package`, and you shouldn't be adding boost include directories manually. – paler123 Aug 26 '18 at 16:20
  • There are several problems there, one of them is that you didn't specify all the required llibraries. If you are using boost_filesystem, you also need boost_system and probably a few others. – n. m. could be an AI Aug 26 '18 at 16:27

1 Answers1

0

You can't use -DBOOST_ERROR_CODE_HEADER_ONLY and link to boost_system, you need to remove either the define or the library.

Alan Birtles
  • 32,622
  • 4
  • 31
  • 60
  • Same errors like above by second try, but it started saying it also on system not only on filesystem. what did i change, i had only the line with dboost_error_code_header_only deleted. – Bequiny Aug 26 '18 at 20:39