libressl / portable

LibreSSL Portable itself. This includes the build scaffold and compatibility layer that builds portable LibreSSL from the OpenBSD source code. Pull requests or patches sent to tech@openbsd.org are welcome.
https://www.libressl.org
1.37k stars 267 forks source link

Cmake 3.18.2 + Clang 11 (Windows 10, 32bit): error: __declspec attributes must be an identifier or string literal #612

Closed advancedwebdeveloper closed 1 year ago

advancedwebdeveloper commented 4 years ago

I tried to build using Clang 11, on Windows - so using Ninja's generator (to avoid MSVC and other non-LLVM stuff). So did like this: libressl-2.8.3\build>cmake -G Ninja -DCMAKE_C_COMPILER=clang -DCMAKE_CXX_COMPILER=clang++ ..

The first odd things was this warning. I am not dealing with GCC, in my case:

CMake Warning (dev) at C:/Program Files/CMake/share/cmake-3.18/Modules/GNUInstallDirs.cmake:225 (message): Unable to determine default CMAKE_INSTALL_LIBDIR directory because no target architecture is known. Please enable at least one language before including GNUInstallDirs. Call Stack (most recent call first): CMakeLists.txt:10 (include) This warning is for project developers. Use -Wno-dev to suppress it. But I can pass the arch. variable, if that would have practical effect.

The rest looks OK:

-- The C compiler identification is Clang 11.0.0 with GNU-like command-line -- Detecting C compiler ABI info -- Detecting C compiler ABI info - done -- Check for working C compiler: C:/Program Files/LLVM/bin/clang.exe - skipped -- Detecting C compile features -- Detecting C compile features - done -- Looking for asprintf -- Looking for asprintf - not found -- Looking for reallocarray -- Looking for reallocarray - not found -- Looking for strcasecmp -- Looking for strcasecmp - not found -- Looking for strlcat -- Looking for strlcat - not found -- Looking for strlcpy -- Looking for strlcpy - not found -- Looking for strndup -- Looking for strndup - not found -- Looking for strsep -- Looking for strsep - not found -- Looking for timegm -- Looking for timegm - not found -- Looking for arc4random_buf -- Looking for arc4random_buf - not found -- Looking for arc4random_uniform -- Looking for arc4random_uniform - not found -- Looking for explicit_bzero -- Looking for explicit_bzero - not found -- Looking for getauxval -- Looking for getauxval - not found -- Looking for getentropy -- Looking for getentropy - not found -- Looking for getpagesize -- Looking for getpagesize - not found -- Looking for timingsafe_bcmp -- Looking for timingsafe_bcmp - not found -- Looking for timingsafe_memcmp -- Looking for timingsafe_memcmp - not found -- Looking for memmem -- Looking for memmem - not found -- Looking for include file err.h -- Looking for include file err.h - not found -- Looking for clock_gettime -- Looking for clock_gettime - not found -- Looking for sys/types.h -- Looking for sys/types.h - found -- Looking for stdint.h -- Looking for stdint.h - found -- Looking for stddef.h -- Looking for stddef.h - found -- Check size of time_t -- Check size of time_t - failed -- Looking for strtonum -- Looking for strtonum - not found -- Looking for pipe2 -- Looking for pipe2 - not found -- Configuring done -- Generating done

Looks like you do not have any C++ code, around:

CMake Warning: Manually-specified variables were not used by the project:

CMAKE_CXX_COMPILER

. And eventually

-- Build files have been written to: libressl-2.8.3/build

My environment:

libressl-2.8.3\build>cmake --version

cmake version 3.18.2

libressl-2.8.3\build>clang --version

clang version 11.0.0 Target: i686-pc-windows-msvc Thread model: posix InstalledDir: C:\Program Files\LLVM\bin

libressl-2.8.3\build>ninja --version

1.10.0.git.kitware.jobserver-1

Triggerring Ninja:

libressl-2.8.3\build>ninja -j 1 And here are my errors:

