aws-c-common icon indicating copy to clipboard operation
aws-c-common copied to clipboard

rw_lock_test.c fails to compile on GCC 9.1

Open jweinst1 opened this issue 5 years ago • 4 comments

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

jweinst1 avatar Aug 28 '20 20:08 jweinst1

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()

jweinst1 avatar Aug 28 '20 20:08 jweinst1

If you check the compile command line, is -pthreads in there?

justinboswell avatar Aug 28 '20 20:08 justinboswell

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

justinboswell avatar Aug 28 '20 20:08 justinboswell

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

jweinst1 avatar Aug 28 '20 23:08 jweinst1