googletest icon indicating copy to clipboard operation
googletest copied to clipboard

Cannot build with MinGW-w64 + CLang: AutoHandle is not defined

Open KOLANICH opened this issue 4 years ago • 4 comments

toolchain.cmake
set(CMAKE_SYSTEM_NAME Windows)
set(CMAKE_SYSTEM_PROCESSOR x86_64)

set(triple x86_64-pc-w64-mingw32)

message(STATUS "Setting CLang as compiler")
set(CMAKE_C_COMPILER "clang")
set(CMAKE_CXX_COMPILER "clang++")
set(CMAKE_CPP_COMPILER "clang++")

set(CMAKE_MAKE_PROGRAM "ninja" CACHE FILEPATH "Path to make")
set(CMAKE_NM "/usr/x86_64-w64-mingw32/bin/nm" CACHE FILEPATH "Path to nm")
set(CMAKE_OBJCOPY "/usr/x86_64-w64-mingw32/bin/objcopy" CACHE FILEPATH "Path to objcopy")
set(CMAKE_STRIP "/usr/x86_64-w64-mingw32/bin/strip" CACHE FILEPATH "Path to strip")

set(CMAKE_AR "llvm-ar" CACHE FILEPATH "Path to ar")
set(CMAKE_OBJDUMP "llvm-objdump" CACHE FILEPATH "Path to objdump")
set(CMAKE_RANLIB "llvm-ranlib" CACHE FILEPATH "Path to ranlib")

set(CMAKE_LINKER "lld-link-10" CACHE FILEPATH "Path to linker")
set(CMAKE_RC_COMPILER "x86_64-w64-mingw32-windres" CACHE FILEPATH "Path to windres")

set(CMAKE_C_COMPILER_TARGET ${triple})
set(CMAKE_CXX_COMPILER_TARGET ${triple})
set(CMAKE_CPP_COMPILER_TARGET ${triple})

set(CMAKE_C_FLAGS ${CMAKE_FLAGS})
set(CMAKE_CXX_FLAGS ${CMAKE_FLAGS})

set(CMAKE_EXE_LINKER_FLAGS "${CMAKE_EXE_LINKER_FLAGS} ${CMAKE_LINKER_FLAGS}")
set(CMAKE_SHARED_LINKER_FLAGS "${CMAKE_SHARED_LINKER_FLAGS} ${CMAKE_LINKER_FLAGS}")


set(CMAKE_LINKER_FLAGS "${CMAKE_LINKER_FLAGS}")
set(CMAKE_C_LINKER_FLAGS ${CMAKE_LINKER_FLAGS})
set(CMAKE_CXX_LINKER_FLAGS ${CMAKE_LINKER_FLAGS})

set(CMAKE_CXX_STANDARD_LIBRARIES "-lssp")


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

The distro is Ubuntu Eoan.

binutils-mingw-w64-i686/eoan,now 2.33-2ubuntu1+8.3ubuntu3 amd64 [installed,automatic]
binutils-mingw-w64-x86-64/eoan,now 2.33-2ubuntu1+8.3ubuntu3 amd64 [installed,automatic]
clang-10/unknown,now 1:10~++20200113081712+c958639098a-1~exp1~20200113072319.77 amd64 [installed]
g++-mingw-w64-i686/eoan,now 9.2.1-9ubuntu1+22~exp1ubuntu2 amd64 [installed]
g++-mingw-w64-x86-64/eoan,now 9.2.1-9ubuntu1+22~exp1ubuntu2 amd64 [installed,automatic]
g++-mingw-w64/eoan,eoan,now 9.2.1-9ubuntu1+22~exp1ubuntu2 all [installed,automatic]
gcc-mingw-w64-base/eoan,now 9.2.1-9ubuntu1+22~exp1ubuntu2 amd64 [installed,automatic]
gcc-mingw-w64-i686/eoan,now 9.2.1-9ubuntu1+22~exp1ubuntu2 amd64 [installed,automatic]
gcc-mingw-w64-x86-64/eoan,now 9.2.1-9ubuntu1+22~exp1ubuntu2 amd64 [installed,automatic]
gcc-mingw-w64/eoan,eoan,now 9.2.1-9ubuntu1+22~exp1ubuntu2 all [installed,automatic]
libclang-10-dev/unknown,now 1:10~++20200113081712+c958639098a-1~exp1~20200113072319.77 amd64 [installed]
libclang-common-10-dev/unknown,now 1:10~++20200113081712+c958639098a-1~exp1~20200113072319.77 amd64 [installed,automatic]
libclang1-10/unknown,now 1:10~++20200113081712+c958639098a-1~exp1~20200113072319.77 amd64 [installed,automatic]
llvm-10-dev/unknown,now 1:10~++20200113081712+c958639098a-1~exp1~20200113072319.77 amd64 [installed]
llvm-10-runtime/unknown,now 1:10~++20200113081712+c958639098a-1~exp1~20200113072319.77 amd64 [installed,automatic]
llvm-10-tools/unknown,now 1:10~++20200113081712+c958639098a-1~exp1~20200113072319.77 amd64 [installed]
llvm-10/unknown,now 1:10~++20200113081712+c958639098a-1~exp1~20200113072319.77 amd64 [installed,automatic]
mingw-w64-common/eoan,eoan,now 6.0.0-3 all [installed,automatic]
mingw-w64-i686-dev/eoan,eoan,now 6.0.0-3 all [installed,automatic]
mingw-w64-x86-64-dev/eoan,eoan,now 6.0.0-3 all [installed,automatic]
mingw-w64/eoan,eoan,now 6.0.0-3 all [installed]

