macOS 10.13安装Caffe时x86_64架构未定义符号错误解决
Hey, I’ve dealt with this exact Protobuf-related linking issue when setting up Caffe on macOS High Sierra before—let me walk you through how to resolve it.
First, let’s break down the problem: those undefined symbols all point to mismatched Protobuf library linking. This usually happens because either:
- Caffe isn’t properly pointing to your installed Protobuf files during compilation, or
- Protobuf was compiled with a different C++ standard library than the one Caffe is using (a common pitfall on macOS with
libc++vslibstdc++).
Here’s how to fix it step by step:
1. Verify Protobuf’s Compiled Standard Library
First, check which C++ standard library your Protobuf installation uses. On High Sierra, Clang defaults to libc++, but if you compiled Protobuf manually with libstdc++, that’s the conflict.
Run this command to check:
otool -L $(which protoc) | grep libc++
If you see libc++.dylib in the output, you’re good. If you see libstdc++.dylib, you’ll need to recompile Protobuf with libc++ (or adjust Caffe to match—though libc++ is the safer default for modern macOS).
2. Update Caffe’s Makefile.config
Head to your Caffe root directory and open Makefile.config in a text editor. Make these key changes:
a. Set Correct Protobuf Paths
Uncomment and specify the paths to your Protobuf installation (Homebrew defaults to /usr/local, so this should work unless you installed it elsewhere):
PROTOBUF_INCLUDE := /usr/local/include PROTOBUF_LIB := /usr/local/lib
b. Force Consistent Standard Library
Add this line to ensure Caffe uses the same libc++ standard library as your Protobuf:
CXXFLAGS += -stdlib=libc++
If there’s already a CXXFLAGS line in your config, make sure it includes -stdlib=libc++ (don’t duplicate the flag—just append it if missing).
c. Ensure Protobuf is Linked
Double-check that protobuf is listed in the LIBRARIES section:
LIBRARIES += glog gflags protobuf boost_system boost_filesystem m hdf5_hl hdf5
3. Recompile Caffe from Scratch
First, clean up any leftover build files to avoid conflicts:
make clean
Then compile with parallel processing (using all your CPU cores for speed):
make all -j$(sysctl -n hw.ncpu) make test -j$(sysctl -n hw.ncpu) make runtest -j$(sysctl -n hw.ncpu)
Extra Troubleshooting Tips
- If you installed Protobuf via Homebrew, make sure there’s no conflicting manual installation:
brew list protobuf # If you see multiple versions, uninstall and reinstall to reset brew uninstall --force protobuf brew install protobuf - Confirm all Caffe dependencies (like Boost, HDF5) are compiled with
libc++—Homebrew-installed versions should already use this, so if you built any dependencies manually, double-check their compile flags.
内容的提问来源于stack exchange,提问作者Cow

