avast / retdec

RetDec is a retargetable machine-code decompiler based on LLVM.
https://retdec.com/
MIT License
7.93k stars 939 forks source link

Windows build fails with "patch is not recognized as an internal or external command" #50

Closed jazzl0ver closed 6 years ago

jazzl0ver commented 6 years ago

Docs state it's possible to build with any VS version after 2015. This happens with VS 2017 CE:

C:\retdec\build> cmake .. -DCMAKE_INSTALL_PREFIX=c:\retdec -G"Visual Studio 16 2017 Win64"
...
    59>C:\retdec\deps\capstone2llvmir\deps\llvm\src\lib\DebugInfo\PDB\DIA\DIASession.cpp(66): fatal error C1189: #error
       :  "Unknown Visual Studio version." [C:\retdec\build\deps\capstone2llvmir\deps\llvm\llvm-project-prefix\src\llvm
       -project-build\lib\DebugInfo\PDB\LLVMDebugInfoPDB.vcxproj] [c:\retdec\build\deps\capstone2llvmir\deps\llvm\llvm-
       project.vcxproj]
s3rvac commented 6 years ago

Hi. I believe that the correct generator for MSVC 2017 is -G"Visual Studio 15 2017 Win64". That is, try replacing 16 with 15.

jazzl0ver commented 6 years ago

I'm sorry, this is a typo - I did use Visual Studio 15 2017 Win64. It wouldn't run at all otherwise

metthal commented 6 years ago

We are aware of this issue and we are trying to solve it. There are some dependencies which still require VS2015 toolset to be installed. I don't know if there is any way to get that toolset into CE, but you can try installing VS2015 alongside VS2017, or just build our decompiler with VS2015 for now. We will hopefully also support VS2017 CE soon. Thank you for understanding.

jazzl0ver commented 6 years ago

@metthal , thanks for reply! I did install VS2015 toolset along with VS2017: image Unfortunately, I'm getting this one:

c:\retdec\build>cmake .. -DCMAKE_INSTALL_PREFIX=c:\retdec -G"Visual Studio 14 2015 Win64"
-- The CXX compiler identification is MSVC 19.0.24225.1
-- Check for working CXX compiler: C:/Program Files (x86)/Microsoft Visual Studio 14.0/VC/bin/x86_amd64/cl.exe
-- Check for working CXX compiler: C:/Program Files (x86)/Microsoft Visual Studio 14.0/VC/bin/x86_amd64/cl.exe -- works
-- Detecting CXX compiler ABI info
-- Detecting CXX compiler ABI info - done
-- Detecting CXX compile features
-- Detecting CXX compile features - done
-- Setting build type to 'Release' as none was specified.
-- The C compiler identification is MSVC 19.0.24225.1
-- Check for working C compiler: C:/Program Files (x86)/Microsoft Visual Studio 14.0/VC/bin/x86_amd64/cl.exe
-- Check for working C compiler: C:/Program Files (x86)/Microsoft Visual Studio 14.0/VC/bin/x86_amd64/cl.exe -- works
-- Detecting C compiler ABI info
-- Detecting C compiler ABI info - done
-- Detecting C compile features
-- Detecting C compile features - done
Enabling CAPSTONE_ARM_SUPPORT
Enabling CAPSTONE_ARM64_SUPPORT
Enabling CAPSTONE_M68K_SUPPORT
Enabling CAPSTONE_MIPS_SUPPORT
Enabling CAPSTONE_PPC_SUPPORT
Enabling CAPSTONE_SPARC_SUPPORT
Enabling CAPSTONE_SYSZ_SUPPORT
Enabling CAPSTONE_XCORE_SUPPORT
Enabling CAPSTONE_X86_SUPPORT
Enabling CAPSTONE_TMS320C64X_SUPPORT
Enabling CAPSTONE_M680X_SUPPORT
-- The ASM compiler identification is MSVC
-- Found assembler: C:/Program Files (x86)/Microsoft Visual Studio 14.0/VC/bin/x86_amd64/cl.exe
-- Warning: Did not find file Compiler/MSVC-ASM
-- Looking for dirent.h
-- Looking for dirent.h - not found
-- Looking for dlfcn.h
-- Looking for dlfcn.h - not found
-- Looking for errno.h
-- Looking for errno.h - found
-- Looking for execinfo.h
-- Looking for execinfo.h - not found
-- Looking for fcntl.h
-- Looking for fcntl.h - found
-- Looking for inttypes.h
-- Looking for inttypes.h - found
-- Looking for limits.h
-- Looking for limits.h - found
-- Looking for link.h
^C
c:\retdec\build>
metthal commented 6 years ago

