Undefined references when trying to add (auto)tests to EventViews

kdenis at posteo.de kdenis at posteo.de
Fri Jan 12 14:12:55 GMT 2018


Hi. I tried to write some tests for the eventviews library, but could not get 
past some undefined reference errors.
Here is a minimized version of what I tried.

I added a new directory "autotests" and the line "add_subdirectory(autotests)" 
in /CMakeLists.txt, right below "add_subdirectory(tests)".
Then, I created the file "autotests/incidencetreemodel_test.cpp":

>>>
#include <todo/incidencetreemodel.h>
int main() {
	IncidenceTreeModel model;
}
<<<

and the file "autotests/CMakeLists.txt":

>>>
add_executable(incidencetreemodel_test incidencetreemodel_test.cpp)
target_link_libraries(incidencetreemodel_test KF5EventViews)
<<<

It compiles just fine, but linking fails with:

>>>
[ 90%] Linking CXX executable ../bin/incidencetreemodel_test
CMakeFiles/incidencetreemodel_test.dir/incidencetreemodel_test.cpp.o: In 
function `main':
/home/kde/test/eventviews/autotests/incidencetreemodel_test.cpp:28: undefined 
reference to `IncidenceTreeModel::IncidenceTreeModel(QObject*)'
/home/kde/test/eventviews/autotests/incidencetreemodel_test.cpp:28: undefined 
reference to `IncidenceTreeModel::~IncidenceTreeModel()'
collect2: error: ld returned 1 exit status
make[2]: *** [autotests/CMakeFiles/incidencetreemodel_test.dir/build.make:121: 
bin/incidencetreemodel_test] Error 1
make[1]: *** [CMakeFiles/Makefile2:329: autotests/CMakeFiles/
incidencetreemodel_test.dir/all] Error 2
make: *** [Makefile:141: all] Error 2
<<<

todo/incidencetreemodel.cpp is one of the source files added to KF5EventViews, 
and I linked my test binary to KF5EventViews.
CMake seems to set include directories correctly, too, since <todo/
incidencetreemodel.h> (and the class IncidenceTreeModel) is found.

Can anyone please help me fix this problem?



More information about the kde-pim mailing list