llvm+clang are installed from the official deb repo apt.llvm.org. clang++ of version 10 (and other llvm 10 tools) are selected using update-alternatives.

The result is the error:

[1/4] /usr/bin/clang++ --target=x86_64-pc-w64-mingw32   -isystem ../include -isystem ../ -Wall -Wshadow -Werror -Wconversion -DGTEST_HAS_PTHREAD=1 -fexceptions -W -Wpointer-arith -Wreturn-type -Wcast-qual -Wwrite-strings -Wswitch -Wunused-parameter -Wcast-align -Wchar-subscripts -Winline -Wredundant-decls -MD -MT CMakeFiles/gtest_main.dir/src/gtest_main.cc.obj -MF CMakeFiles/gtest_main.dir/src/gtest_main.cc.obj.d -o CMakeFiles/gtest_main.dir/src/gtest_main.cc.obj -c ../src/gtest_main.cc
FAILED: CMakeFiles/gtest_main.dir/src/gtest_main.cc.obj 
/usr/bin/clang++ --target=x86_64-pc-w64-mingw32   -isystem ../include -isystem ../ -Wall -Wshadow -Werror -Wconversion -DGTEST_HAS_PTHREAD=1 -fexceptions -W -Wpointer-arith -Wreturn-type -Wcast-qual -Wwrite-strings -Wswitch -Wunused-parameter -Wcast-align -Wchar-subscripts -Winline -Wredundant-decls -MD -MT CMakeFiles/gtest_main.dir/src/gtest_main.cc.obj -MF CMakeFiles/gtest_main.dir/src/gtest_main.cc.obj.d -o CMakeFiles/gtest_main.dir/src/gtest_main.cc.obj -c ../src/gtest_main.cc
In file included from ../src/gtest_main.cc:31:
In file included from ../include/gtest/gtest.h:62:
In file included from ../include/gtest/internal/gtest-internal.h:40:
../include/gtest/internal/gtest-port.h:1487:3: error: unknown type name 'AutoHandle'
  AutoHandle thread_;
  ^
1 error generated.
ninja: build stopped: subcommand failed.

KOLANICH avatar Jan 14 '20 12:01 KOLANICH

https://github.com/google/googletest/issues/1051 -Dgtest_disable_pthreads=ON fixes my problem.

chirsz-ever avatar Apr 03 '22 11:04 chirsz-ever

Has it reallty fixed, or just worked around?

KOLANICH avatar Apr 03 '22 15:04 KOLANICH

I meet this problem in v1.8.0, and after I upgrade to 1.11.0, the problem disappeared.

THis is a bug tracked in #606 and solved by #721 and #856, which merged in version v1.8.1.

So setting gtest_disable_pthreads to OFF is just a workaround with version less or equal than v1.8.0. But in most cases you do not really need multi-thread for testing.

chirsz-ever avatar Apr 03 '22 18:04 chirsz-ever

I had the same issue. The problem was the CMake-installation I used. I installed CMake in MSYS2. But instead of installing the clang64-environment version I installed the "normal" version. Just removing cmake an install the right version via pacboy- S cmake:p resolved my issue.

Why this helped? Maybe because the clang64-env version does not find pthread thus the find_package will not be set. Just a guess...

Psy-Kai avatar Jun 11 '22 13:06 Psy-Kai