[1/799] Building C object crypto/CMakeFiles/crypto.dir/md5/md5_dgst.c.obj FAILED: crypto/CMakeFiles/crypto.dir/md5/md5_dgst.c.obj C:\PROGRA~1\LLVM\bin\clang.exe -DCPPFLAGS -DHAVE_STRNLEN -DLIBRESSL_INTERNAL -DNO_CRYPT -DNO_SYSLOG -DOPENSSLDIR="\"C:/Program Files/LibreSSL/etc/ssl\"" -DOPENSSL_NO_ASM -DOPENSSL_NO_HW_PADLOCK -DOPENSSL_NO_SPEED -DSIZEOF_TIME_T="" -DWIN32_LEAN_AND_MEAN -D_CRT_DEPRECATED_NO_WARNINGS -D_CRT_SECURE_NO_WARNINGS -D_POSIX_THREAD_SAFE_FUNCTIONS -D_REENTRANT -D_WIN32_WINNT=0x0600 -DBEGIN_HIDDEN_DECLS="" -DEND_HIDDEN_DECLS="" -Drestrict -I../crypto/. -I../crypto/asn1 -I../crypto/bn -I../crypto/dsa -I../crypto/evp -I../crypto/modes -I../crypto/../include/compat -I../crypto/../include -g -Xclang -gcodeview -O0 -D_DEBUG -D_DLL -D_MT -Xclang --dependent-lib=msvcrtd -Wno-pointer-sign -MD -MT crypto/CMakeFiles/crypto.dir/md5/md5_dgst.c.obj -MF crypto\CMakeFiles\crypto.dir\md5\md5_dgst.c.obj.d -o crypto/CMakeFiles/crypto.dir/md5/md5_dgst.c.obj -c ../crypto/md5/md5_dgst.c

In file included from ../crypto/md5/md5_dgst.c:59 : In file included from ../crypto/../include/compat/stdio.h:11 : In file included from C:\Program Files\Windows Kits\10\include\10.0.18362.0\ucrt../ucrt/stdlib.h:13 : C:/Program Files/Windows Kits/10/include/10.0.18362.0/ucrt/corecrt_malloc.h:54:24:

error: __declspec attributes must be an identifier or string literal

_ACRTIMP _CRTALLOCATOR _CRTRESTRICT ^ C:\Program Files\Windows Kits\10\include\10.0.18362.0\ucrt\corecrt.h:50:37: note: expanded from macro '_CRTRESTRICT'

define _CRTRESTRICT __declspec(restrict)

                                ^

:19:18: note: expanded from here

define restrict 1

             ^

In file included from ../crypto/md5/md5_dgst.c:59: In file included from ../crypto/../include/compat\stdio.h:11: In file included from C:\Program Files\Windows Kits\10\include\10.0.18362.0\ucrt../ucrt/stdlib.h:13: C:\Program Files\Windows Kits\10\include\10.0.18362.0\ucrt\corecrt_malloc.h:61:43: error: __declspec attributes must be an identifier or string literal _ACRTIMP _CRT_JIT_INTRINSIC _CRTALLOCATOR _CRTRESTRICT _CRT_HYBRIDPATCHABLE ^ C:\Program Files\Windows Kits\10\include\10.0.18362.0\ucrt\corecrt.h:50:37: note: expanded from macro '_CRTRESTRICT'

define _CRTRESTRICT __declspec(restrict)

                                ^

:19:18: note: expanded from here

define restrict 1

             ^

In file included from ../crypto/md5/md5_dgst.c:59: In file included from ../crypto/../include/compat\stdio.h:11: In file included from C:\Program Files\Windows Kits\10\include\10.0.18362.0\ucrt../ucrt/stdlib.h:13: C:\Program Files\Windows Kits\10\include\10.0.18362.0\ucrt\corecrt_malloc.h:90:24: error: __declspec attributes must be an identifier or string literal _ACRTIMP _CRTALLOCATOR _CRTRESTRICT ^ C:\Program Files\Windows Kits\10\include\10.0.18362.0\ucrt\corecrt.h:50:37: note: expanded from macro '_CRTRESTRICT'

define _CRTRESTRICT __declspec(restrict)

                                ^

:19:18: note: expanded from here

define restrict 1

             ^

In file included from ../crypto/md5/md5_dgst.c:59: In file included from ../crypto/../include/compat\stdio.h:11: In file included from C:\Program Files\Windows Kits\10\include\10.0.18362.0\ucrt../ucrt/stdlib.h:13: C:\Program Files\Windows Kits\10\include\10.0.18362.0\ucrt\corecrt_malloc.h:96:43: error: __declspec attributes must be an identifier or string literal _ACRTIMP _CRTALLOCATOR _CRT_JIT_INTRINSIC _CRTRESTRICT _CRT_HYBRIDPATCHABLE ^ C:\Program Files\Windows Kits\10\include\10.0.18362.0\ucrt\corecrt.h:50:37: note: expanded from macro '_CRTRESTRICT'

define _CRTRESTRICT __declspec(restrict)

                                ^

:19:18: note: expanded from here

define restrict 1

             ^

In file included from ../crypto/md5/md5_dgst.c:59: In file included from ../crypto/../include/compat\stdio.h:11: In file included from C:\Program Files\Windows Kits\10\include\10.0.18362.0\ucrt../ucrt/stdlib.h:13: C:\Program Files\Windows Kits\10\include\10.0.18362.0\ucrt\corecrt_malloc.h:114:24: error: __declspec attributes must be an identifier or string literal _ACRTIMP _CRTALLOCATOR _CRTRESTRICT ^ C:\Program Files\Windows Kits\10\include\10.0.18362.0\ucrt\corecrt.h:50:37: note: expanded from macro '_CRTRESTRICT'

