3

I'm using JetBrain's CLion and try to run some boost tests, but they won't. Here's my code:

#define BOOST_TEST_MAIN 1
#define BOOST_TEST_MODULE !
#include <boost/test/unit_test.hpp>
#include <iostream>

BOOST_AUTO_TEST_CASE(MyTest) {
    BOOST_CHECK(false);
}


int main() {
    std::cout << "in main!" << std::endl;
    return 0;
}

and my cmake file :

set(CMAKE_CXX_FLAGS "${CMAKE_CXX_FLAGS} -std=c++11")
set(SOURCE_FILES main.cpp)
set(BOOST_ROOT /home/vitalii/Downloads/boost_1_57_0)
find_package(Boost 1.57 COMPONENTS unit_test_framework REQUIRED)
add_executable(justForFun ${SOURCE_FILES})
if (Boost_FOUND)
    include_directories(${Boost_INCLUDE_DIRS})
    link_directories(${Boost_LIBRARY_DIRS})
    target_link_libraries(justForFun ${Boost_UNIT_TEST_FRAMEWORK_LIBRARY})
else()
    message(FATAL "Boost not found")
endif()
enable_testing()

The problem is that the output wil be just "in main". And test won't launch. I figured i don't need 'main' function. It should be created automatically. But If i delete it then I get these errors :

/usr/bin/ld: /usr/lib/debug/usr/lib/x86_64-linux-gnu/crt1.o(.debug_info): relocation 0 has invalid symbol index 11
/usr/bin/ld: /usr/lib/debug/usr/lib/x86_64-linux-gnu/crt1.o(.debug_info): relocation 1 has invalid symbol index 12
/usr/bin/ld: /usr/lib/debug/usr/lib/x86_64-linux-gnu/crt1.o(.debug_info): relocation 2 has invalid symbol index 2
/usr/bin/ld: /usr/lib/debug/usr/lib/x86_64-linux-gnu/crt1.o(.debug_info): relocation 3 has invalid symbol index 2
/usr/bin/ld: /usr/lib/debug/usr/lib/x86_64-linux-gnu/crt1.o(.debug_info): relocation 4 has invalid symbol index 11
/usr/bin/ld: /usr/lib/debug/usr/lib/x86_64-linux-gnu/crt1.o(.debug_info): relocation 5 has invalid symbol index 13
/usr/bin/ld: /usr/lib/debug/usr/lib/x86_64-linux-gnu/crt1.o(.debug_info): relocation 6 has invalid symbol index 13
/usr/bin/ld: /usr/lib/debug/usr/lib/x86_64-linux-gnu/crt1.o(.debug_info): relocation 7 has invalid symbol index 13
/usr/bin/ld: /usr/lib/debug/usr/lib/x86_64-linux-gnu/crt1.o(.debug_info): relocation 8 has invalid symbol index 12
/usr/bin/ld: /usr/lib/debug/usr/lib/x86_64-linux-gnu/crt1.o(.debug_info): relocation 9 has invalid symbol index 13
/usr/bin/ld: /usr/lib/debug/usr/lib/x86_64-linux-gnu/crt1.o(.debug_info): relocation 10 has invalid symbol index 13
/usr/bin/ld: /usr/lib/debug/usr/lib/x86_64-linux-gnu/crt1.o(.debug_info): relocation 11 has invalid symbol index 13
/usr/bin/ld: /usr/lib/debug/usr/lib/x86_64-linux-gnu/crt1.o(.debug_info): relocation 12 has invalid symbol index 13
/usr/bin/ld: /usr/lib/debug/usr/lib/x86_64-linux-gnu/crt1.o(.debug_info): relocation 13 has invalid symbol index 13
/usr/bin/ld: /usr/lib/debug/usr/lib/x86_64-linux-gnu/crt1.o(.debug_info): relocation 14 has invalid symbol index 13
/usr/bin/ld: /usr/lib/debug/usr/lib/x86_64-linux-gnu/crt1.o(.debug_info): relocation 15 has invalid symbol index 13
/usr/bin/ld: /usr/lib/debug/usr/lib/x86_64-linux-gnu/crt1.o(.debug_info): relocation 16 has invalid symbol index 13
/usr/bin/ld: /usr/lib/debug/usr/lib/x86_64-linux-gnu/crt1.o(.debug_info): relocation 17 has invalid symbol index 13
/usr/bin/ld: /usr/lib/debug/usr/lib/x86_64-linux-gnu/crt1.o(.debug_info): relocation 18 has invalid symbol index 13
/usr/bin/ld: /usr/lib/debug/usr/lib/x86_64-linux-gnu/crt1.o(.debug_info): relocation 19 has invalid symbol index 21
/usr/bin/ld: /usr/lib/debug/usr/lib/x86_64-linux-gnu/crt1.o(.debug_line): relocation 0 has invalid symbol index 2
/usr/lib/gcc/x86_64-linux-gnu/4.8/../../../x86_64-linux-gnu/crt1.o: In function `_start':
(.text+0x20): undefined reference to `main'
collect2: error: ld returned 1 exit status

Can someone please help me ?

sehe
  • 328,274
  • 43
  • 416
  • 565
  • 1
    Is Boost linked correctly (see [this](http://stackoverflow.com/questions/13767699/boost-test-undefined-reference-errors))? Or does [this](http://stackoverflow.com/questions/7781374/boost-test-linking) help you? – TobiMcNamobi Apr 30 '15 at 11:22
  • 1
    @TobiMcNamobi Thanks, is does actually. I added `ADD_DEFINITIONS(-DBOOST_TEST_DYN_LINK)` as in second link and it worked. Also it works if i write `#include ` insted of `#include `. Could you explain why ? If you post your comment as answer, I'll mark as accepted. Thanks! – Виталик Бушаев Apr 30 '15 at 11:46
  • A search for "boost/test/included" provided [this](http://www.boost.org/doc/libs/1_43_0/libs/test/doc/html/utf/user-guide/usage-variants/single-header-variant.html) (among others). – TobiMcNamobi Apr 30 '15 at 12:33

1 Answers1

0

You wrote

#define BOOST_TEST_MODULE !

In the examples I have found BOOST_TEST_MODULE is defined as some valid identifier, e.g.

#define BOOST_TEST_MODULE MyModule

This works in my project as well. If you define your own main() function instead, I guess that BOOST_TEST_MODULE is not used at all which explains your result.

Further reference is found here.

TobiMcNamobi
  • 4,305
  • 2
  • 29
  • 51