oatpp / oatpp

🌱Light and powerful C++ web framework for highly scalable and resource-efficient web application. It's zero-dependency and easy-portable.
https://oatpp.io/
Apache License 2.0
7.59k stars 1.28k forks source link

Why my project can not link with pthread, when I want to build the sample where in document. #848

Open hps2002 opened 9 months ago

hps2002 commented 9 months ago

I'm a new user in oatpp, when I want to create my first demo with oatpp that is saying pthread_create undecalare in liboatpp.a. I had searched some soluve but haven't result;

These is my output after make my project :

[100%] Linking CXX executable /home/ubuntu/PictureBook/bin/RequestTest
/usr/local/bin/cmake -E cmake_link_script CMakeFiles/RequestTest.dir/link.txt --verbose=1
/usr/bin/c++ -rdynamic CMakeFiles/RequestTest.dir/tests/RequestHandleTest.cpp.o -o /home/ubuntu/PictureBook/bin/RequestTest   -L/usr/local/lib  -L/usr/local/lib/oatpp-1.3.0  -Wl,-rpath,/usr/local/lib:/usr/local/lib/oatpp-1.3.0 -lpthread -loatpp 
/usr/bin/ld: /usr/local/lib/oatpp-1.3.0/liboatpp.a(Server.cpp.o): in function `std::thread::thread<void (&)(oatpp::network::Server*), oatpp::network::Server*, void>(void (&)(oatpp::network::Server*), oatpp::network::Server*&&)':
/usr/include/c++/9/thread:126: undefined reference to `pthread_create'
/usr/bin/ld: /usr/local/lib/oatpp-1.3.0/liboatpp.a(HttpConnectionHandler.cpp.o): in function `std::thread::thread<void (oatpp::web::server::HttpProcessor::Task::*)(), oatpp::web::server::HttpProcessor::Task, void>(void (oatpp::web::server::HttpProcessor::Task::*&&)(), oatpp::web::server::HttpProcessor::Task&&)':
/usr/include/c++/9/thread:126: undefined reference to `pthread_create'
/usr/bin/ld: /usr/local/lib/oatpp-1.3.0/liboatpp.a(Thread.cpp.o): in function `oatpp::concurrency::setThreadAffinityToCpuRange(unsigned long, int, int)':
/home/ubuntu/apps/oatpp/src/oatpp/core/concurrency/Thread.cpp:57: undefined reference to `pthread_setaffinity_np'
collect2: error: ld returned 1 exit status

What should I do with cmake or rebuild the oatpp? Thank you!

These is CMakeList.txt:

cmake_minimum_required(VERSION 2.8)
project(PictureBook)

set(CMAKE_VERBOSE_MAKEFILE ON)
# set(CMAKE_CXX_FLAGS "$ENV{CXXFLAGS} -rdynamic -O0 -ggdb -std=c++11 -Wall -Wno-deprecated -Werror -Wno-unused-function -Wno-builtin-macro-redefined")

include_directories(.)
include_directories(/usr/local/include)
include_directories(/usr/local/include/oatpp-1.3.0)

link_directories(/usr/local/lib)
link_directories(/usr/local/lib/oatpp-1.3.0)

set(LIB_LIB
    pthread
    oatpp
)

add_executable(RequestTest tests/RequestHandleTest.cpp)
target_link_libraries(RequestTest ${LIB_LIB} )

set(EXECUTABLE_OUTPUT_PATH ${PROJECT_SOURCE_DIR}/bin)
set(LIBRARY_OUTPUT_PATH ${PROJECT_SOURCE_DIR}/lib)
hps2002 commented 9 months ago

Fix the problem, move 'pthread' after 'oatpp' when targe_link_libraries