Windows下CMake构建ympd时LibMPDClient未找到的参数配置求助
Hey there, I’ve been in your exact spot before—frustrated that CMake can’t find a dependency you’ve already spent time compiling. Let’s walk through a few straightforward ways to point CMake straight to your libmpdclient files and get that ympd build rolling.
Option 1: Specify Paths Directly in the CMake Command Line
This is the quickest fix. When running cmake .. from your ympd build directory, add two command-line arguments to explicitly tell CMake where to find the library and its headers:
cmake .. -DLIBMPDCLIENT_LIBRARY="C:/your/path/to/mpd/ympd/libmpdclient-2.13/libmpdclient-2.lib" -DLIBMPDCLIENT_INCLUDE_DIR="C:/your/path/to/mpd/ympd/libmpdclient-2.13/include"
Quick Notes:
- Swap out the example paths with your actual file locations. On Windows, use forward slashes (
/) or double backslashes (\\) to avoid CMake parsing errors. - Critical: CMake needs a linker input file (like a
.libimport library) for linking, not the.dlldirectly. Check yourlibmpdclient-2.13folder (especially the.outputsubdirectory) for a.libfile—use that path forLIBMPDCLIENT_LIBRARYif it exists. The.dllwill only be needed when running ympd later.
Option 2: Edit the CMakeCache.txt File
If you’ve already run cmake .. once, your build directory will have a CMakeCache.txt file. You can manually update the missing paths here:
- Open
CMakeCache.txtin a text editor. - Search for lines starting with
LIBMPDCLIENT_LIBRARY:andLIBMPDCLIENT_INCLUDE_DIR:. - Replace their empty or incorrect values with your actual paths, like this:
LIBMPDCLIENT_LIBRARY:FILEPATH=C:/your/path/to/libmpdclient-2.13/libmpdclient-2.lib LIBMPDCLIENT_INCLUDE_DIR:PATH=C:/your/path/to/libmpdclient-2.13/include - Save the file and re-run
cmake ..—CMake will pick up the corrected paths immediately.
Option 3: Tweak the FindLibMPDClient.cmake File
Since you have the FindLibMPDClient.cmake in your ympd cmake directory, you can modify it to automatically search your local libmpdclient folder:
- Open
mpd/ympd/cmake/FindLibMPDClient.cmake. - Add this line near the top to set a root path for your local libmpdclient installation:
set(LIBMPDCLIENT_ROOT "${CMAKE_SOURCE_DIR}/libmpdclient-2.13" CACHE PATH "Local libmpdclient directory") - Update the
find_pathandfind_librarycalls to include this root as a priority search location:find_path(LIBMPDCLIENT_INCLUDE_DIR NAMES mpd/client.h HINTS ${LIBMPDCLIENT_ROOT}/include) find_library(LIBMPDCLIENT_LIBRARY NAMES libmpdclient-2 mpdclient HINTS ${LIBMPDCLIENT_ROOT} ${LIBMPDCLIENT_ROOT}/.output) - Save the file, then re-run
cmake ..from your build directory. CMake will now check your local libmpdclient folder first before searching system paths.
Final Quick Checks
- Make sure the
includedirectory in your libmpdclient folder contains thempd/client.hheader. If the header is nested deeper (like insrc/mpd), adjustLIBMPDCLIENT_INCLUDE_DIRto point to the parent folder of thempdsubdirectory. - If you built libmpdclient as a static library, double-check that the
.libfile matches the build type (Debug/Release) you’re using for ympd.
内容的提问来源于stack exchange,提问作者bierschi

