MacOS系统CLion中链接Folly失败问题排查求助
Let's break down the possible issues and fixes step by step, since you've already confirmed Folly is installed at /usr/local/Cellar/folly/2017.10.23.00 but CMake still can't find it in CLion:
1. You're setting folly_DIR to the wrong directory
CMake doesn't look for Folly directly in the main Cellar folder—it needs the subdirectory containing Folly's CMake config files. These files are usually named something like FollyConfig.cmake or folly-config.cmake.
First, run this command in your terminal to locate the correct path:
find /usr/local/Cellar/folly/2017.10.23.00 -name "*FollyConfig.cmake"
For most Homebrew-installed Folly versions, this path will be something like /usr/local/Cellar/folly/2017.10.23.00/lib/cmake/Folly. Update your folly_DIR to point to this exact directory, not the root Folly folder.
2. Your CMakeLists.txt syntax has case or command issues
Double-check how you're calling find_package after setting folly_DIR. Folly's CMake config is often case-sensitive—try:
set(folly_DIR "/path/to/your/found/FollyConfig.cmake/directory") find_package(Folly REQUIRED) # Note the uppercase "F"
If you used find_package(folly REQUIRED) (lowercase), that might be the mismatch, since the config file uses uppercase in its name.
3. CLion is using an incompatible CMake version
Folly 2017.10.23.00 requires a minimum CMake version (usually 3.5 or higher). To check CLion's CMake version:
- Go to
Settings > Build, Execution, Deployment > CMake - Look at the "CMake executable" field and verify its version with
cmake --versionin your terminal.
If CLion is using an older version, update CMake (via Homebrew or the official website) and point CLion to the updated executable.
4. Missing dependencies are blocking Folly detection
Folly has several hard dependencies (like gflags, glog, Boost, and libevent). Even if Folly is installed, if CMake can't find one of its dependencies, it will fail to detect Folly entirely.
Check CLion's CMake output log (in the "Build" tab) for specific error messages like "Could NOT find Gflags" or "Boost not found". Install any missing dependencies via Homebrew (e.g., brew install gflags glog boost) and re-run CMake.
5. Fallback: Manually link Folly (if all else fails)
If the find_package approach still doesn't work, you can bypass CMake's package detection and manually specify the include and library paths:
# Add Folly's include directory include_directories(/usr/local/Cellar/folly/2017.10.23.00/include) # Add Folly's library directory link_directories(/usr/local/Cellar/folly/2017.10.23.00/lib) # Link your target against Folly target_link_libraries(HelloWorld folly)
This is less clean than using find_package, but it will confirm if your project can actually access the installed Folly files.
内容的提问来源于stack exchange,提问作者RandomQuestion

