c++ - trouble linking cpp/hpp from cmake -
c++ - trouble linking cpp/hpp from cmake -
there's zillions of questions on this, nil have read has helped me resolve problem, apologies in advance if (most likely) have missed something.
i working on unit testing on big project, there multiple cmakelists.txt files. created "utilities.cpp" file grew quickly, decided split test_utilities.cpp , test_utilities.hpp. when #include test_utilities.cpp
there joy, if #include test_utilities.hpp
build fails:
linking cxx executable foo cmakefiles/foo.dir/src/foo.cpp.o: in function `foo::bar()': /mydir/trunk/tests/src/foo.cpp:57: undefined reference `exit_on_invalid_config(std::vector<std::basic_string<char, std::char_traits<char>, std::allocator<char> >, std::allocator<std::basic_string<char, std::char_traits<char>, std::allocator<char> > > >&)' collect2: ld returned 1 exit status make[2]: *** [tests/foo] error 1 make[1]: *** [tests/cmakefiles/foo.dir/all] error 2 make: *** [all] error 2
i think because hpp , cpp not beingness linked.
i have tried adding cmakelists.txt:
add_executable(utilities src/test_utilities.cpp src/test_utilities.hpp) target_link_libraries(utilities some_project test_main boost_program_options)
(actually here before, minus hpp part, when including utilities.cpp, before added header file). alter not help, tried adding
add_library(test_utilities src/test_utilities.cpp src/test_utilities.hpp)
and included test_utilities target_link_libraries:
add_executable(foo src/foo.cpp) target_link_libraries(foo some_project test_main test_utilities boost_program_options)
but when seek this, zillions of errors boost crap beingness redefined. when remove boost imports foo.cpp, test_utilities.cpp/hpp either same output or complaints can't find boost definitions.
what cmake compile test_utilities executable (cpp + hpp) don't undefined reference when seek import test_utilities.hpp foo.cpp.
thanks in advance help.
edit: issue having is, i'll add together executable test_utilities, doesn't built before foo. sense part of problem , haven't figured out how test_utilities build first.
edit: got utilities build first using add_dependencies(foo utilities)
still getting undefined reference :(
edit: issue having is, build fails because getting "multiple definition of" boost. forever.
edit: resolved!!!!! wojciii!!! it's worth, issue boiled downwards to, importing boost unit test in test_utilities.cpp, test_main.cpp, , foo.cpp. needed stop doing that, prepare dependency issues in hpp, , tweak cmakelists.txt little.
c++ boost cmake
Comments
Post a Comment