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

Compile on Windows with Clang 14.0.6 #1634

Open
itavero opened this issue Sep 8, 2022 · 7 comments
Open

Compile on Windows with Clang 14.0.6 #1634

itavero opened this issue Sep 8, 2022 · 7 comments

Comments

@itavero
Copy link
Contributor

itavero commented Sep 8, 2022

I'm getting a similar error as in #1405 when trying to build the current master branch on my Windows machine with Clang 14.0.6 (via CMake / ninja).
Example of the error I got:

[build] D:/gitrepo/cpputest/src/Platforms/Gcc/UtestPlatform.cpp:248:11: error: 'fopen' is deprecated: This function or variable may be unsafe. Consider using fopen_s instead. To disable deprecation, use _CRT_SECURE_NO_WARNINGS. See online help for details. [-Werror,-Wdeprecated-declarations]
[build]    return fopen(filename, flag);
[build]           ^
[build] C:\Program Files (x86)\Windows Kits\10\Include\10.0.22621.0\ucrt\stdio.h:212:20: note: 'fopen' has been explicitly marked deprecated here
[build]     _Check_return_ _CRT_INSECURE_DEPRECATE(fopen_s)
[build]                    ^
[build] C:\Program Files (x86)\Microsoft Visual Studio 14.0\VC\include\vcruntime.h:269:55: note: expanded from macro '_CRT_INSECURE_DEPRECATE'
[build]         #define _CRT_INSECURE_DEPRECATE(_Replacement) _CRT_DEPRECATE_TEXT(    \
[build]                                                       ^
[build] C:\Program Files (x86)\Microsoft Visual Studio 14.0\VC\include\vcruntime.h:259:47: note: expanded from macro '_CRT_DEPRECATE_TEXT'
[build] #define _CRT_DEPRECATE_TEXT(_Text) __declspec(deprecated(_Text))
[build]                                               ^

I fixed the compilation itself by changing the pre-processor check for fopen_s and localtime_s from:

#if defined(_WIN32) && defined(MINGW_HAS_SECURE_API)

to

#if defined(_WIN32) && (defined(__clang__) || defined(MINGW_HAS_SECURE_API))

The next failure I run into is:

[build] CMake Error at D:/gitrepo/cpputest/cmake/Scripts/CppUTestBuildTimeDiscoverTests.cmake:49 (message):
[build]   Executable "D:/gitrepo/cpputest/build/tests/CppUTest/CppUTestTests.exe -lg"
[build]   failed with output:
[build] 
[build]   Access violation
[build] 
[build]   Please check that the excutable was added.
[build] Call Stack (most recent call first):
[build]   D:/gitrepo/cpputest/cmake/Scripts/CppUTestBuildTimeDiscoverTests.cmake:82 (buildtime_discover_tests)

Not sure how to proceed on getting this working.
Is this a combination also tested in the CI environment of CppUTest?

@thetic
Copy link
Contributor

thetic commented Sep 8, 2022

Which of _WIN32 and MINGW_HAS_SECURE_API is not defined in your toolchain?

@itavero
Copy link
Contributor Author

itavero commented Sep 8, 2022

Which of _WIN32 and MINGW_HAS_SECURE_API is not defined in your toolchain?

as you can tell from the change I made, _WIN32 is defined.
I'm not using MinGW. I've installed Clang using the Windows installer.

@thetic
Copy link
Contributor

thetic commented Sep 8, 2022

Would you mind posting the output of your CMake configure step? (-- The C compiler identification is ..., etc.)

@itavero
Copy link
Contributor Author

itavero commented Sep 9, 2022

Here you go:

