aws-c-common
aws-c-common copied to clipboard
rw_lock_test.c fails to compile on GCC 9.1
Using gcc 9.1 the following error is encountered when compiling tests
2020-08-28 03:43:13 In file included from contrib/aws-c-common-0.4.52/tests/rw_lock_test.c:16:
2020-08-28 03:43:13 contrib/aws-c-common-0.4.52/include/aws/common/rw_lock.h:21:5: error: unknown type name 'pthread_rwlock_t'
The included header is used fine in building the actual library for aws-c-common. A workaround is to pass in -DB UILD_TESTING=FALSE while running cmake to build the project, but this is clearly a bug. The configuring does find pthread.h. There might be a problem with how the gnu standard is determined for building the tests.
This does not happen on GCC 9.3
Possibly the following posix source defines need to be added to tests too
if (UNIX AND NOT APPLE AND NOT ${CMAKE_SYSTEM_NAME} MATCHES FreeBSD)
#this only gets applied to aws-c-common (not its consumers).
target_compile_definitions(${PROJECT_NAME} PRIVATE -D_POSIX_C_SOURCE=200809L -D_XOPEN_SOURCE=500)
endif()
If you check the compile command line, is -pthreads in there?
Usually that's the result of target_link_libraries(${MY_TARGET} Threads::Threads), which causes -pthreads to end up in the compile flags, which causes gcc to find the pthreads library it knows about. See also: https://github.com/awslabs/aws-c-common/blob/master/CMakeLists.txt#L83
Wouldn't this be due to the guards around pthread_rwlock_t in pthreads?
https://code.woboq.org/gcc/include/bits/pthreadtypes.h.html#83