I am trying to use GoogleTest to test a simple function, but as I run make
in my build folder, the compiler throws Undefined Reference
error messag
Put the libgtest.a
after your object files
If you are doing things manually instead of with CMake, make sure to do:
g++ main.cpp googletest/build/lib/libgtest.a
instead of:
g++ googletest/build/lib/libgtest.a main.cpp
Here's a full working example I've tested with: https://askubuntu.com/questions/97626/how-to-install-googletest/1295185#1295185
This problem is not exclusive to GoogleTest: I can also reproduce it with a minimal library example like this one and Eli explainss the ordering rules which I don't have the patience to learn right now.