简体   繁体   English

使用 Visual Studio 2019 和 cmake for x86 编译 pe-parse 库

[英]Compile pe-parse library with visual studio 2019 and cmake for x86

I'm trying to build pe-parse library to do some stuff.我正在尝试构建pe-parse库来做一些事情。 I have both Visual Studio 2019 and cmake installed in my desktop.我的桌面上安装了 Visual Studio 2019 和 cmake。 pe-parse library git says to compile library with command below. 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 ..

I only have Visual Studio 2019 so I compiled with cmake -G "Visual Studio 16 2019" -DCMAKE_BUILD_TYPE=Release .. .我只有 Visual Studio 2019,所以我用cmake -G "Visual Studio 16 2019" -DCMAKE_BUILD_TYPE=Release .. But, library is compiled for 64 bit computers so if I try to use in x86 it shows me the library is for x64 and fails with message below.但是,库是为 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

I've installed MSVC v141 - VS2107 C++ x64/x86 build tools(v14.16) but cmake -G "Visual Studio 15 2017" -DCMAKE_BUILD_TYPE=Release .. shows me error below.我已经安装了 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.

Do I have to install Visual Studio 2017 to build library for x86 system?我是否必须安装 Visual Studio 2017 才能为 x86 系统构建库?

According to the documentation, generator Visual Studio 16 2019 is not longer defaults to Win32 target platform:根据文档,生成器Visual Studio 16 2019不再默认为 Win32 目标平台:

The default target platform name (architecture) is that of the host and is provided in the CMAKE_VS_PLATFORM_NAME_DEFAULT variable.默认目标平台名称(架构)是主机的名称,并在CMAKE_VS_PLATFORM_NAME_DEFAULT变量中提供。

For build a project for Win32 on 64-bit host, just pass appropriate -A option:要在 64 位主机上为 Win32 构建项目,只需传递适当的-A选项:

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

Generators for previous Visual Studio versions still default to Win32.以前的Visual Studio 版本的生成器仍然默认为 Win32。 Eg documentation for generator Visual Studio 15 2017 says:例如,生成器Visual Studio 15 2017 的文档说:

The default target platform name (architecture) is Win32.默认目标平台名称(体系结构)是 Win32。

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

相关问题 用 CMake 和 Visual Studio 2019 编译 GLEW? - Compile GLEW with CMake and Visual Studio 2019? 调试X86生成的Visual Studio链接器错误 - Visual Studio Linker Error for Debug X86 Build 如何在 Visual Studio 2019 cmake 项目中附加到 WSL 共享库 - How to attach to WSL shared library in Visual Studio 2019 cmake project Visual Studio 2015上的log10()性能比Visual Studio 2013 for x86慢很多 - log10() performance on Visual Studio 2015 a lot slower than Visual Studio 2013 for x86 使用Visual Studio 2008从x86编译x64 dll - Compiling x64 dll from x86 using Visual Studio 2008 Visual Studio 2019 编译构建 - Visual studio 2019 compile and build Visual Studio 2010 X86版本忽略#pragma警告和/ W0 C ++ - Visual Studio 2010 X86 Release ignoring #pragma warnings and /W0 C++ 在Win 7 64位上在Visual Studio 2012中编写x86汇编代码时遇到的问题 - problems in writing x86 assembly code in visual studio 2012 on win 7 64 bit Visual Studio 2012本机C ++ DLL x86编译 - Visual Studio 2012 native C++ DLL x86 compilation 在 Microsoft Visual Studio 的 x86 C++ 应用程序中集成犰狳 - Integration of Armadillo in x86 C++ Application in Microsoft Visual Studio
 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM