yhirose / cpp-peglib

A single file C++ header-only PEG (Parsing Expression Grammars) library
MIT License
900 stars 112 forks source link

Use Thread library in CMake for the samples #103

Closed XinzhaoZHU closed 4 years ago

XinzhaoZHU commented 4 years ago

When building on wsl2, it seems the peglint doesn't link against to the pthread library even when the cmake asks to link against pthread library in the CMake files. It's caused by a potential bug for Linux platform when using multiple-thread library. And it may be confused to see such a result.

to refine it, please use

find_package(Threads)

inner the main CMake, and for application like peglint, use

target_link_libraries(peglint Threads::Threads)

This will add option -pthread for both of the comipler and linker(not -lpthread only on linker), and it would solve the problem of linking against pthread issue on linux platform.

yhirose commented 4 years ago

@XinzhaoZHU, thank you for your feedback. Do you mean that the following code in CMakeLists.txt doesn't work on WSL2 environment?

https://github.com/yhirose/cpp-peglib/blob/ffbc58c1038b3c0a27f3287148785c9af0b6dda7/CMakeLists.txt#L33-L35

Since I don't have WSL2 environment yet, could you send a pull request including your fix? Thanks for your help!

XinzhaoZHU commented 4 years ago

The pull request have been issued.

I aslo checked the original one. It seems only the peglint binary would have no pthread link against when checking with ldd. Other binary files, calc* and test-main are all ok, on my WSL2 platform, with Ubuntu 20.04, CMAKE 3.16.3 and GCC 9.3.0.

After using Threads library, it's all okay. But it is still very strange to see this case.

yhirose commented 4 years ago

@XinzhaoZHU, I have just merged your pull request. Thanks for your help!