I'm using boost 1.60 and noticed a weird thing while compiling my project.. I compiled boost statically and used it into my static slib
project.
The static library uses boost::log for debugging all over.
Then I included and linked this slib
into an executable and got lots of errors like this:
[ 76%] Linking CXX executable ../bin/test
/home/user/aeb509b8f8eb8ba82af2bc50d4649570ba08ff42/lib/libboost_log.a(text_file_backend.o): In function `boost::log::v2s_mt_posix::sinks::file:
:aux::make_collector(boost::filesystem::path const&, unsigned long, unsigned long)':
text_file_backend.cpp:(.text+0x1b73): undefined reference to `boost::filesystem::detail::current_path(boost::system::error_code*)'
text_file_backend.cpp:(.text+0x1bda): undefined reference to `boost::filesystem::absolute(boost::filesystem::path const&, boost::filesystem::path const&)'
text_file_backend.cpp:(.text+0x1c11): undefined reference to `boost::filesystem::detail::create_directories(boost::filesystem::path const&, boost::system::error_code*)'
weird since I'm sure boost_filesystem
is included.
As soon as I added a useless line which used boost_filesystem
into my executable
if (boost::filesystem::exists("ttt.txt"))
std::cout << "tt";
all the errors disappeared and compilation and linking went fine.
Is it possible that gcc is optimizing away boost_filesystem
from my slib
static library??
Edit: I'm posting the CMake files for the static library
cmake_minimum_required(VERSION 3.2)
set (CMAKE_CXX_STANDARD 14)
project(slib)
add_subdirectory(src)
add_library(slib ${SRCS})
# Conan setup
include(${CMAKE_BINARY_DIR}/conanbuildinfo.cmake)
conan_basic_setup()
find_package(Threads) # needed
target_include_directories(test PUBLIC ${CMAKE_SOURCE_DIR}/include ${CMAKE_BINARY_DIR})
target_link_libraries(test ${CONAN_LIBS} ${CMAKE_THREAD_LIBS_INIT})
and for the simple executable which links against it (almost a hello world)
project(test)
set(SRCS test.cpp)
add_executable(test ${SRCS})
target_include_directories(test PRIVATE ${CMAKE_SOURCE_DIR}/include
${Boost_INCLUDE_DIRS})
target_link_libraries(test boost_filesystem ${CONAN_LIBS} slib) # Link it in!
The boost libraries are statically compiled with conan (Boost:shared=False).