mstorsjo/msvc-wine

link.exe crashes everytime in cmake

WaterJuice opened this issue · 7 comments

I created the docker image using your tool the other day, and am running into an issue where I can not get link.exe to run in wine without crashing.
It always comes up with a "Unhandled exception: page fault on write access" when ever cmake calls it. calling link byitself will print the syntax and not cause an error, but as soon as it tries to do something it crashes.
I also tried using the 32bit version of link and had the same problem.
The versions it downloaded were
MSVCVER=14.27.29110
SDKVER=10.0.18362.0

Do you have an ideas what could be happening and what I could do to fix it?

Thanks.

Cmake often tries to enable pdb options which don't work well in wine; I usually use a custom patched cmake when building with msvc in wine. See https://gitlab.kitware.com/mstorsjo/cmake/-/commits/msvc/ for one version of such patches (haven't verified atm that it works with the current version of msvc-wine though).

Confirmed it worked for me with CMake 3.19.4 built from source with 3 @mstorsjo patches on top of it

@mstorsjo @dmikushin
I also encountered a strange problem with cmake, can you give me some guidance?
cmake --version

cmake version 3.16.3  
CMake suite maintained and supported by Kitware (kitware.com/cmake).

cmake project :cxx_hello

cmake toolchain.cmake:

cmake_minimum_required(VERSION 3.8.0)
if(MSVC_TOOLCHAIN_HAS_RUN)
return()
endif(MSVC_TOOLCHAIN_HAS_RUN)
set(MSVC_TOOLCHAIN_HAS_RUN true)
list(APPEND _supported_archs
"x86" "x64"
"arm"
"arm64")

message(STATUS "ARCH:${ARCH}")

if(NOT DEFINED ARCH)
message(FATAL_ERROR "ARCH argument not set. Bailing configure since I don't know what target you want to build for!")
endif()

list(FIND _supported_archs ${ARCH} contains_ARCH)
if("${contains_ARCH}" EQUAL "-1")
string(REPLACE ";" "\n * " _supported_archs_formatted "${_supported_archs}")
message(FATAL_ERROR " Invalid ARCH specified! Current value: ${ARCH}.\n"
" Supported ARCH values: \n * ${_supported_archs_formatted}")
endif()

if(DEFINED MSVC_WINE_BIN_PATH)
set(ENV{_MSVC_WINE_BIN_PATH} "${MSVC_WINE_BIN_PATH}")
elseif(DEFINED ENV{_MSVC_WINE_BIN_PATH})
set(MSVC_WINE_BIN_PATH "$ENV{_MSVC_WINE_BIN_PATH}")
elseif(NOT DEFINED MSVC_WINE_BIN_PATH)
if(EXISTS "/opt/msvc/bin/")
set(MSVC_WINE_BIN_PATH "/opt/msvc/bin")
else()
message(FATAL_ERROR "can not find msvc wine bin path ")
endif()
endif ()

set(ENV{PATH} "${MSVC_WINE_BIN_PATH}/${ARCH}/:$ENV{PATH}")

message(STATUS "PATH: ${MSVC_WINE_BIN_PATH}")
set(CMAKE_SYSTEM_NAME Windows)
set(CMAKE_MAKE_PROGRAM "${MSVC_WINE_BIN_PATH}/${ARCH}/nmake")
set(CMAKE_C_COMPILER "${MSVC_WINE_BIN_PATH}/${ARCH}/cl")
set(CMAKE_CXX_COMPILER "${MSVC_WINE_BIN_PATH}/${ARCH}/cl")
set(CMAKE_RC_COMPILER "${MSVC_WINE_BIN_PATH}/${ARCH}/rc")
set(CMAKE_MT "${MSVC_WINE_BIN_PATH}/${ARCH}/mt")
set(CMAKE_AR "${MSVC_WINE_BIN_PATH}/${ARCH}/lib")

