我正在尝试建立pe-parse库来做一些事情。我的桌面上同时安装了Visual Studio 2019和cmake。 pe-parse库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系统构建库?
根据文档,对于Win32目标平台,生成器Visual Studio 16 2019 <]][默认目标平台名称(体系结构)是主机的名称,并在
CMAKE_VS_PLATFORM_NAME_DEFAULT
变量中提供。
要在64位主机上为Win32构建项目,只需传递适当的-A
选项:
cmake -G "Visual Studio 16 2019" -A Win32 <other options>
<< [previous]的生成器> Visual Studio版本仍默认为Win32。例如。生成器Visual Studio 15 2017的文档说:默认目标平台名称(体系结构)是Win32。