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

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

Open
KOLANICH opened this issue Jan 14, 2020 · 4 comments
Open

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

KOLANICH opened this issue Jan 14, 2020 · 4 comments
Assignees

Comments

@KOLANICH
Copy link

KOLANICH commented Jan 14, 2020

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.

@derekmauro derekmauro assigned derekmauro and vslashg and unassigned derekmauro Aug 4, 2020
@chirsz-ever
Copy link

#1051
-Dgtest_disable_pthreads=ON fixes my problem.

@KOLANICH
Copy link
Author

KOLANICH commented Apr 3, 2022

Has it reallty fixed, or just worked around?

@chirsz-ever
Copy link

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.

@Psy-Kai
Copy link

Psy-Kai commented Jun 11, 2022

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

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

5 participants