[cmake] Not searching for unused variables given on the command line.
[cmake] -- The C compiler identification is Clang 14.0.6 with GNU-like command-line
[cmake] -- The CXX compiler identification is Clang 14.0.6 with GNU-like command-line
[cmake] -- Detecting C compiler ABI info
[cmake] -- Detecting C compiler ABI info - done
[cmake] -- Check for working C compiler: C:/Program Files/LLVM/bin/clang.exe - skipped
[cmake] -- Detecting C compile features
[cmake] -- Detecting C compile features - done
[cmake] -- Detecting CXX compiler ABI info
[cmake] -- Detecting CXX compiler ABI info - done
[cmake] -- Check for working CXX compiler: C:/Program Files/LLVM/bin/clang++.exe - skipped
[cmake] -- Detecting CXX compile features
[cmake] -- Detecting CXX compile features - done
[cmake] -- Performing Test CPPUTEST_HAVE_EXCEPTIONS
[cmake] -- Performing Test CPPUTEST_HAVE_EXCEPTIONS - Success
[cmake] -- Looking for sys/types.h
[cmake] -- Looking for sys/types.h - found
[cmake] -- Looking for stdint.h
[cmake] -- Looking for stdint.h - found
[cmake] -- Looking for stddef.h
[cmake] -- Looking for stddef.h - found
[cmake] -- Check size of long long
[cmake] -- Check size of long long - done
[cmake] -- Performing Test WARNING_C_FLAG_Wall
[cmake] -- Performing Test WARNING_C_FLAG_Wall - Success
[cmake] -- Performing Test WARNING_C_FLAG_Wextra
[cmake] -- Performing Test WARNING_C_FLAG_Wextra - Success
[cmake] -- Performing Test WARNING_C_FLAG_pedantic
[cmake] -- Performing Test WARNING_C_FLAG_pedantic - Success
[cmake] -- Performing Test WARNING_C_FLAG_Wshadow
[cmake] -- Performing Test WARNING_C_FLAG_Wshadow - Success
[cmake] -- Performing Test WARNING_C_FLAG_Wswitch-default
[cmake] -- Performing Test WARNING_C_FLAG_Wswitch-default - Success
[cmake] -- Performing Test WARNING_C_FLAG_Wswitch-enum
[cmake] -- Performing Test WARNING_C_FLAG_Wswitch-enum - Success
[cmake] -- Performing Test WARNING_C_FLAG_Wconversion
[cmake] -- Performing Test WARNING_C_FLAG_Wconversion - Success
[cmake] -- Performing Test WARNING_C_FLAG_Wsign-conversion
[cmake] -- Performing Test WARNING_C_FLAG_Wsign-conversion - Success
[cmake] -- Performing Test WARNING_C_FLAG_Wno-padded
[cmake] -- Performing Test WARNING_C_FLAG_Wno-padded - Success
[cmake] -- Performing Test WARNING_C_FLAG_Wno-disabled-macro-expansion
[cmake] -- Performing Test WARNING_C_FLAG_Wno-disabled-macro-expansion - Success
[cmake] -- Performing Test WARNING_C_FLAG_Wno-reserved-id-macro
[cmake] -- Performing Test WARNING_C_FLAG_Wno-reserved-id-macro - Success
[cmake] -- Performing Test WARNING_C_FLAG_Wno-keyword-macro
[cmake] -- Performing Test WARNING_C_FLAG_Wno-keyword-macro - Success
[cmake] -- Performing Test WARNING_C_FLAG_Wno-long-long
[cmake] -- Performing Test WARNING_C_FLAG_Wno-long-long - Success
[cmake] -- Performing Test WARNING_C_FLAG_Werror
[cmake] -- Performing Test WARNING_C_FLAG_Werror - Success
[cmake] -- Performing Test WARNING_C_FLAG_Wstrict-prototypes
[cmake] -- Performing Test WARNING_C_FLAG_Wstrict-prototypes - Success
[cmake] -- Performing Test WARNING_CXX_FLAG_Wall
[cmake] -- Performing Test WARNING_CXX_FLAG_Wall - Success
[cmake] -- Performing Test WARNING_CXX_FLAG_Wextra
[cmake] -- Performing Test WARNING_CXX_FLAG_Wextra - Success
[cmake] -- Performing Test WARNING_CXX_FLAG_pedantic
[cmake] -- Performing Test WARNING_CXX_FLAG_pedantic - Success
[cmake] -- Performing Test WARNING_CXX_FLAG_Wshadow
[cmake] -- Performing Test WARNING_CXX_FLAG_Wshadow - Success
[cmake] -- Performing Test WARNING_CXX_FLAG_Wswitch-default
[cmake] -- Performing Test WARNING_CXX_FLAG_Wswitch-default - Success
[cmake] -- Performing Test WARNING_CXX_FLAG_Wswitch-enum
[cmake] -- Performing Test WARNING_CXX_FLAG_Wswitch-enum - Success
[cmake] -- Performing Test WARNING_CXX_FLAG_Wconversion
[cmake] -- Performing Test WARNING_CXX_FLAG_Wconversion - Success
[cmake] -- Performing Test WARNING_CXX_FLAG_Wsign-conversion
[cmake] -- Performing Test WARNING_CXX_FLAG_Wsign-conversion - Success
[cmake] -- Performing Test WARNING_CXX_FLAG_Wno-padded
[cmake] -- Performing Test WARNING_CXX_FLAG_Wno-padded - Success
[cmake] -- Performing Test WARNING_CXX_FLAG_Wno-disabled-macro-expansion
[cmake] -- Performing Test WARNING_CXX_FLAG_Wno-disabled-macro-expansion - Success
[cmake] -- Performing Test WARNING_CXX_FLAG_Wno-reserved-id-macro
[cmake] -- Performing Test WARNING_CXX_FLAG_Wno-reserved-id-macro - Success
[cmake] -- Performing Test WARNING_CXX_FLAG_Wno-keyword-macro
[cmake] -- Performing Test WARNING_CXX_FLAG_Wno-keyword-macro - Success
[cmake] -- Performing Test WARNING_CXX_FLAG_Wno-long-long
[cmake] -- Performing Test WARNING_CXX_FLAG_Wno-long-long - Success
[cmake] -- Performing Test WARNING_CXX_FLAG_Werror
[cmake] -- Performing Test WARNING_CXX_FLAG_Werror - Success
[cmake] -- Performing Test WARNING_CXX_FLAG_Woverloaded-virtual
[cmake] -- Performing Test WARNING_CXX_FLAG_Woverloaded-virtual - Success
[cmake] -- Performing Test WARNING_CXX_FLAG_Wno-global-constructors
[cmake] -- Performing Test WARNING_CXX_FLAG_Wno-global-constructors - Success
[cmake] -- Performing Test WARNING_CXX_FLAG_Wno-exit-time-destructors
[cmake] -- Performing Test WARNING_CXX_FLAG_Wno-exit-time-destructors - Success
[cmake] -- Performing Test WARNING_CXX_FLAG_Wno-weak-vtables
[cmake] -- Performing Test WARNING_CXX_FLAG_Wno-weak-vtables - Success
[cmake] -- Performing Test WARNING_CXX_FLAG_Wno-old-style-cast
[cmake] -- Performing Test WARNING_CXX_FLAG_Wno-old-style-cast - Success
[cmake] -- Looking for FE_DIVBYZERO
[cmake] -- Looking for FE_DIVBYZERO - found
[cmake] -- Looking for fork
[cmake] -- Looking for fork - not found
[cmake] -- Looking for waitpid
[cmake] -- Looking for waitpid - not found
[cmake] -- Looking for gettimeofday
[cmake] -- Looking for gettimeofday - not found
[cmake] -- Looking for pthread_mutex_lock
[cmake] -- Looking for pthread_mutex_lock - not found
[cmake] -- Looking for strdup
[cmake] -- Looking for strdup - not found
[cmake] 
[cmake] -------------------------------------------------------
[cmake] CppUTest Version 4.0
[cmake] 
[cmake] Current compiler options:
[cmake]     CC:                                 C:/Program Files/LLVM/bin/clang.exe
[cmake]     CXX:                                C:/Program Files/LLVM/bin/clang++.exe
[cmake]     CppUTest CFLAGS:                     -include "D:/gitrepo/cpputest/include/CppUTest/MemoryLeakDetectorMallocMacros.h"  -Wall -Wextra -pedantic -Wshadow -Wswitch-default -Wswitch-enum -Wconversion -Wsign-conversion -Wno-padded -Wno-disabled-macro-expansion -Wno-reserved-id-macro -Wno-keyword-macro -Wno-long-long -Werror -Wstrict-prototypes
[cmake]     CppUTest CXXFLAGS:                   -include "D:/gitrepo/cpputest/include/CppUTest/MemoryLeakDetectorNewMacros.h" -include "D:/gitrepo/cpputest/include/CppUTest/MemoryLeakDetectorMallocMacros.h"  -Wall -Wextra -pedantic -Wshadow -Wswitch-default -Wswitch-enum -Wconversion -Wsign-conversion -Wno-padded -Wno-disabled-macro-expansion -Wno-reserved-id-macro -Wno-keyword-macro -Wno-long-long -Werror -Woverloaded-virtual -Wno-global-constructors -Wno-exit-time-destructors -Wno-weak-vtables -Wno-old-style-cast
[cmake]     CppUTest LDFLAGS:                   
[cmake] 
[cmake] Features configured in CppUTest:
[cmake]     Memory Leak Detection Disabled:     OFF
[cmake]     Compiling Extensions:               ON
[cmake]     Support Long Long:                  ON
[cmake]     Use CppUTest flags:                 ON
[cmake] 
[cmake]     Disable Standard C library:         OFF
[cmake]     Disable Standard C++ library:       OFF
[cmake] 
[cmake]     Generating map file:                OFF
[cmake]     Compiling with coverage:            OFF
[cmake] 
[cmake]     Compile and run self-tests          ON
[cmake]     Run self-tests separately           OFF
[cmake] 
[cmake] Library name options:
[cmake]     Add architecture bitsize (32/64)    OFF
[cmake]     Add debug compilation indicator     OFF
[cmake] 
[cmake] -------------------------------------------------------
[cmake] 
[cmake] -- Configuring done
[cmake] -- Generating done
[cmake] -- Build files have been written to: D:/gitrepo/cpputest/build

