问题描述
我试图了解如何在带有 Visual Studio 2019 的 windows 上使用我的 linux 项目。所以我为 yaml_cpp 编写了一个简单的测试:
#include "yaml-cpp/yaml.h"
#include <iostream>
#include <string>
#include <cassert>
int main()
{
try
{
assert(1 == 2);
YAML::Node config = YAML::LoadFile("config.yaml");
std::cerr << config["hello"].as<std::string>() << std::endl;
}
catch (std::exception& e)
{
std::cerr << "Caught " << e.what() << std::endl;
std::cerr << "Type " << typeid(e).name() << std::endl;
};
return 0;
}
我写了一个基本的 CMakeLists.txt 文件:
cmake_minimum_required(VERSION 3.1)
project (test)
set(CMAKE_CONFIGURATION_TYPES "Debug;Release" CACHE STRING "" FORCE)
get_filename_component(PARENT_DIR_INSTALL_PREFIX ${CMAKE_INSTALL_PREFIX} DIRECTORY)
find_package(yaml-cpp REQUIRED PATHS "${PARENT_DIR_INSTALL_PREFIX}/YAML_CPP/share/cmake/yaml-cpp")
add_executable(test
main.cpp)
target_include_directories(test
PUBLIC
${PARENT_DIR_INSTALL_PREFIX}/YAML_CPP/include >
)
target_link_libraries(test debug yaml-cppd optimized yaml-cpp)
我使用 cmake -G "Visual Studio 16 2019" -Ax64 ..
生成项目。该程序在 Release (cmake --build . --config Release
) 上编译并运行良好。但是在调试(cmake --build . --config Debug
,我有以下错误:
LINK : fatal error LNK1104: impossible d'ouvrir le fichier 'yaml-cppd.lib' [C:\Users\kafka\dev\C++\test\yaml_for_vs\bui
ld\test.vcxproj]
“Impossible d'ouvrir le fichier”表示无法打开文件“yaml-cppd.lib”。我已经在发布和调试中编译了 yaml-cpp,并且文件“yaml-cppd.lib”存在于“C:\Program Files (x86)\YAML_CPP\lib”中。我错过了什么?
解决方法
暂无找到可以解决该程序问题的有效方法,小编努力寻找整理中!
如果你已经找到好的解决方法,欢迎将解决方案带上本链接一起发送给小编。
小编邮箱:dio#foxmail.com (将#修改为@)