set(CMAKE_FIND_ROOT_PATH_MODE_PROGRAM NEVER)
set(CMAKE_FIND_ROOT_PATH_MODE_LIBRARY ONLY)
set(CMAKE_FIND_ROOT_PATH_MODE_INCLUDE ONLY)
set(CMAKE_FIND_ROOT_PATH_MODE_PACKAGE ONLY)

run :

 wineserver -p && wine wineboot && cmake  -DCMAKE_TOOLCHAIN_FILE=/worker/msvc-toolchain.cmake  -DARCH=x86  ..

CMake error log:

-- ARCH:x86
-- PATH: /opt/msvc/bin
-- The CXX compiler identification is MSVC 19.29.30133.0
-- Check for working CXX compiler: /opt/msvc/bin/x86/cl
CMake Error at /worker/msvc-toolchain.cmake:16 (message):
ARCH argument not set. Bailing configure since I don't know what target
you want to build for!
Call Stack (most recent call first):
/worker/cxx-example/build/CMakeFiles/3.16.3/CMakeSystem.cmake:6 (include)
/worker/cxx-example/build/CMakeFiles/CMakeTmp/CMakeLists.txt:3 (project)

CMake Error: CMake was unable to find a build program corresponding to "Unix Makefiles". CMAKE_MAKE_PROGRAM is not set. You probably need to select a different build tool.
CMake Error: CMAKE_CXX_COMPILER not set, after EnableLanguage
CMake Error at /usr/share/cmake-3.16/Modules/CMakeTestCXXCompiler.cmake:37 (try_compile):
Failed to configure test project build system.
Call Stack (most recent call first):
CMakeLists.txt:5 (project)

-- Configuring incomplete, errors occurred!
See also "/worker/cxx-example/build/CMakeFiles/CMakeOutput.log".

The ARCH and CXX compilers were detected successfully at first, and the message (STATUS "PATH: ${MSVC_WINE_BIN_PATH}") has been printed, it seems that this toolchain.cmake has been run many times.

thanks!
best regards

@zuowanbushiwo To use CMake with MSVC, you can't use the default "Unix Makefiles" generator. Your best bet is to use Ninja. (The other ones that work with MSVC on Windows are the Visual Studio project generator, and nmake. Using the visual studio project files via Wine probably is more tricky, the nmake generator might work but I haven't tested it. Edit: Those generators aren't available in a unix-based cmake; the only choice available that works with MSVC is ninja.)

I pushed a branch here which contains a working example of building things with CMake: https://github.com/mstorsjo/msvc-wine/commits/cmake

@mstorsjo
thanks , my test branch cmake can be compiled successful and output bin is available,I still encountered two problems:

  1. Is the following error caused by wine?
    [1/2] Building CXX object CMakeFiles/hello-world.dir/hello-world.cc.obj
    0178:err:msvcrt:demangle_datatype Unknown type @
    0178:err:msvcrt:demangle_datatype Unknown type @
    0178:err:msvcrt:demangle_datatype Unknown type @
    0178:err:msvcrt:demangle_datatype Unknown type @
    0178:err:msvcrt:demangle_datatype Unknown type @
    0178:err:msvcrt:demangle_datatype Unknown type @
    0178:err:msvcrt:demangle_datatype Unknown type @
    0178:err:msvcrt:demangle_datatype Unknown type @
    0178:err:msvcrt:demangle_datatype Unknown type s
    0178:err:msvcrt:demangle_datatype Unknown type s
    0178:err:msvcrt:demangle_datatype Unknown type s
    0178:err:msvcrt:demangle_datatype Unknown type s
    0178:err:msvcrt:demangle_datatype Unknown type s
    0178:err:msvcrt:demangle_datatype Unknown type s
    0178:err:msvcrt:demangle_datatype Unknown type s
    0178:err:msvcrt:demangle_datatype Unknown type s
    9041.0\ucrt\corecrt_wctype.h
    [2/2] Linking CXX executable hello-world.exe

  2. Strange problem, it seems that the message(FATAL_ERROR "xx") function cannot be used?
    If it looks like the following, it can compile normally.

    message(STATUS "ARCH:${ARCH}")
     if(DEFINED ARCH)
        message(STATUS "DEFINE ARCH")
     endif()
    if(NOT DEFINED ARCH)
      message(STATUS "NOT DEFINE ARCH")
   endif() 

