Skip to content

Commit 1751a33

Browse files
Fix pthread reference in example CMakeLists.txt + removal of executable (SolidWallOfCode#82)
* cmake was generating -lpthread at beginning of compiler call, resulting in a undefined pthread_create * added *.pc to .gitignore * added example executables to .gitignore * removed executable from repo
1 parent 75c7545 commit 1751a33

File tree

3 files changed

+12
-2
lines changed

3 files changed

+12
-2
lines changed

.gitignore

Lines changed: 6 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -4,6 +4,9 @@
44
*.swp
55
*.cbp
66

7+
# Pkg-config files
8+
*.pc
9+
710
# Compiled Dynamic libraries
811
*.so
912
*.dylib
@@ -17,7 +20,10 @@
1720
*.exe
1821
*.out
1922
*.app
23+
example/ex_diskstats
2024
example/ex_flat_space
25+
example/ex_host_file
26+
example/ex_lru_cache
2127
example/ex_netcompact
2228
example/ex_netdb
2329
unit_tests/test_libswoc

example/CMakeLists.txt

Lines changed: 6 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -30,14 +30,18 @@ endif()
3030

3131
add_executable(ex_lru_cache ex_lru_cache.cc)
3232
target_link_libraries(ex_lru_cache PUBLIC libswoc-static)
33+
34+
set(THREADS_PREFER_PTHREAD_FLAG ON) # Without this flag CMake may resort to just '-lpthread'
35+
find_package(Threads)
36+
3337
if (CMAKE_COMPILER_IS_GNUCXX)
3438
target_compile_options(ex_lru_cache PRIVATE -Wall -Wextra -Werror)
35-
target_link_options(ex_lru_cache PRIVATE -lpthread)
39+
target_link_libraries(ex_lru_cache PRIVATE Threads::Threads)
3640
endif()
3741

3842
add_executable(ex_host_file ex_host_file.cc)
3943
target_link_libraries(ex_host_file PUBLIC libswoc-static)
4044
if (CMAKE_COMPILER_IS_GNUCXX)
4145
target_compile_options(ex_host_file PRIVATE -Wall -Wextra -Werror)
42-
target_link_options(ex_host_file PRIVATE -lpthread)
46+
target_link_libraries(ex_host_file PRIVATE Threads::Threads)
4347
endif()

example/ex_diskstats

-942 KB
Binary file not shown.

0 commit comments

Comments
 (0)