Fix the build failure with C++20 standard #302
Merged
Add this suggestion to a batch that can be applied as a single commit.
This suggestion is invalid because no changes were made to the code.
Suggestions cannot be applied while the pull request is closed.
Suggestions cannot be applied while viewing a subset of changes.
Only one suggestion per line can be applied in a batch.
Add this suggestion to a batch that can be applied as a single commit.
Applying suggestions on deleted lines is not supported.
You must change the existing code in this line in order to create a valid suggestion.
Outdated suggestions cannot be applied.
This suggestion has been applied or marked resolved.
Suggestions cannot be applied from pending reviews.
Suggestions cannot be applied on multi-line comments.
Suggestions cannot be applied while the pull request is queued to merge.
Suggestion cannot be applied right now. Please check back later.
Motivation
When building the project with the
-DCMAKE_CXX_STANDARD=20
option and GCC 11.3, it failed. There are two main reasons.One is the
ObjectPool.h
, see http://eel.is/c++draft/diff.cpp17.class#2In short, see the code below:
The other reason is deeply hidden and OS-specific. When building the target for the unit test, the
lib/
directory is added into the include directories. So for#include "Semaphore.h"
, theSemaphore.h
header will be looked up first in thelib/
directory. However, C++20 introduced a<semaphore>
header, which finds the POSIX semaphore headersemaphore.h
in the system path.For example, the include order in
ubuntu:22.04
arm64 container is:$PROJECT_DIR/lib/
(whereSemaphore.h
is)/usr/lib/gcc/aarch64-linux-gnu/11/include
(wheresemaphore.h
is)The C++ header might be case insensitive so the
lib/Semaphore.h
will be included by the<semaphore>
header, which is implicitly included by<thread>
. Our ownSemaphore.h
does not have the POSIX semaphore struct definitions so the build failed.Modifications
ObjectPool.h
lib/
directory from the included directories of the unit test and includelib/xxx.h
for header inlib/
directory.