@itavero
Copy link
Contributor Author

itavero commented Sep 9, 2022

Just tried out your windows_s branch, but this still leaves the error I mentioned:

[build] CMake Error at D:/gitrepo/cpputest/cmake/Scripts/CppUTestBuildTimeDiscoverTests.cmake:49 (message):
[build]   Executable "D:/gitrepo/cpputest/build/tests/CppUTest/CppUTestTests.exe -lg"
[build]   failed with output:
[build] 
[build]   Access violation
[build] 
[build]   Please check that the excutable was added.
[build] Call Stack (most recent call first):
[build]   D:/gitrepo/cpputest/cmake/Scripts/CppUTestBuildTimeDiscoverTests.cmake:82 (buildtime_discover_tests)
[build] 
[build] 

Might not be compiler specific but Windows specific, perhaps related to #1381?

@thetic
Copy link
Contributor

thetic commented Sep 9, 2022

Yeah, I haven't found a fix yet for this. Good find on #1381. From the limited investigation I've done so far, it looks like static initialization for the tests is running before PlatformSpecificMalloc is initialized, so memory allocation is failing before we even get to main.

@itavero
Copy link
Contributor Author

itavero commented Sep 9, 2022

That's indeed also what I noticed when doing a trial run on a project that previously used GCC + MinGW.
It gets a segfault because PlatformSpecificMalloc is null.

I'm not that familiar with C++ (mainly used C at my current job), so I couldn't really wrap my head around it as I would have expected the linker to determine the correct pointer.

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

2 participants