2
votes

I'm trying to build pe-parse library to do some stuff. I have both Visual Studio 2019 and cmake installed in my desktop. pe-parse library git says to compile library with command below.

# 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 ... 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.

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.

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?

1

1 Answers

-1
votes

According to the documentation, generator Visual Studio 16 2019 is not longer defaults to Win32 target platform:

The default target platform name (architecture) is that of the host and is provided in the CMAKE_VS_PLATFORM_NAME_DEFAULT variable.

For build a project for Win32 on 64-bit host, just pass appropriate -A option:

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

Generators for previous Visual Studio versions still default to Win32. E.g. documentation for generator Visual Studio 15 2017 says:

The default target platform name (architecture) is Win32.