Search code examples
c++windowscmakegoogle-nativeclient

CMake: Error running link command: %1 is not a valid Win32 application


I'm trying to build a NaCl extension on 64-bit Windows 8.1 using CMake. The same code works on Ubuntu without any problems. Everything goes well until CMake tries to link with this command:

cmake -E cmake_link_script link.txt

CMake: Error running link command: %1 is not a valid Win32 application

The link.txt is as follows:

C:/nacl_sdk/pepper_39/toolchain/win_pnacl/bin/pnacl-ar cr libfoo.a CMakeFiles/foo.dir/Foo.cc.o
C:/nacl_sdk/pepper_39/toolchain/win_pnacl/bin/pnacl-ranlib libfoo.a

This happens with both NMake and Unix makefile generators (the NaCl SDK contains make.exe for Windows).

If I run those commands manually, they succeed. What could be wrong here?


Solution

  • Just like eugensk00 suggested adding ".bat" in toolchain definitions seems to work. It is required to add both for ar and ranlib though:

    set(CMAKE_AR                    "${PLATFORM_PREFIX}/bin/pnacl-ar.bat" CACHE STRING "")
    set(CMAKE_RANLIB                "${PLATFORM_PREFIX}/bin/pnacl-ranlib.bat" CACHE STRING "")