Xcode9.2编译报错:找不到-lopencv_core.3.3.1库,已装OpenCV3.4.0求助
Let’s work through this linker error — your hunch about version mismatch is totally correct. Here’s how to resolve it step by step:
1. Check for hardcoded version references in your project
First, double-check your Other Linker Flags in Xcode. If you’ve explicitly added -lopencv_core.3.3.1, that’s the root issue. Replace it with either:
-lopencv_core(uses the default symlinked version in your OpenCV install)-lopencv_core.3.4.0(matches your installed 3.4.0 version)
You can confirm the exact library filename by running this in Terminal:
ls /usr/local/Cellar/opencv/3.4.0_1/lib | grep opencv_core
You should see something like libopencv_core.3.4.0.dylib — use that version suffix if you go with the explicit flag.
2. Clean Xcode’s cached data
Xcode often holds onto old dependency paths or cached builds, which can cause issues even after you update settings. To fix this:
- Open Xcode, go to Xcode > Preferences > Locations
- Under Derived Data, click the arrow icon to open the folder
- Delete the folder corresponding to your project
- Quit and restart Xcode, then do a full clean (
Cmd+Shift+K) before rebuilding
3. Verify your Library Search Paths and linked frameworks
Even though you’ve set the path, make sure:
- Your Library Search Paths points directly to
/usr/local/Cellar/opencv/3.4.0_1/lib(not just/usr/local/lib— symlinks can sometimes cause confusion) - In Linked Frameworks and Libraries, you’ve added the actual
.dylibfiles from the 3.4.0_1 folder, not any leftover 3.3.1 files that might still be on your system
4. Hunt for leftover old OpenCV files
If uninstalling/reinstalling didn’t clear everything, check for residual 3.3.1 files:
Run this in Terminal to find all OpenCV core libraries:
find /usr -name "libopencv_core*.dylib" 2>/dev/null
If you see any files with 3.3.1 in the name, delete them (you’ll need sudo for system-level files):
sudo rm /path/to/libopencv_core.3.3.1.dylib
5. Check for third-party dependencies
If your project uses any external libraries or pods that depend on OpenCV 3.3.1, those could be forcing the linker to look for the old version. Double-check your Podfile or any imported frameworks to ensure they’re compatible with 3.4.0.
Give these steps a try — the most likely fix is updating the hardcoded linker flag and clearing Xcode’s cache. Let me know if you hit any snags!
内容的提问来源于stack exchange,提问作者Braandyy_

