我尝试在Windows 64上使用cmake和clang(8.0)构建zlib。我执行了以下步骤:
mkdir build.clang
cd build.clang
call "c:\Program Files (x86)\Microsoft Visual Studio\2017\Community\VC\Auxiliary\Build\vcvarsall.bat" x64
cmake -E env LDFLAGS="-fuse-ld=lld" cmake -H. -G Ninja ^
-DCMAKE_C_COMPILER:PATH="C:\Program Files\LLVM\bin\clang-cl.exe" ^
-DCMAKE_C_COMPILER_ID="Clang" ^
-DCMAKE_AR="c:\Program Files\LLVM\bin\llvm-ar.exe" ^
-DCMAKE_SYSTEM_NAME="Generic" ..
配置运行正常(不声称无法构建共享库,但这不是当前问题)
-- The C compiler identification is Clang
-- Check for working C compiler: C:/Program Files/LLVM/bin/clang-cl.exe
-- Check for working C compiler: C:/Program Files/LLVM/bin/clang-cl.exe -- works
-- Detecting C compiler ABI info
-- Detecting C compiler ABI info - failed
-- Detecting C compile features
-- Detecting C compile features - done CMake Warning (dev) at CMakeLists.txt:186 (add_library): ADD_LIBRARY called with SHARED option but the target platform does not support dynamic linking. Building a STATIC library instead. This may lead to problems. This warning is for project developers. Use -Wno-dev to suppress it.
-- Configuring done
-- Generating done
-- Build files have been written to: F:/Project-tests/clang_lept/zlib-1.2.11/build.clang
但是构建失败:
cmake --build . --config Release
[1/36] Building C object CMakeFiles/zlib.dir/crc32.obj
FAILED: CMakeFiles/zlib.dir/crc32.obj
C:\PROGRA~1\LLVM\bin\clang-cl.exe -DNO_FSEEKO -I. -I../ -MD -MT CMakeFiles/zlib.dir/crc32.obj -MF CMakeFiles\zlib.dir\crc32.obj.d -o CMakeFiles/zlib.dir/crc32.obj -c ../crc32.c
clang-cl: warning: unknown argument ignored in clang-cl: '-MF' [-Wunknown-argument]
clang-cl: error: no such file or directory: 'CMakeFiles/zlib.dir/crc32.obj'
clang-cl: error: no such file or directory: 'CMakeFiles\zlib.dir\crc32.obj.d'
[2/36] Building C object CMakeFiles/zlib.dir/gzread.obj
FAILED: CMakeFiles/zlib.dir/gzread.obj
C:\PROGRA~1\LLVM\bin\clang-cl.exe -DNO_FSEEKO -I. -I../ -MD -MT CMakeFiles/zlib.dir/gzread.obj -MF CMakeFiles\zlib.dir\gzread.obj.d -o CMakeFiles/zlib.dir/gzread.obj -c ../gzread.c
clang-cl: warning: unknown argument ignored in clang-cl: '-MF' [-Wunknown-argument]
clang-cl: error: no such file or directory: 'CMakeFiles/zlib.dir/gzread.obj'
clang-cl: error: no such file or directory: 'CMakeFiles\zlib.dir\gzread.obj.d'
[3/36] Building C object CMakeFiles/zlib.dir/compress.obj
FAILED: CMakeFiles/zlib.dir/compress.obj
C:\PROGRA~1\LLVM\bin\clang-cl.exe -DNO_FSEEKO -I. -I../ -MD -MT CMakeFiles/zlib.dir/compress.obj -MF CMakeFiles\zlib.dir\compress.obj.d -o CMakeFiles/zlib.dir/compress.obj -c ../compress.c
clang-cl: warning: unknown argument ignored in clang-cl: '-MF' [-Wunknown-argument]
clang-cl: error: no such file or directory: 'CMakeFiles/zlib.dir/compress.obj'
clang-cl: error: no such file or directory: 'CMakeFiles\zlib.dir\compress.obj.d'
[4/36] Building C object CMakeFiles/zlib.dir/adler32.obj
FAILED: CMakeFiles/zlib.dir/adler32.obj
C:\PROGRA~1\LLVM\bin\clang-cl.exe -DNO_FSEEKO -I. -I../ -MD -MT CMakeFiles/zlib.dir/adler32.obj -MF CMakeFiles\zlib.dir\adler32.obj.d -o CMakeFiles/zlib.dir/adler32.obj -c ../adler32.c
clang-cl: warning: unknown argument ignored in clang-cl: '-MF' [-Wunknown-argument]
clang-cl: error: no such file or directory: 'CMakeFiles/zlib.dir/adler32.obj'
clang-cl: error: no such file or directory: 'CMakeFiles\zlib.dir\adler32.obj.d'
[5/36] Building C object CMakeFiles/zlib.dir/gzclose.obj
FAILED: CMakeFiles/zlib.dir/gzclose.obj
C:\PROGRA~1\LLVM\bin\clang-cl.exe -DNO_FSEEKO -I. -I../ -MD -MT CMakeFiles/zlib.dir/gzclose.obj -MF CMakeFiles\zlib.dir\gzclose.obj.d -o CMakeFiles/zlib.dir/gzclose.obj -c ../gzclose.c
clang-cl: warning: unknown argument ignored in clang-cl: '-MF' [-Wunknown-argument]
clang-cl: error: no such file or directory: 'CMakeFiles/zlib.dir/gzclose.obj'
clang-cl: error: no such file or directory: 'CMakeFiles\zlib.dir\gzclose.obj.d'
[6/36] Building C object CMakeFiles/zlib.dir/gzlib.obj
FAILED: CMakeFiles/zlib.dir/gzlib.obj
C:\PROGRA~1\LLVM\bin\clang-cl.exe -DNO_FSEEKO -I. -I../ -MD -MT CMakeFiles/zlib.dir/gzlib.obj -MF CMakeFiles\zlib.dir\gzlib.obj.d -o CMakeFiles/zlib.dir/gzlib.obj -c ../gzlib.c
clang-cl: warning: unknown argument ignored in clang-cl: '-MF' [-Wunknown-argument]
clang-cl: error: no such file or directory: 'CMakeFiles/zlib.dir/gzlib.obj'
clang-cl: error: no such file or directory: 'CMakeFiles\zlib.dir\gzlib.obj.d'
ninja: build stopped: subcommand failed.
当我尝试使用clang的ccc兼容性时-构建也失败了,但是在链接过程中...
PS:使用VS 2017(cmake .. -G "Visual Studio 15 2017 Win64"
)进行构建可以毫无问题...
答案 0 :(得分:1)
您需要再设置一些环境变量。
set CC=clang-cl
set CXX=clang-cl
set CFLAGS=-m64 -fmsc-version=<your vs version>
set CXXFLAGS=-m64 -fmsc-version=<your vs version>
或在您的cmake
通话中传递它们。
答案 1 :(得分:0)
所以看起来就像“少即是多” ;-)。以下是使用忍者,c和cmake(必须以管理员身份运行以进行安装)构建zlib的步骤:
set CC=clang-cl
set CFLAGS=-m64 -fmsc-version=1915
call "c:\Program Files (x86)\Microsoft Visual Studio\2017\Community\VC\Auxiliary\Build\vcvarsall.bat" x64
cmake .. -G Ninja -DCMAKE_INSTALL_PREFIX="C:\Program Files\zlib"
cmake --build . --config Release --target install
cmake --build . --config Debug --target install
我需要指定CMAKE_INSTALL_PREFIX
,否则cmake会将64位zlib安装到“ C:/ Program Files(x86)”