【问题标题】:Compile pe-parse library with visual studio 2019 and cmake for x86使用 Visual Studio 2019 和 cmake for x86 编译 pe-parse 库
【发布时间】:2020-04-28 16:22:51
【问题描述】:

我正在尝试构建pe-parse 库来做一些事情。我的桌面上安装了 Visual Studio 2019 和 cmake。 pe-parse library git 说用下面的命令编译库。

# Compile 64-bit binaries with Visual Studio 2017
cmake -G "Visual Studio 15 2017 Win64" -DCMAKE_BUILD_TYPE=Release ..

# Compile 32-bit binaries with Visual Studio 2017
cmake -G "Visual Studio 15 2017" -DCMAKE_BUILD_TYPE=Release ..

我只有 Visual Studio 2019,所以我用 cmake -G "Visual Studio 16 2019" -DCMAKE_BUILD_TYPE=Release .. 编译。但是,库是为 64 位计算机编译的,所以如果我尝试在 x86 中使用,它会显示该库是针对 x64 的,并且失败并显示以下消息。

1>main.obj : error LNK2019: unresolved external symbol "struct peparse::_parsed_pe * __cdecl peparse::ParsePEFromFile(char const *)" (?ParsePEFromFile@peparse@@YAPAU_parsed_pe@1@PBD@Z) referenced in function _main
1>lib\pe-parser-library.lib : warning LNK4272: library machine type 'x64' conflicts with target machine type 'x86'
1>C:\Workspace\Windows\CPP\MalwareAnalysis\Debug\MalwareAnalysis.exe : fatal error LNK1120: 1 unresolved externals

我已经安装了 MSVC v141 - VS2107 C++ x64/x86 构建工具(v14.16),但cmake -G "Visual Studio 15 2017" -DCMAKE_BUILD_TYPE=Release .. 在下面显示错误。

CMake Error at CMakeLists.txt:2 (project):
  Generator

    Visual Studio 15 2017

  could not find any instance of Visual Studio.

是否必须安装 Visual Studio 2017 才能为 x86 系统构建库?

【问题讨论】:

    标签: c++ visual-studio cmake static-libraries


    【解决方案1】:

    根据文档,生成器Visual Studio 16 2019 不再默认为 Win32 目标平台:

    默认的目标平台名称(架构)是主机的名称,并在CMAKE_VS_PLATFORM_NAME_DEFAULT 变量中提供。

    要在 64 位主机上为 Win32 构建项目,只需传递适当的 -A 选项:

    cmake -G "Visual Studio 16 2019" -A Win32 <other options>
    

    以前的 Visual Studio 版本的生成器仍默认为 Win32。例如。生成器Visual Studio 15 2017 的文档说:

    默认的目标平台名称(架构)是 Win32。

    【讨论】:

    • cmake -G "Visual Studio 16 2019" -A Win32 host=x86 使用这个仍然无法设置 hostx86 并得到相同的链接器错误。
    • 根据your self-answer,问题不在cmake参数中,而是在cmake-js包装器中。
    猜你喜欢
    • 1970-01-01
    • 1970-01-01
    • 1970-01-01
    • 2021-01-16
    • 2020-03-26
    • 1970-01-01
    • 2019-06-07
    • 1970-01-01
    • 2022-09-24
    相关资源
    最近更新 更多