Unable to test Godot GDExtension -- undefined reference to symbol


I am trying to add doctest unit testing to my Godot GDExtension project with CMake. I am pretty sure my CMakeLists.txt is accurate, but I’m a CMake newb.

A minimally viable project is available at GitHub - cyberpuffin-digital/gdexample at doctest. The tests reside in a test folder and the build directory of .cmake. The project’s Makefile contains targets for building the various components.

Executing the tests target completes gdexample/test/CMakeLists.txt at doctest · cyberpuffin-digital/gdexample · GitHub up to the point of linking the test file before spitting out a bunch of text. Towards the end, I see several errors like:

/usr/bin/ld: test_gdexample.cpp:(.text+0x15eb3): undefined reference to `godot::GDExample::is_prime(int)'

I’ve linked to the built object and its header files to make the publicly scoped function visible.

This was also done in Linux and I’m running tests on Windows to ensure the build process is working.

Any help or guidance would be appreciated.

FYI: This discussion is also present in the Godot discourse: Adding doctest to GDExtension for unit testing - Programming - Godot Forum.