define _CRTRESTRICT __declspec(restrict)

                                ^

:19:18: note: expanded from here

define restrict 1

             ^

In file included from ../crypto/md5/md5_dgst.c:59: In file included from ../crypto/../include/compat\stdio.h:11: In file included from C:\Program Files\Windows Kits\10\include\10.0.18362.0\ucrt../ucrt/stdlib.h:13: C:\Program Files\Windows Kits\10\include\10.0.18362.0\ucrt\corecrt_malloc.h:121:24: error: __declspec attributes must be an identifier or string literal _ACRTIMP _CRTALLOCATOR _CRTRESTRICT _CRT_HYBRIDPATCHABLE ^ C:\Program Files\Windows Kits\10\include\10.0.18362.0\ucrt\corecrt.h:50:37: note: expanded from macro '_CRTRESTRICT'

define _CRTRESTRICT __declspec(restrict)

                                ^

:19:18: note: expanded from here

define restrict 1

             ^

In file included from ../crypto/md5/md5_dgst.c:59: In file included from ../crypto/../include/compat\stdio.h:11: In file included from C:\Program Files\Windows Kits\10\include\10.0.18362.0\ucrt../ucrt/stdlib.h:13: C:\Program Files\Windows Kits\10\include\10.0.18362.0\ucrt\corecrt_malloc.h:128:24: error: __declspec attributes must be an identifier or string literal _ACRTIMP _CRTALLOCATOR _CRTRESTRICT ^ C:\Program Files\Windows Kits\10\include\10.0.18362.0\ucrt\corecrt.h:50:37: note: expanded from macro '_CRTRESTRICT'

define _CRTRESTRICT __declspec(restrict)

                                ^

:19:18: note: expanded from here

define restrict 1

             ^

In file included from ../crypto/md5/md5_dgst.c:59: In file included from ../crypto/../include/compat\stdio.h:11: In file included from C:\Program Files\Windows Kits\10\include\10.0.18362.0\ucrt../ucrt/stdlib.h:13: C:\Program Files\Windows Kits\10\include\10.0.18362.0\ucrt\corecrt_malloc.h:136:24: error: __declspec attributes must be an identifier or string literal _ACRTIMP _CRTALLOCATOR _CRTRESTRICT ^ C:\Program Files\Windows Kits\10\include\10.0.18362.0\ucrt\corecrt.h:50:37: note: expanded from macro '_CRTRESTRICT'

define _CRTRESTRICT __declspec(restrict)

                                ^

:19:18: note: expanded from here

define restrict 1

             ^

In file included from ../crypto/md5/md5_dgst.c:59: In file included from ../crypto/../include/compat\stdio.h:11: In file included from C:\Program Files\Windows Kits\10\include\10.0.18362.0\ucrt../ucrt/stdlib.h:13: C:\Program Files\Windows Kits\10\include\10.0.18362.0\ucrt\corecrt_malloc.h:149:24: error: __declspec attributes must be an identifier or string literal _ACRTIMP _CRTALLOCATOR _CRTRESTRICT ^ C:\Program Files\Windows Kits\10\include\10.0.18362.0\ucrt\corecrt.h:50:37: note: expanded from macro '_CRTRESTRICT'

define _CRTRESTRICT __declspec(restrict)

                                ^

:19:18: note: expanded from here

define restrict 1

             ^

In file included from ../crypto/md5/md5_dgst.c:59: In file included from ../crypto/../include/compat\stdio.h:11: In file included from C:\Program Files\Windows Kits\10\include\10.0.18362.0\ucrt../ucrt/stdlib.h:13: C:\Program Files\Windows Kits\10\include\10.0.18362.0\ucrt\corecrt_malloc.h:156:24: error: __declspec attributes must be an identifier or string literal _ACRTIMP _CRTALLOCATOR _CRTRESTRICT ^ C:\Program Files\Windows Kits\10\include\10.0.18362.0\ucrt\corecrt.h:50:37: note: expanded from macro '_CRTRESTRICT'

define _CRTRESTRICT __declspec(restrict)

                                ^

:19:18: note: expanded from here

define restrict 1

             ^

