Reputation: 468
I'm trying to build a c++ project using cmake and CLion but I get a few errors I can't understand:
"C:\Program Files\JetBrains\CLion 2019.2.5\bin\cmake\win\bin\cmake.exe" --build C:\Users\username\project-name\cmake-build-debug --target all_tests
Scanning dependencies of target all_tests
[ 0%] Building CXX object CMakeFiles/all_tests.dir/tests/all_tests.cpp.obj
all_tests.cpp
C:\PROGRA~2\Boost\include\BOOST-~1\boost/test/impl/compiler_log_formatter.ipp(64): warning C4273: 'boost::unit_test::output::compiler_log_formatter::log_start': inconsistent dll link
C:\PROGRA~2\Boost\include\BOOST-~1\boost/test/output/compiler_log_formatter.hpp(37): note: see previous definition of 'log_start'
C:\PROGRA~2\Boost\include\BOOST-~1\boost/test/impl/compiler_log_formatter.ipp(76): warning C4273: 'boost::unit_test::output::compiler_log_formatter::log_finish': inconsistent dll link
C:\PROGRA~2\Boost\include\BOOST-~1\boost/test/output/compiler_log_formatter.hpp(38): note: see previous definition of 'log_finish'
// ...
// ... many more warnings like these
// ...
C:\PROGRA~2\Boost\include\BOOST-~1\boost/test/impl/unit_test_parameters.ipp(759): warning C4273: 'boost::unit_test::runtime_config::save_pattern': inconsistent dll link
C:\PROGRA~2\Boost\include\BOOST-~1\boost/test/unit_test_parameters.hpp(93): note: see previous definition of 'save_pattern'
NMAKE : fatal error U1077: 'C:\PROGRA~2\MICROS~3\2017\BUILDT~1\VC\Tools\MSVC\1416~1.270\bin\Hostx86\x86\cl.exe' : return code '0x2'
Stop.
NMAKE : fatal error U1077: '"C:\Program Files (x86)\Microsoft Visual Studio\2017\BuildTools\VC\Tools\MSVC\14.16.27023\bin\HostX86\x86\nmake.exe"' : return code '0x2'
Stop.
NMAKE : fatal error U1077: '"C:\Program Files (x86)\Microsoft Visual Studio\2017\BuildTools\VC\Tools\MSVC\14.16.27023\bin\HostX86\x86\nmake.exe"' : return code '0x2'
Stop.
NMAKE : fatal error U1077: '"C:\Program Files (x86)\Microsoft Visual Studio\2017\BuildTools\VC\Tools\MSVC\14.16.27023\bin\HostX86\x86\nmake.exe"' : return code '0x2'
Stop.
The cmake file I use is the following:
cmake_minimum_required(VERSION 3.9)
project(project_name)
set(CMAKE_CXX_STANDARD 11)
# private lib
add_library(lib INTERFACE)
target_include_directories(lib INTERFACE src/utilities)
# boost
set(BOOST_ROOT "C:\\Program Files\\Boost")
find_package(Boost CONFIG 1.71.0)
if(Boost_FOUND)
message("FOUND")
include_directories(${Boost_INCLUDE_DIR})
endif()
SET(MAIN "...")
SET(TESTS "...")
add_executable(all_tests tests/all_tests.cpp ${MAIN} ${TESTS})
target_link_libraries(all_tests lib)
Please note that this same project works on my mac but when I try to build it in windows 10 it gives this error, so what's the problem here?
EDIT:
all_tests.cpp:
#define BOOST_TEST_DYN_LINK
#include <boost/test/unit_test.hpp>
#include <boost/test/included/unit_test.hpp>
// initialization function:
bool init_unit_test() {
return true;
}
// entry point:
int main(int argc, char* argv[], char* envp[]) {
return boost::unit_test::unit_test_main( &init_unit_test, argc, argv );
}
Example test suite:
#define BOOST_TEST_DYN_LINK
#include <boost/test/unit_test.hpp>
#include "../../src/path/to/header.hpp"
BOOST_AUTO_TEST_SUITE( Suite1 )
BOOST_AUTO_TEST_CASE( Test1 ) {
auto res = header_class::function1();
BOOST_CHECK_EQUAL(res, expected_result);
}
BOOST_AUTO_TEST_CASE( Test2 ) {
auto res = header_class::function2();
BOOST_CHECK_EQUAL(res, expected_result);
}
BOOST_AUTO_TEST_SUITE_END()
I'm pretty sure that the code inside test cases is correct and it's not causing the problem.
Upvotes: 0
Views: 15177
Reputation: 65870
The headers boost/test/unit_test.hpp
and boost/test/included/unit_test.hpp
contains same functionality but for different use:
boost/test/unit_test.hpp
only declares the functions which are defined in the library file,boost/test/included/unit_test.hpp
defines the functions, thus including the library file is not needed.There is absolutely no needs to use both these headers.
Upvotes: 1