I am not sure what to look at in the log. If you mean those not found messages, that is OK, nothing to worry about. That is just regular CMake output. It is trying to find the right headers for certain things.

s3rvac commented 6 years ago

There seems to be nothing wrong in the output. Did you kill cmake prematurely with Ctrl-C? The ^C at the end suggests that. Or did it hang?

jazzl0ver commented 6 years ago

Oh. I thought, it's not good if it can't find the headers. Good to know no issues here. @s3rvac, yeah, i killed the script

jazzl0ver commented 6 years ago

CMakeOutput.zip Here is what I get:

C:\retdec\build> msbuild /m /p:Configuration=Release retdec.sln
...
       "c:\retdec\build\retdec.sln" (default target) (1) ->
       "c:\retdec\build\src\bin2llvmirtool\bin2llvmirtool.vcxproj.metaproj" (default target) (6) ->
       "c:\retdec\build\src\bin2llvmirtool\bin2llvmirtool.vcxproj" (default target) (96) ->
       (Link target) ->
         ucrt.lib(api-ms-win-crt-math-l1-1-0.dll) : warning LNK4006: log2 already defined in libyara64.lib(math.obj); s
       econd definition ignored [c:\retdec\build\src\bin2llvmirtool\bin2llvmirtool.vcxproj]
         C:\retdec\build\src\bin2llvmirtool\Release\bin2llvmir.exe : warning LNK4088: image being generated due to /FOR
       CE option; image may not run [c:\retdec\build\src\bin2llvmirtool\bin2llvmirtool.vcxproj]

       "c:\retdec\build\retdec.sln" (default target) (1) ->
       "c:\retdec\build\deps\fileformat\deps\tinyxml2\tinyxml2-project.vcxproj.metaproj" (default target) (43) ->
       "c:\retdec\build\deps\fileformat\deps\tinyxml2\tinyxml2-project.vcxproj" (default target) (54) ->
       (CustomBuild target) ->
         C:\Program Files (x86)\MSBuild\Microsoft.Cpp\v4.0\V140\Microsoft.CppCommon.targets(171,5): error MSB6006: "cmd
       .exe" exited with code 9009. [c:\retdec\build\deps\fileformat\deps\tinyxml2\tinyxml2-project.vcxproj]

    16844 Warning(s)
    1 Error(s)

Time Elapsed 00:15:09.33
s3rvac commented 6 years ago

Could you please send us the complete output from the following command so we can investigate this further?

msbuild /m /p:Configuration=Release retdec.sln
jazzl0ver commented 6 years ago

@s3rvac , doesn't this https://github.com/avast-tl/retdec/files/1571854/CMakeOutput.zip suit? oops. that's from cmake. will send you msbuild output in 15 minutes

s3rvac commented 6 years ago

This is just the output from the cmake step. We will also need the output from the build step (msbuild), as this is the command that fails.

jazzl0ver commented 6 years ago

msbuild.zip Will this work or you'd like me to run the build from scratch?

s3rvac commented 6 years ago

Thank you. In the output, we saw the following line:

'patch' is not recognized as an internal or external command

Could you please try installing the patch package into MSYS2 to see whether it fixes the build for you? By running this in the MSYS2 shell:

pacman -S patch

I assume that you have installed everything from our guide, correct?

jazzl0ver commented 6 years ago

Zero errors after installing patch:

    5715 Warning(s)
    0 Error(s)

Thank you!!

s3rvac commented 6 years ago

Great! I have included the patch package into our installation guide.

s3rvac commented 6 years ago

I am closing this issue as the problem with the missing patch command was fixed. For build issues with VS 2017 without the 2015 toolset, I have created a dedicated issue: #55 .