Skip to content

Commit 7afd14a

Browse files
author
Steinar H. Gunderson
committed
Bug #26399073: MYSQL DOES NOT COMPILE WITH CLANG ON WINDOWS [noclose]
Modify convenience library linking so that one can use lld-link for linking executables and use MSVC's linker for linking convenience libraries. This is currently the best of both worlds, as lld-link can't link convenience libraries, and MSVC's linker has a hard-coded symbol/file limit that chokes on Clang's output in debug mode. In sum, this means that it's possible to compile and link MySQL with Clang on Windows also in debug mode. Change-Id: If62cadff0db8f3ce80baf18043c4732458319d24
1 parent 09ed92e commit 7afd14a

File tree

2 files changed

+29
-4
lines changed

2 files changed

+29
-4
lines changed

BUILD/README

Lines changed: 16 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -39,6 +39,22 @@ these cmake variables off:
3939
WITH_DEFAULT_COMPILER_OPTIONS
4040
WITH_DEFAULT_FEATURE_SET
4141

42+
===
43+
44+
It is possible to compile with Clang on Windows, which compiles faster
45+
and also yields faster binaries, but this is experimental and not officially
46+
supported. To compile, use LLVM 5.0.0 or newer from releases.llvm.org
47+
(Clang/C2, which is Microsoft's own version of Clang, is not supported),
48+
and put a Windows compile of Ninja in your path. Then execute the following
49+
in a shell:
50+
51+
"c:\Program Files (x86)\Microsoft Visual Studio\2017\Enterprise\VC\Auxiliary\Build\vcvarsall.bat" amd64
52+
set PATH=<path to Ninja>;c:\program files\llvm\msbuild-bin;%PATH%
53+
"c:\Program Files\CMake 3.8\bin\cmake.exe" -G Ninja -DCMAKE_C_COMPILER="c:/program files/llvm/msbuild-bin/cl.exe" -DCMAKE_CXX_COMPILER="c:/program files/llvm/msbuild-bin/cl.exe" -DCMAKE_LINKER="c:/program files/llvm/bin/lld-link.exe" -DWITH_BOOST=<path to Boost> ..
54+
ninja
55+
56+
===
57+
4258
Note: For building with unit tests, you need to tell cmake where to find
4359
the sources, see ../unittest/gunit/CMakeLists.txt
4460
You should *not* 'make install' googletest/googlemock on your system,

cmake/merge_archives.cmake.in

Lines changed: 13 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -76,10 +76,19 @@ EXECUTE_PROCESS(
7676

7777
IF(MSVC)
7878
# See CMAKE_CXX_CREATE_STATIC_LIBRARY
79-
EXECUTE_PROCESS(
80-
COMMAND ${CMAKE_LINKER} "/lib" "/NOLOGO" "${CMAKE_STATIC_LINKER_FLAGS}"
81-
"/OUT:${TARGET_LOC}" ${LIB_LOCATIONS}
82-
)
79+
IF(CMAKE_LINKER MATCHES "lld-link")
80+
# lld-link does not yet support making convenience libraries;
81+
# use MSVC's linker. We assume link.exe is in our path.
82+
EXECUTE_PROCESS(
83+
COMMAND link.exe "/lib" "/NOLOGO" "${CMAKE_STATIC_LINKER_FLAGS}"
84+
"/OUT:${TARGET_LOC}" ${LIB_LOCATIONS}
85+
)
86+
ELSE()
87+
EXECUTE_PROCESS(
88+
COMMAND ${CMAKE_LINKER} "/lib" "/NOLOGO" "${CMAKE_STATIC_LINKER_FLAGS}"
89+
"/OUT:${TARGET_LOC}" ${LIB_LOCATIONS}
90+
)
91+
ENDIF()
8392
ELSEIF(APPLE)
8493
# libtool handles it for us
8594
EXECUTE_PROCESS(

0 commit comments

Comments
 (0)