【发布时间】:2021-01-19 20:21:33
【问题描述】:
我正在尝试了解如何通过 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”中。我错过了什么?
【问题讨论】:
-
能否在
get_filename_component和find_package行之间添加message( "PARENT_DIR_INSTALL_PREFIX=${PARENT_DIR_INSTALL_PREFIX}" )并发布运行cmake 时显示的内容? -
PARENT_DIR_INSTALL_PREFIX=C:/程序文件 (x86)。 yaml 正在安装在 C:\Program Files (x86)\YAML_CPP 中。在 bin 文件夹中,我有 yaml-cpp.dll 和 yaml-cppd.lib。在 lib 文件夹中,我有 yaml-cpp.dll 和 yaml-cppd.lib。
-
你试过
target_link_libraries(test debug ${PARENT_DIR_INSTALL_PREFIX}/YAML_CPP/lib/yaml-cppd.lib optimized ${PARENT_DIR_INSTALL_PREFIX}/YAML_CPP/lib/yaml-cpp.lib)吗?
标签: c++ visual-studio yaml-cpp