0

I am starting a new project using C++, Boost, CMake tools, Visual Studio Code, and Ubuntu. The Ubuntu version of Boost is currently 1.71 and it is located in /usr/local/boost. It is not the version that I want to run because I want to use the Json features in 1.75. Unfortunately I felt I had to start with the 1.71 version of Boost that came with Ubuntu because I could not get CMake tools to find the 1.75 version that I put in {$workspace}/boost. I used the bootstrap.sh and b2 to compile it there directly from the downloaded version as prescribed in all of the boost tutorials. Any attempt as setting $BOOST_ROOT was completely ignored by CMake tools and it always defaulted to the system's version for some reason. I had no problems with getting intellisense to pick up the Boost 1.75.0 using .vscode/c_cpp_properties.json. I basically gave up on 1.75 and used 1.71 from usr/local/boost because I wanted to make forward progress on using boost:logs.

So... after switching to Ubuntu's 1.71 version in /usr/local and following the boost::log tutorials I came up with this set of problems. I was able to build and run my code until I did the following.

My jsc-main.cpp started popping out CMake Tools compile errors when I added the following include statements and method:

#include <boost/log/core.hpp>
#include <boost/log/trivial.hpp>
#include <boost/log/expressions.hpp>
#include <boost/log/sinks/text_file_backend.hpp>
#include <boost/log/utility/setup/file.hpp>
#include <boost/log/utility/setup/common_attributes.hpp>
#include <boost/log/sources/severity_logger.hpp>
#include <boost/log/sources/record_ostream.hpp>

namespace logging = boost::log;
namespace src = boost::log::sources;
namespace sinks = boost::log::sinks;
namespace keywords = boost::log::keywords;

void InitLogFIle()
{
    logging::add_file_log("sample.log");
}

Here is the contents of my CMakeLists.txt file:

cmake_minimum_required(VERSION 3.0.0)
project(JANNEcore VERSION 0.1.0)

include(CTest)
enable_testing()

add_library(JANNE_CoreUtils 
    STATIC 
        JANNE_CoreUtils.hpp 
        JANNE_CoreUtils.cpp
    )

add_library(JOODA
    STATIC
        JOODA.hpp
        JOODA.cpp
        JANNE_CoreUtils.hpp
        JANNE_CoreUtils.cpp
    )
find_package(Boost 1.71 REQUIRED COMPONENTS system filesystem log )

include_directories(include)

add_executable(JANNEcore jsc-main.cpp)



target_link_libraries(JANNEcore JANNE_CoreUtils JOODA pthread )
set(CPACK_PROJECT_NAME ${PROJECT_NAME})
set(CPACK_PROJECT_VERSION ${PROJECT_VERSION})
include(CPack)

At this point I've started generating this crazy looking set of errors when I attempt to build using cmake:build off of the command pallet in VS Code

