Telling g++ about homebrew-installed lib

I’ve been having fun looking at some code created by a friend/ex-coworker, including https://github.com/hfgong/walker_vose. It makes use of the beloved to me GoogleTest C++ test framework.

I guess probably the right thing to do is to set things up via one of the methods mentioned in the GoogleTest docs, Bazel or CMake. (I was very interested to learn of https://registry.bazel.build/ via that page. How does it compare with https://conan.io/ and https://vcpkg.io/? What do you use?)

But feeling lazy, I just installed it via Homebrew:

brew install googletest

It’s been a while since I had to point g++ (or really Clang) to a custom location for headers and libs so I asked Gemini about it. I was pleased that Gemini gave me a couple options that didn’t even require modifying the Makefile. Even better.

export LIBRARY_PATH=$LIBRARY_PATH:/opt/homebrew/lib
export CPLUS_INCLUDE_PATH=$CPLUS_INCLUDE_PATH:/opt/homebrew/include

With that, the following worked:

% make test              
Running tests...
./build/test_walker_vose
[==========] Running 15 tests from 1 test suite.
[----------] Global test environment set-up.
[----------] 15 tests from WalkerVoseTest
[ RUN ] WalkerVoseTest.ConstructorDefault
[ OK ] WalkerVoseTest.ConstructorDefault (0 ms)
...
[ OK ] WalkerVoseTest.ClearAndReinitialize (0 ms)
[ RUN ] WalkerVoseTest.TypeAlias
[ OK ] WalkerVoseTest.TypeAlias (0 ms)
[----------] 15 tests from WalkerVoseTest (10 ms total)

[----------] Global test environment tear-down
[==========] 15 tests from 1 test suite ran. (10 ms total)
[ PASSED ] 15 tests.

Beautiful!

And I’m happy to see that things go back to failing to build after I do the following:

brew uninstall googletest
make clean
make test

I’m happy to be able to run the tests even if in a slightly hacky way. And I’m also happy to be set up to use GoogleTest in my own code, though I’ll also be mindful of it being a good idea to explore what other options are out there.


Comments

Leave a Reply

Your email address will not be published. Required fields are marked *