You need to enable JavaScript to run this app.
优惠活动
大模型
产品
解决方案
定价
更多

Windows新手求助:yaml-cpp源码生成DLL及使用方法(VS2015)

Hey there! I totally get how frustrating it is when you've nailed building yaml-cpp on Ubuntu but hit a brick wall on Windows—especially with Visual Studio 2015, which has its own set of quirks. Let's walk through this step by step to get a working DLL built and integrated into your project, no missing pieces this time.

Step 1: Prepare the yaml-cpp Source Code

Grab the yaml-cpp source code (version 0.6.3 is recommended for better compatibility with VS 2015) and extract it to a folder on your Windows machine—say, C:\yaml-cpp-src. This version plays nicely with older VS versions without requiring too many modern C++ features that might cause issues.

Step 2: Configure the Build with CMake

yaml-cpp uses CMake to generate project files, so you'll need a compatible version of CMake (3.17.x or newer works well with VS 2015). Here's how to set it up:

  • Open the CMake GUI.
  • In the "Where is the source code" field, browse to your extracted yaml-cpp folder (C:\yaml-cpp-src).
  • In the "Where to build the binaries" field, create a new folder (e.g., C:\yaml-cpp-build)—this keeps your source code clean from build artifacts.
  • Click "Configure". When prompted, select Visual Studio 14 2015 as the generator, choose either "Win32" or "x64" depending on your project's architecture, then click "Finish".
  • Wait for the initial configuration to complete. Then, find these variables in the list and tweak them:
    • Set BUILD_SHARED_LIBS to ON—this tells CMake to build a DLL instead of a static library.
    • Set YAML_CPP_BUILD_TESTS to OFF (optional, but saves build time by skipping the test suite).
  • Click "Configure" again to apply these changes, then click "Generate" to create the Visual Studio solution files.
Step 3: Build the DLL in Visual Studio 2015

Now let's turn those generated files into a working DLL:

  • Navigate to your build folder (C:\yaml-cpp-build) and open yaml-cpp.sln with VS 2015.
  • In the top menu bar, set the build configuration to Release (or "Debug" if you need debug symbols—just remember to match this with your project later).
  • Right-click the yaml-cpp project in the Solution Explorer and select "Build".
  • Once the build finishes, you'll find your files in the build output folder:
    • Release: C:\yaml-cpp-build\Release\yaml-cpp.dll (the actual DLL) and yaml-cpp.lib (the import library your project will link against)
    • Debug: C:\yaml-cpp-build\Debug\yaml-cppd.dll and yaml-cppd.lib (note the 'd' suffix for debug builds)
Step 4: Integrate the DLL and Headers into Your Project

Now let's set up your project to use yaml-cpp:

  1. Organize your files (optional but keeps things tidy):
    • Create a folder like C:\yaml-cpp with two subfolders: include and lib.
    • Copy the entire yaml-cpp folder from C:\yaml-cpp-src\include into C:\yaml-cpp\include—this contains all the header files you'll need.
    • Copy the appropriate import library (yaml-cpp.lib for Release, yaml-cppd.lib for Debug) into C:\yaml-cpp\lib.
    • Copy the corresponding DLL (yaml-cpp.dll or yaml-cppd.dll) to your project's output directory (where your .exe gets built) or add its folder to your system PATH—this ensures Windows can find it when your program runs.
  2. Configure your VS project settings:
    • Right-click your project in the Solution Explorer and select "Properties".
    • Under "Configuration Properties":
      • C/C++ > General: Add C:\yaml-cpp\include to the "Additional Include Directories" field.
      • Linker > General: Add C:\yaml-cpp\lib to the "Additional Library Directories" field.
      • Linker > Input: Add yaml-cpp.lib (Release) or yaml-cppd.lib (Debug) to the "Additional Dependencies" field.
    • Make sure to apply these settings to both "Release" and "Debug" configurations if you use both.
  3. Test with sample code:
    Add this simple snippet to your project to verify everything works:
    #include <iostream>
    #include "yaml-cpp/yaml.h"
    
    int main() {
        YAML::Node config = YAML::Load("{name: John, age: 30}");
        std::cout << "Name: " << config["name"].as<std::string>() << std::endl;
        std::cout << "Age: " << config["age"].as<int>() << std::endl;
        return 0;
    }
    
    Build and run your project—if it prints out the name and age correctly, you're good to go!
Quick Troubleshooting Tips
  • If you get linker errors, double-check that your project's architecture (x86/x64) matches the one you used to build the DLL.
  • If your program crashes or says it can't find the DLL at runtime, make sure the DLL file is in the same folder as your executable or in a directory listed in your system PATH.
  • Ensure VS 2015 is updated to Service Pack 1—this fixes a lot of compatibility issues with CMake-generated projects.

内容的提问来源于stack exchange,提问作者Izik

相关产品推荐
方舟 Agent Plan

超全模态模型 × Harness 升级,最新支持 Deepseek-V4.1-Flash、GLM-5.3 系列、Doubao-Seedream-5.0-pro、Kimi-K3 (部分), 限时 9.9 元起

最近更新时间:2026.05.22 09:03:00