[main] Building folder: JANNE 
[build] Starting build
[proc] Executing command: /usr/bin/cmake --build /home/morsa/source/repos/JANNE/build --config Debug --target all -- -j 10
[build] [ 42%] Built target JOODA
[build] [ 71%] Built target JANNE_CoreUtils
[build] [ 85%] Linking CXX executable JANNEcore
[build] /usr/bin/ld: CMakeFiles/JANNEcore.dir/jsc-main.cpp.o: in function `boost::log::v2s_mt_posix::aux::once_block_sentry::~once_block_sentry()':
[build] /usr/include/boost/log/utility/once_block.hpp:86: undefined reference to `boost::log::v2s_mt_posix::aux::once_block_sentry::rollback()'
[build] /usr/bin/ld: CMakeFiles/JANNEcore.dir/jsc-main.cpp.o: in function `boost::log::v2s_mt_posix::aux::once_block_sentry::executed() const':
[build] /usr/include/boost/log/utility/once_block.hpp:91: undefined reference to `boost::log::v2s_mt_posix::aux::once_block_sentry::enter_once_block() const'
[build] /usr/bin/ld: CMakeFiles/JANNEcore.dir/jsc-main.cpp.o: in function `boost::log::v2s_mt_posix::expressions::tag::message::get_name()':
[build] /usr/include/boost/log/expressions/message.hpp:56: undefined reference to `boost::log::v2s_mt_posix::aux::default_attribute_names::message()'
[build] /usr/bin/ld: CMakeFiles/JANNEcore.dir/jsc-main.cpp.o: in function `boost::shared_ptr<boost::log::v2s_mt_posix::sinks::synchronous_sink<boost::log::v2s_mt_posix::sinks::text_file_backend> > boost::log::v2s_mt_posix::aux::add_file_log<boost::parameter::aux::tagged_argument_list_of_1<boost::parameter::aux::tagged_argument<boost::log::v2s_mt_posix::keywords::tag::file_name, char const [11]> > >(boost::parameter::aux::tagged_argument_list_of_1<boost::parameter::aux::tagged_argument<boost::log::v2s_mt_posix::keywords::tag::file_name, char const [11]> > const&)':
[build] /usr/include/boost/log/utility/setup/file.hpp:85: undefined reference to `boost::log::v2s_mt_posix::sinks::text_file_backend::set_file_collector(boost::shared_ptr<boost::log::v2s_mt_posix::sinks::file::collector> const&)'
[build] /usr/bin/ld: /usr/include/boost/log/utility/setup/file.hpp:86: undefined reference to `boost::log::v2s_mt_posix::sinks::text_file_backend::scan_for_files(boost::log::v2s_mt_posix::sinks::file::scan_method, bool)'
[build] /usr/bin/ld: /usr/include/boost/log/utility/setup/file.hpp:98: undefined reference to `boost::log::v2s_mt_posix::core::get()'
[build] /usr/bin/ld: /usr/include/boost/log/utility/setup/file.hpp:98: undefined reference to `boost::log::v2s_mt_posix::core::add_sink(boost::shared_ptr<boost::log::v2s_mt_posix::sinks::sink> const&)'
[build] /usr/bin/ld: CMakeFiles/JANNEcore.dir/jsc-main.cpp.o: in function `void boost::log::v2s_mt_posix::sinks::text_file_backend::construct<boost::parameter::aux::tagged_argument_list_of_1<boost::parameter::aux::tagged_argument<boost::log::v2s_mt_posix::keywords::tag::file_name, char const [11]> > >(boost::parameter::aux::tagged_argument_list_of_1<boost::parameter::aux::tagged_argument<boost::log::v2s_mt_posix::keywords::tag::file_name, char const [11]> > const&)':
[build] /usr/include/boost/log/sinks/text_file_backend.hpp:575: undefined reference to `boost::log::v2s_mt_posix::sinks::text_file_backend::construct(boost::filesystem::path const&, boost::filesystem::path const&, std::_Ios_Openmode, unsigned long, boost::log::v2s_mt_posix::aux::light_function<bool ()> const&, boost::log::v2s_mt_posix::sinks::auto_newline_mode, bool, bool)'
[build] /usr/bin/ld: CMakeFiles/JANNEcore.dir/jsc-main.cpp.o: in function `boost::thread_specific_ptr<boost::log::v2s_mt_posix::sinks::basic_formatting_sink_frontend<char>::formatting_context>::~thread_specific_ptr()':
[build] /usr/include/boost/thread/tss.hpp:61: undefined reference to `boost::detail::set_tss_data(void const*, void (*)(void (*)(void*), void*), void (*)(void*), void*, bool)'
[build] /usr/bin/ld: CMakeFiles/JANNEcore.dir/jsc-main.cpp.o: in function `boost::detail::sp_ms_deleter<boost::log::v2s_mt_posix::sinks::text_file_backend>::destroy()':
[build] /usr/include/boost/smart_ptr/make_shared_object.hpp:59: undefined reference to `boost::log::v2s_mt_posix::sinks::text_file_backend::~text_file_backend()'
[build] /usr/bin/ld: CMakeFiles/JANNEcore.dir/jsc-main.cpp.o: in function `boost::log::v2s_mt_posix::visitation_result boost::log::v2s_mt_posix::value_visitor_invoker<boost::mpl::vector2<std::__cxx11::basic_string<char, std::char_traits<char>, std::allocator<char> >, std::__cxx11::basic_string<wchar_t, std::char_traits<wchar_t>, std::allocator<wchar_t> > >, boost::log::v2s_mt_posix::fallback_to_none>::operator()<boost::log::v2s_mt_posix::binder1st<boost::log::v2s_mt_posix::output_fun, boost::log::v2s_mt_posix::expressions::aux::stream_ref<boost::log::v2s_mt_posix::basic_formatting_ostream<char, std::char_traits<char>, std::allocator<char> > >&> >(boost::log::v2s_mt_posix::attribute_name const&, boost::log::v2s_mt_posix::attribute_value_set const&, boost::log::v2s_mt_posix::binder1st<boost::log::v2s_mt_posix::output_fun, boost::log::v2s_mt_posix::expressions::aux::stream_ref<boost::log::v2s_mt_posix::basic_formatting_ostream<char, std::char_traits<char>, std::allocator<char> > >&>) const':
[build] /usr/include/boost/log/attributes/value_visitation.hpp:182: undefined reference to `boost::log::v2s_mt_posix::attribute_value_set::find(boost::log::v2s_mt_posix::attribute_name) const'
[build] /usr/bin/ld: /usr/include/boost/log/attributes/value_visitation.hpp:183: undefined reference to `boost::log::v2s_mt_posix::attribute_value_set::end() const'
[build] /usr/bin/ld: /usr/include/boost/log/attributes/value_visitation.hpp:191: undefined reference to `boost::log::v2s_mt_posix::aux::attach_attribute_name_info(boost::exception&, boost::log::v2s_mt_posix::attribute_name const&)'
[build] /usr/bin/ld: CMakeFiles/JANNEcore.dir/jsc-main.cpp.o: in function `boost::array<std::pair<boost::typeindex::stl_type_index, void*>, 2ul> const& boost::log::v2s_mt_posix::aux::type_sequence_dispatcher<boost::mpl::vector2<std::__cxx11::basic_string<char, std::char_traits<char>, std::allocator<char> >, std::__cxx11::basic_string<wchar_t, std::char_traits<wchar_t>, std::allocator<wchar_t> > > >::get_dispatching_map<boost::log::v2s_mt_posix::binder1st<boost::log::v2s_mt_posix::output_fun, boost::log::v2s_mt_posix::expressions::aux::stream_ref<boost::log::v2s_mt_posix::basic_formatting_ostream<char, std::char_traits<char>, std::allocator<char> > >&> >()':
[build] /usr/include/boost/log/utility/type_dispatch/static_type_dispatcher.hpp:182: undefined reference to `boost::log::v2s_mt_posix::aux::once_block_sentry::commit()'
[build] /usr/bin/ld: CMakeFiles/JANNEcore.dir/jsc-main.cpp.o: in function `boost::enable_if_c<(boost::log::v2s_mt_posix::aux::is_character_type<wchar_t>::value&&boost::log::v2s_mt_posix::aux::is_character_type<char>::value)&&((sizeof (wchar_t))!=(sizeof (char))), bool>::type boost::log::v2s_mt_posix::aux::code_convert<wchar_t, char, std::char_traits<char>, std::allocator<char> >(wchar_t const*, unsigned long, std::__cxx11::basic_string<char, std::char_traits<char>, std::allocator<char> >&, unsigned long, std::locale const&)':
[build] /usr/include/boost/log/detail/code_conversion.hpp:133: undefined reference to `boost::log::v2s_mt_posix::aux::code_convert_impl(wchar_t const*, unsigned long, std::__cxx11::basic_string<char, std::char_traits<char>, std::allocator<char> >&, unsigned long, std::locale const&)'
[build] /usr/bin/ld: CMakeFiles/JANNEcore.dir/jsc-main.cpp.o: in function `void boost::log::v2s_mt_posix::sinks::basic_formatting_sink_frontend<char>::feed_record<boost::recursive_mutex, boost::log::v2s_mt_posix::sinks::text_file_backend>(boost::log::v2s_mt_posix::record_view const&, boost::recursive_mutex&, boost::log::v2s_mt_posix::sinks::text_file_backend&)':
[build] /usr/include/boost/log/sinks/basic_sink_frontend.hpp:463: undefined reference to `boost::log::v2s_mt_posix::sinks::text_file_backend::consume(boost::log::v2s_mt_posix::record_view const&, std::__cxx11::basic_string<char, std::char_traits<char>, std::allocator<char> > const&)'
[build] /usr/bin/ld: CMakeFiles/JANNEcore.dir/jsc-main.cpp.o: in function `boost::thread_specific_ptr<boost::log::v2s_mt_posix::sinks::basic_formatting_sink_frontend<char>::formatting_context>::get() const':
[build] /usr/include/boost/thread/tss.hpp:66: undefined reference to `boost::detail::get_tss_data(void const*)'
[build] /usr/bin/ld: CMakeFiles/JANNEcore.dir/jsc-main.cpp.o: in function `boost::thread_specific_ptr<boost::log::v2s_mt_posix::sinks::basic_formatting_sink_frontend<char>::formatting_context>::reset(boost::log::v2s_mt_posix::sinks::basic_formatting_sink_frontend<char>::formatting_context*)':
[build] /usr/include/boost/thread/tss.hpp:87: undefined reference to `boost::detail::set_tss_data(void const*, void (*)(void (*)(void*), void*), void (*)(void*), void*, bool)'
[build] /usr/bin/ld: CMakeFiles/JANNEcore.dir/jsc-main.cpp.o: in function `void boost::log::v2s_mt_posix::sinks::basic_formatting_sink_frontend<char>::feed_record<boost::log::v2s_mt_posix::aux::fake_mutex, boost::log::v2s_mt_posix::sinks::text_file_backend>(boost::log::v2s_mt_posix::record_view const&, boost::log::v2s_mt_posix::aux::fake_mutex&, boost::log::v2s_mt_posix::sinks::text_file_backend&)':
[build] /usr/include/boost/log/sinks/basic_sink_frontend.hpp:463: undefined reference to `boost::log::v2s_mt_posix::sinks::text_file_backend::consume(boost::log::v2s_mt_posix::record_view const&, std::__cxx11::basic_string<char, std::char_traits<char>, std::allocator<char> > const&)'
[build] /usr/bin/ld: CMakeFiles/JANNEcore.dir/jsc-main.cpp.o: in function `void boost::log::v2s_mt_posix::sinks::basic_sink_frontend::flush_backend_impl<boost::recursive_mutex, boost::log::v2s_mt_posix::sinks::text_file_backend>(boost::recursive_mutex&, boost::log::v2s_mt_posix::sinks::text_file_backend&, mpl_::bool_<true>)':
[build] /usr/include/boost/log/sinks/basic_sink_frontend.hpp:230: undefined reference to `boost::log::v2s_mt_posix::sinks::text_file_backend::flush()'
[build] collect2: error: ld returned 1 exit status
[build] make[2]: *** [CMakeFiles/JANNEcore.dir/build.make:86: JANNEcore] Error 1
[build] make[1]: *** [CMakeFiles/Makefile2:109: CMakeFiles/JANNEcore.dir/all] Error 2
[build] make: *** [Makefile:117: all] Error 2
[build] Build finished with exit code 2
[main] Configuring folder: JANNE 
[proc] Executing command: /usr/bin/cmake --no-warn-unused-cli -DCMAKE_EXPORT_COMPILE_COMMANDS:BOOL=TRUE -DCMAKE_BUILD_TYPE:STRING=Debug -DCMAKE_C_COMPILER:FILEPATH=/bin/gcc-9 -DCMAKE_CXX_COMPILER:FILEPATH=/bin/g++-9 -H/home/morsa/source/repos/JANNE -B/home/morsa/source/repos/JANNE/build -G "Unix Makefiles"
[cmake] Not searching for unused variables given on the command line.
[cmake] -- Configuring done
[cmake] -- Generating done
[cmake] -- Build files have been written to: /home/morsa/source/repos/JANNE/build
[main] Configuring folder: JANNE 
[proc] Executing command: /usr/bin/cmake --no-warn-unused-cli -DCMAKE_EXPORT_COMPILE_COMMANDS:BOOL=TRUE -DCMAKE_BUILD_TYPE:STRING=Debug -DCMAKE_C_COMPILER:FILEPATH=/bin/gcc-9 -DCMAKE_CXX_COMPILER:FILEPATH=/bin/g++-9 -H/home/morsa/source/repos/JANNE -B/home/morsa/source/repos/JANNE/build -G "Unix Makefiles"
[cmake] Not searching for unused variables given on the command line.
[cmake] -- Configuring done
[cmake] -- Generating done
[cmake] -- Build files have been written to: /home/morsa/source/repos/JANNE/build
[main] Configuring folder: JANNE 
[proc] Executing command: /usr/bin/cmake --no-warn-unused-cli -DCMAKE_EXPORT_COMPILE_COMMANDS:BOOL=TRUE -DCMAKE_BUILD_TYPE:STRING=Debug -DCMAKE_C_COMPILER:FILEPATH=/bin/gcc-9 -DCMAKE_CXX_COMPILER:FILEPATH=/bin/g++-9 -H/home/morsa/source/repos/JANNE -B/home/morsa/source/repos/JANNE/build -G "Unix Makefiles"
[cmake] Not searching for unused variables given on the command line.
[cmake] -- Configuring done
[cmake] -- Generating done
[cmake] -- Build files have been written to: /home/morsa/source/repos/JANNE/build

Any help would be greatly appreciated!

Daniel Jerome
  • 301
  • 1
  • 3
  • 13
  • Well, you completely ignore located boost libraries instead of linking them. – user7860670 Feb 10 '21 at 08:20
  • Would you mind clarifying that explanation please. I am completely new to this set of tools. I am finding my CMake experience to be rather painful. Also, would you happen to have any input on the list of errors that were generated on the version that I was able to locate? – Daniel Jerome Feb 10 '21 at 15:52
  • Required boost libraries to be linked should appear among `target_link_libraries` arguments. And yeah, dealing with cmake is indeed a rather painful experience. – user7860670 Feb 10 '21 at 17:06
  • Does that mean that I should do something like define a variable as paths and use them in the target_link_libraries? If so, can I use a path relative to $HOME or workspace in order to make my git repos somewhat "portable"? I've honest read so many conflicting tutorials on the subject that I am utterly confused at this point. I'm usually pretty good at this kind of thing. – Daniel Jerome Feb 10 '21 at 18:07
  • When you use `find_package(Boost...` it executes corresponding module script that defines some global variables such as `Boost_LIBRARIES` to be used later for linking like `target_link_libraries(... ${Boost_LIBRARIES})` see https://cmake.org/cmake/help/latest/module/FindBoost.html From my experience cmake creates more problems than solves, crappy language relying on global variables for everything and not enforcing some standardized project organization practices creates a devastating combo. – user7860670 Feb 10 '21 at 22:03
  • I appreciate the help. I think you have solidified my conclusion. I'm switching back to GNU Make. CMake has wasted a lot of my time with very little results. – Daniel Jerome Feb 11 '21 at 18:11

0 Answers0