简体   繁体   中英

Fixing pkg-config using Apple silicon and homebrew

I am working with C++ on an M1 Mac, and I used Time Machine to get my old laptop's data on the new one once I got it. The old laptop was not an Apple silicon MacBook. The problem is that I think this screwed up my homebrew installation, since it changed the default location from /usr/local/Cellar/ to /opt/homebrew/Cellar/ and so now I have two homebrew versions since I installed it again on my new laptop after I got it (since nothing was working with homebrew at first and thought it didn't carry over using Time Machine, oops)

I didn't use homebrew much until recently so I didn't notice, but it has made compiling C++ programs with external libraries very difficult since everything I need is on my new homebrew installation in /opt/homebrew/Cellar/ except pkg-config , which when I call it in a bash script or on the command line points to my old homebrew installation.

For example, I have pugixml in my new installation of homebrew and when I enter pkg-config --libs --cflags pugixml

Package pugixml was not found in the pkg-config search path.
Perhaps you should add the directory containing `pugixml.pc'
to the PKG_CONFIG_PATH environment variable
No package 'pugixml' found

pkg-config finds the libraries in the older homebrew installation just fine

My only alternative is to manually inspect the .pc files in the new homebrew installation and enter the flags in my Makefile. I would prefer not to do this. What's the best way to make sure that pkg-config works correctly? If someone knows how to get the new installation of pkg-config to be used at the command line that would solve all my problems I have right now

edit: I forgot to mention this - when I use the which command and ask which pkg-config it outputs /opt/homebrew/bin/pkg-config . This is sort of confusing since this is the new location

Remove the old (Intel) installation with the official uninstall script .

You have to make it executable with:

chmod +x uninstall.sh

And run it with

./uninstall.sh --path=/usr/local

Then reinstall everything you need on the new M1 version under /opt/homebrew .

The technical post webpages of this site follow the CC BY-SA 4.0 protocol. If you need to reprint, please indicate the site URL or the original address.Any question please contact:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM