NOTE: William has updated his example code, so the following bugs have been fixed. Target_link_libraries(test_myPackage myPackage_lib) In case it's helpful, here's the relevant section of my CMakeLists.txt: catkin_add_gtest(test_myPackage test/utest.cpp) NOTE: I don't want the test executable or data-file to be installed in the final package. What is the best-practice for dealing with test data files under catkin? The build process does not copy my data file to this tree, so it is unclear how I should specify the relative path to my data file. In catkin, I run make run_tests and the working directory is in the catkin_ws/devel tree. So, I can reference the test data file using a relative path: test/test.dat. In rosbuild, I run tests using make test, and the working directory is the package root. This data file is in the same directory as my utest.cpp file: /test/test.dat. In one of the tests, I would like to read in an external data file to use in the test routine. I have set up my CMakeLists.txt to compile the unit-test program and link against my package library. In comparison, -lpthread will only do the second part, i.e.I am creating a Unit-Test program for my catkin package, using gtest.At link time, the linker will specifically link the resultant object.At compile time, -pthread manifests that the Pthread API is requestedĪnd defines platform-specific macros, such as _REENTRANT on Linux.The -pthread option sets flags for both the compiler preprocessor and linker.I went down the rabbit hole to discover the difference between -pthread and That, Linux machines should also make use of -pthread, according to the To both compile and link POSIX-compliant multi-threaded applications. Whether to use -lpthread or the compiler command line option -pthread.Īfter some digging, I discovered that clang compilers require using -pthread GTest requires Pthreads to compile, so it seemed like I need This resulted in linker errors and warnings about undefined references to The library needs to be in place to link against it, so first install theĬlang++ **/ *.cc -lgtest -lgtest_main &.To manually link against the test framework and produce a test executable thatĬan be run from the command line, do the following: The tools!) Manually Linking against GoogleTest (This is what I do for “fun”, in the workplace I play by the rules and use all Using the terminal and nothing else, I can avoid the overhead of an IDE andĬMake, and as a nice bonus, my directories are decluttered of IDE files. Projects like the ones I complete for my BSc. As a minimalist approach, it also works really well for small-scale It’s good to do things the hard way sometimes and good practice to remember You might think I’m a masochist for foregoing a standard setup in favour of It’s generally used with a build system like CMake or Bazel. GTestĬan be used for any kind of tests, not just unit tests, and has some niceįeatures like automatically detecting tests and playing nicely with your IDE. GoogleTest (or GTest) is Google’s testing and mocking framework for C++. ![]() Without CMake for small-scale C++ projects. In this post, I’m going to explain how I went back to basics and used Back to basics: using GoogleTest without CMake for C++ projects | TP Home Résumé About Blog Projects Back to basics: using GoogleTest without CMake for C++ projects 29 April 2021
0 Comments
Leave a Reply. |
AuthorWrite something about yourself. No need to be fancy, just an overview. ArchivesCategories |