cmake out :

  -- ARCH:x86
-- DEFINE ARCH
-- PATH: /opt/msvc/bin
-- The CXX compiler identification is MSVC 19.29.30133.0
-- Check for working CXX compiler: /opt/msvc/bin/x86/cl
-- Check for working CXX compiler: /opt/msvc/bin/x86/cl - works
-- Detecting CXX compiler ABI info
-- Detecting CXX compiler ABI info - done
-- Detecting CXX compile features
-- Detecting CXX compile features - done
-- Configuring done
-- Generating done
-- Build files have been written to: /worker/cxx-example/build

if change to this:

    message(STATUS "ARCH:${ARCH}")
    if(DEFINED ARCH)
        message(STATUS "DEFINE ARCH")
     endif()
    if(NOT DEFINED ARCH)
      message(FATAL_ERROR  "NOT DEFINE ARCH")         // only here
   endif() 

cmake error output:

-- ARCH:x86
-- DEFINE ARCH
-- PATH: /opt/msvc/bin
-- The CXX compiler identification is MSVC 19.29.30133.0
-- Check for working CXX compiler: /opt/msvc/bin/x86/cl
CMake Error at /worker/msvc-toolchain.cmake:20 (message):
  NOT DEFINE ARCH
Call Stack (most recent call first):
  /worker/cxx-example/build/CMakeFiles/3.16.20200203-ga5e7a94/CMakeSystem.cmake:6 (include)
  /worker/cxx-example/build/CMakeFiles/CMakeTmp/CMakeLists.txt:3 (project)


CMake Error: CMAKE_CXX_COMPILER not set, after EnableLanguage
CMake Error at /opt/cmake/share/cmake-3.16/Modules/CMakeTestCXXCompiler.cmake:37 (try_compile):
  Failed to configure test project build system.
Call Stack (most recent call first):
  CMakeLists.txt:5 (project)


-- Configuring incomplete, errors occurred!

it seems that this toolchain.cmake has been run many times? and didn't define the ARCH variable in the next few times?

Thanks!

@mstorsjo
thanks , my test branch cmake can be compiled successful and output bin is available,I still encountered two problems:

  1. Is the following error caused by wine?
    [1/2] Building CXX object CMakeFiles/hello-world.dir/hello-world.cc.obj
    0178:err:msvcrt:demangle_datatype Unknown type @
    0178:err:msvcrt:demangle_datatype Unknown type @
    0178:err:msvcrt:demangle_datatype Unknown type @
    0178:err:msvcrt:demangle_datatype Unknown type @
    0178:err:msvcrt:demangle_datatype Unknown type @
    0178:err:msvcrt:demangle_datatype Unknown type @
    0178:err:msvcrt:demangle_datatype Unknown type @
    0178:err:msvcrt:demangle_datatype Unknown type @
    0178:err:msvcrt:demangle_datatype Unknown type s
    0178:err:msvcrt:demangle_datatype Unknown type s
    0178:err:msvcrt:demangle_datatype Unknown type s
    0178:err:msvcrt:demangle_datatype Unknown type s
    0178:err:msvcrt:demangle_datatype Unknown type s
    0178:err:msvcrt:demangle_datatype Unknown type s
    0178:err:msvcrt:demangle_datatype Unknown type s
    0178:err:msvcrt:demangle_datatype Unknown type s
    9041.0\ucrt\corecrt_wctype.h
    [2/2] Linking CXX executable hello-world.exe

Hmm, maybe, I'm not sure if this is a combination of cornercases in wine that aren't implemented, or your cmake build doing something more fancy than I've tested. I don't get those errors with my example.

  1. Strange problem, it seems that the message(FATAL_ERROR "xx") function cannot be used?
    If it looks like the following, it can compile normally.

Sorry, I don't have time to help you figure out your own cmake toolchain files - things work with the example I provided, anything outside of that is up to you to figure out.

Thanks!you are so great。
best regards