Search code examples
c++macosgccldglog

g++ not finding library in /usr/local/lib


I'm trying to get g++ to find glog on its own (OS X 10.11.5). I installed glog (tried with both cmake from a github pull as well as brew install - same result in both cases). Then I tried to compile this file:

#include <glog/logging.h>

int main(int argc, char** argv) {
  int* x = nullptr;
  CHECK_NOTNULL(x);
  return 0;
}

by running g++ -lglog -I/usr/local/include test.cpp

This fails with the following error:

ld: library not found for -lglog
clang: error: linker command failed with exit code 1 (use -v to see invocation)

However, when I compile with g++ -L/usr/local/lib -lglog -I/usr/local/include test.cpp it works fine.

I tried adding /usr/local/lib into my LD_LIBRARY_PATH to no avail.

Normally, I wouldn't mind, but I'm using CMake (which finds glog just fine), and I don't want to "hardcode" library paths in there so that it's portable. I tried this before on another Mac and it worked fine, so I'm not sure what's going on. Any advice on fixing this?


Solution

  • Found a potential solution:

    export LIBRARY_PATH=/usr/local/lib
    

    Not sure if this is the best solution but it works for now. I can put this locally in my .bashrc.

    UPDATE: On macOS if you run xcode-select --install it should fix these issues.