簡體   English   中英

g ++在/ usr / local / lib中找不到庫

[英]g++ not finding library in /usr/local/lib

我正在嘗試讓g ++自行查找glog (OS X 10.11.5)。 我安裝了glog(嘗試了來自github pull的cmake以及brew install-兩種情況下的結果相同)。 然后,我嘗試編譯該文件:

#include <glog/logging.h>

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

通過運行g++ -lglog -I/usr/local/include test.cpp

失敗並顯示以下錯誤:

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

但是,當我使用g++ -L/usr/local/lib -lglog -I/usr/local/include test.cpp它可以正常工作。

我嘗試將/usr/local/lib到LD_LIBRARY_PATH中無濟於事。

通常,我不會介意,但是我使用的是CMake(可以很好地找到glog),並且我不想在其中“硬編碼”庫路徑以使其可移植。 我之前曾在另一台Mac上嘗試過此方法,但效果很好,所以我不確定發生了什么。 有什么建議解決這個問題嗎?

找到了潛在的解決方案:

export LIBRARY_PATH=/usr/local/lib

不知道這是否是最好的解決方案,但它現在可以使用。 我可以將它放在我的.bashrc中。

更新:在macOS上,如果您運行xcode-select --install它將解決這些問題。

暫無
暫無

聲明:本站的技術帖子網頁,遵循CC BY-SA 4.0協議,如果您需要轉載,請注明本站網址或者原文地址。任何問題請咨詢:yoyou2525@163.com.

 
粵ICP備18138465號  © 2020-2024 STACKOOM.COM