In file included from ../crypto/md5/md5_dgst.c:59: In file included from ../crypto/../include/compat\stdio.h:11: In file included from C:\Program Files\Windows Kits\10\include\10.0.18362.0\ucrt../ucrt/stdlib.h:13: C:\Program Files\Windows Kits\10\include\10.0.18362.0\ucrt\corecrt_malloc.h:172:24: error: __declspec attributes must be an identifier or string literal _ACRTIMP _CRTALLOCATOR _CRTRESTRICT ^ C:\Program Files\Windows Kits\10\include\10.0.18362.0\ucrt\corecrt.h:50:37: note: expanded from macro '_CRTRESTRICT'

define _CRTRESTRICT __declspec(restrict)

                                ^

:19:18: note: expanded from here

define restrict 1

             ^

In file included from ../crypto/md5/md5_dgst.c:59: In file included from ../crypto/../include/compat\stdio.h:11: In file included from C:\Program Files\Windows Kits\10\include\10.0.18362.0\ucrt../ucrt/stdlib.h:13: C:\Program Files\Windows Kits\10\include\10.0.18362.0\ucrt\corecrt_malloc.h:181:24: error: __declspec attributes must be an identifier or string literal _ACRTIMP _CRTALLOCATOR _CRTRESTRICT ^ C:\Program Files\Windows Kits\10\include\10.0.18362.0\ucrt\corecrt.h:50:37: note: expanded from macro '_CRTRESTRICT'

define _CRTRESTRICT __declspec(restrict)

                                ^

:19:18: note: expanded from here

define restrict 1

             ^

In file included from ../crypto/md5/md5_dgst.c:59: In file included from ../crypto/../include/compat\stdio.h:11: In file included from C:\Program Files\Windows Kits\10\include\10.0.18362.0\ucrt../ucrt/stdlib.h:13: C:\Program Files\Windows Kits\10\include\10.0.18362.0\ucrt\corecrt_malloc.h:191:24: error: __declspec attributes must be an identifier or string literal _ACRTIMP _CRTALLOCATOR _CRTRESTRICT ^ C:\Program Files\Windows Kits\10\include\10.0.18362.0\ucrt\corecrt.h:50:37: note: expanded from macro '_CRTRESTRICT'

define _CRTRESTRICT __declspec(restrict)

                                ^

:19:18: note: expanded from here

define restrict 1

             ^

In file included from ../crypto/md5/md5_dgst.c:59: In file included from ../crypto/../include/compat\stdio.h:11: In file included from C:\Program Files\Windows Kits\10\include\10.0.18362.0\ucrt../ucrt/stdlib.h:13: C:\Program Files\Windows Kits\10\include\10.0.18362.0\ucrt\corecrt_malloc.h:199:24: er

ror: __declspec attributes must be an identifier or string literal

_ACRTIMP _CRTALLOCATOR _CRTRESTRICT ^ C:\Program Files\Windows Kits\10\include\10.0.18362.0\ucrt\corecrt.h:50:37: note: expanded from macro '_CRTRESTRICT'

define _CRTRESTRICT __declspec(restrict)

                                ^

:19:18: note: expanded from here

define restrict 1

advancedwebdeveloper commented 4 years ago

compat.zip I am attaching my files. I rad from declspec error when compiling clang's along with Windows headers :

The problem comes from a conflict between the C11 standard and Windows-specific extensions to C/C++. Windows extends storage-classes using the declspec syntax, which predates C11. It provides a storage-class for functions which don't return with __declspec(noreturn).

Unfortunately this conflicts with the keyword macro noreturn from C11. Microsoft likely doesn't see this as a problem, since they don't claim any support for C11. If you try to use Windows SDK headers with the macro defined, your compiler will complain about using a keyword in the declspec through the somewhat cryptic error message listed in the original question (noreturn expands into _Noreturn, the actual keyword added in C11).

The answer is pretty simple though: as long as your code isn't trying to mix __declspec(noreturn) and noreturn, which would be redundant, just include the header after the other system headers. The preprocessor won't expand noreturn inside the Windows SDK headers, and everything will be copacetic.

That didn't work for me.

Also passing Clang's args -fms-extensions -fdeclspec didn't change the situation - and errors are the same.

Ivan

advancedwebdeveloper commented 4 years ago

@ericniebler , please share your knowledge around Clang's compatibility flags

kinichiro commented 3 years ago

@advancedwebdeveloper can you close this ? I think this is compiler issue rather than LibreSSL one, though.

zhihaoy commented 3 years ago

Can you try setting both CMAKE_C_COMPILER and CMAKE_CXX_COMPILER to clang-cl on Windows?

panzerfaust1 commented 2 years ago

add restrict=restrict to add_compile_definitions (or pass in commandline)

busterb commented 1 year ago

I'm going to close this, since discussion seems to have settled on it being a compiler configuration issue. Right now, we are testing on MSVC 2019, 2022, and mingw-w64 (gcc) in 32-bit and 64-bit configs using CMake and automake.