c++ - CMake cannot found libraries installed by brew - Stack Overflow

Idk why my previous topic was determined like 'question not related for programming and tools` but

Idk why my previous topic was determined like 'question not related for programming and tools` but I'll ask again and more accurate.

I moved from Windows to Mac and started working on my C++ project.

I installed brew, configured it and started to install libraries that I need.

  1. I installed openldap lib.
  2. Openldap installation hint helped me to add path into my ~./zshrc environment:
export PKG_CONFIG_PATH="/opt/homebrew/opt/openldap/lib/pkgconfig"

After that CMake successfully detected ldap, but when I installed hiredis, I got an error that hiredis can't be found. Again. So, then I moved to ~/.zshrc again and add another path and my PKG_CONFIG_PATH starts look like:

  export PKG_CONFIG_PATH="/opt/homebrew/opt/openldap/lib/pkgconfig":"/opt/homebrew/opt/hiredis/lib/pkgconfig"

To be honest, it's awful. After any brew installation I should always add new library path to help CMake detect it? Or there is more simple way for it?

Idk why my previous topic was determined like 'question not related for programming and tools` but I'll ask again and more accurate.

I moved from Windows to Mac and started working on my C++ project.

I installed brew, configured it and started to install libraries that I need.

  1. I installed openldap lib.
  2. Openldap installation hint helped me to add path into my ~./zshrc environment:
export PKG_CONFIG_PATH="/opt/homebrew/opt/openldap/lib/pkgconfig"

After that CMake successfully detected ldap, but when I installed hiredis, I got an error that hiredis can't be found. Again. So, then I moved to ~/.zshrc again and add another path and my PKG_CONFIG_PATH starts look like:

  export PKG_CONFIG_PATH="/opt/homebrew/opt/openldap/lib/pkgconfig":"/opt/homebrew/opt/hiredis/lib/pkgconfig"

To be honest, it's awful. After any brew installation I should always add new library path to help CMake detect it? Or there is more simple way for it?

Share Improve this question asked Mar 3 at 13:18 GrimlockGrimlock 1379 bronze badges 12
  • How exactly have you installed openldap library? The second opt/ in the path looks weird. – Tsyvarev Commented Mar 3 at 13:51
  • 4 you might have a better experience using a library manager like vcpkg or conan which have better cmake integration – Alan Birtles Commented Mar 3 at 15:26
  • 1 Can you show the actual CMakeLists.txt and cmake output log? Because homebrew installs symlinks to your pkgconfig files into /opt/homebrew/lib/pkgconfig, so that is the only path you should add to PKG_CONFIG_PATH. Moreover, on my system the PkgConfig module adapts to the paths of pkg-config, which includes that directory by default so you don't need the variable at all! – Botje Commented Mar 3 at 20:40
  • 1 @Grimlock this is highly unusual. does brew create the symlinks in /opt/homebrew/lib/pkgconfig if you call brew link hiredis yourself? – Botje Commented Mar 4 at 7:55
  • 1 Ah, but openldap is a special beast. The install log says so: openldap is keg-only, which means it was not symlinked into /opt/homebrew. So you still need to specify the PKG_CONFIG_PATH for openldap, but hiredis can be found as normal. – Botje Commented Mar 4 at 8:53
 |  Show 7 more comments

1 Answer 1

Reset to default 2

When installing packages, the homebrew package manager links files from the package-specific directory /opt/homebrew/Cellar/$PACKAGE/$VERSION/... into /opt/homebrew/{include,lib,share}.

Packages that ship a pkg-config .pc file (such as hiredis) end up linked into /opt/homebrew/lib/pkgconfig. The homebrew-supplied pkg-config knows to find them there, and CMake's FindPkgConfig calls pkg-config to find these packages.

However, some packages overlap system libraries / binaries and the Homebrew team does not do this automatic linking by default.

Openldap is one such package:

% brew info openldap
==> openldap: stable 2.6.9 (bottled) [keg-only]
...
==> Caveats
openldap is keg-only, which means it was not symlinked into /opt/homebrew,
because macOS already provides this software and installing another version in
parallel can cause all kinds of trouble.

If you need to have openldap first in your PATH, run:
  echo 'export PATH="/opt/homebrew/opt/openldap/bin:$PATH"' >> ~/.zshrc
  echo 'export PATH="/opt/homebrew/opt/openldap/sbin:$PATH"' >> ~/.zshrc

For compilers to find openldap you may need to set:
  export LDFLAGS="-L/opt/homebrew/opt/openldap/lib"
  export CPPFLAGS="-I/opt/homebrew/opt/openldap/include"

For pkg-config to find openldap you may need to set:
  export PKG_CONFIG_PATH="/opt/homebrew/opt/openldap/lib/pkgconfig"

For packages like these, you must explicitly tell pkg-config where to look. There are two options:

  1. set PKG_CONFIG_PATH before invoking CMake as above, or
  2. append /opt/homebrew to CMAKE_PREFIX_PATH. CMake will know to look under /opt/homebrew/lib/pkgconfig.

发布者:admin,转转请注明出处:http://www.yc00.com/questions/1745093039a4610808.html

相关推荐

  • c++ - CMake cannot found libraries installed by brew - Stack Overflow

    Idk why my previous topic was determined like 'question not related for programming and tools` but

    19小时前
    20

发表回复

评论列表(0条)

  • 暂无评论

联系我们

400-800-8888

在线咨询: QQ交谈

邮件:admin@example.com

工作时间:周一至周五,9:30-18:30,节假日休息

关注微信