Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

link.exe crashes everytime in cmake #21

Open
WaterJuice opened this issue Oct 15, 2020 · 7 comments
Open

link.exe crashes everytime in cmake #21

WaterJuice opened this issue Oct 15, 2020 · 7 comments

Comments

@WaterJuice
Copy link

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.

@mstorsjo
Copy link
Owner

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

@dmikushin
Copy link

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

@zuowanbushiwo
Copy link

zuowanbushiwo commented Aug 23, 2021

@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

@mstorsjo
Copy link
Owner

mstorsjo commented Aug 23, 2021

@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

@zuowanbushiwo
Copy link

@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
Copy link
Owner

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

@zuowanbushiwo
Copy link

Thanks!you are so great。
best regards

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

No branches or pull requests

4 participants