matt-42 / lithium

Easy to use C++17 HTTP Server with no compromise on performances. https://matt-42.github.io/lithium
https://matt-42.github.io/lithium
MIT License
1.26k stars 91 forks source link

Can't run Lithium locally #112

Closed vipulgupta2048 closed 2 years ago

vipulgupta2048 commented 2 years ago

I followed the instruction provided here https://matt-42.github.io/lithium/getting-started to install Lithium locally. I am not sure what the automatic symbol generation needs to because it generates nothing when I run it. I created my Cmake file as below:

cmake_minimum_required(VERSION 3.0)
set(CMAKE_CXX_STANDARD 17)

project(my_api)

find_package(CURL REQUIRED)
find_package(Boost REQUIRED context)
find_package(Threads REQUIRED)
find_package(OpenSSL REQUIRED)

include_directories(${CURL_INCLUDE_DIRS} ${OPENSSL_INCLUDE_DIR})

set(LIBS ${CURL_LIBRARIES} ${Boost_LIBRARIES} ${CMAKE_THREAD_LIBS_INIT} ${OPENSSL_LIBRARIES})

# Directory where lithium headers are located if not in the default include path.
include_directories(/home/vipulgupta2048/work/cpp-hello-world/include)

add_custom_target(symbols_generation COMMAND bin/li_symbol_generator ${CMAKE_CURRENT_SOURCE_DIR})

add_executable(my_api src/server.cc)
add_dependencies(my_api symbols_generation)

The code I am trying to compile is very simple on Linux Ubuntu 20.04 x86_64 GNU/Linux

#include <lithium_http_server.hh>

int main()
{
    li::http_api my_api;

    my_api.add_subapi("/public", li::serve_directory("/source/views/public"));

    my_api.get("/") = [&](li::http_request &request, li::http_response &response)
    {
        response.write_file("/source/views/index.html");
    };
    li::http_serve(my_api, 8080);
}

I am running the commands as mentioned in the Python li file to compile with

cmake .
make

I get the following error:

➜  cpp-hello-world git:(master) ✗ cmake .
-- Configuring done
-- Generating done
-- Build files have been written to: /home/vipulgupta2048/work/cpp-hello-world
➜  cpp-hello-world git:(master) ✗ make
[  0%] Built target symbols_generation
[ 50%] Building CXX object CMakeFiles/my_api.dir/src/server.cc.o
[100%] Linking CXX executable my_api
/usr/bin/ld: CMakeFiles/my_api.dir/src/server.cc.o: in function `boost::context::continuation::~continuation()':
server.cc:(.text._ZN5boost7context12continuationD2Ev[_ZN5boost7context12continuationD5Ev]+0x5f): undefined reference to `ontop_fcontext'
/usr/bin/ld: CMakeFiles/my_api.dir/src/server.cc.o: in function `boost::context::continuation::resume() &&':
server.cc:(.text._ZNO5boost7context12continuation6resumeEv[_ZNO5boost7context12continuation6resumeEv]+0x72): undefined reference to `jump_fcontext'
/usr/bin/ld: CMakeFiles/my_api.dir/src/server.cc.o: in function `li::ssl_context::~ssl_context()':
server.cc:(.text._ZN2li11ssl_contextD2Ev[_ZN2li11ssl_contextD5Ev]+0x27): undefined reference to `SSL_CTX_free'
/usr/bin/ld: CMakeFiles/my_api.dir/src/server.cc.o: in function `li::ssl_context::ssl_context(std::__cxx11::basic_string<char, std::char_traits<char>, std::allocator<char> > const&, std::__cxx11::basic_string<char, std::char_traits<char>, std::allocator<char> > const&, std::__cxx11::basic_string<char, std::char_traits<char>, std::allocator<char> > const&)':
server.cc:(.text._ZN2li11ssl_contextC2ERKNSt7__cxx1112basic_stringIcSt11char_traitsIcESaIcEEES8_S8_[_ZN2li11ssl_contextC5ERKNSt7__cxx1112basic_stringIcSt11char_traitsIcESaIcEEES8_S8_]+0x40): undefined reference to `OPENSSL_init_ssl'
/usr/bin/ld: server.cc:(.text._ZN2li11ssl_contextC2ERKNSt7__cxx1112basic_stringIcSt11char_traitsIcESaIcEEES8_S8_[_ZN2li11ssl_contextC5ERKNSt7__cxx1112basic_stringIcSt11char_traitsIcESaIcEEES8_S8_]+0x4f): undefined reference to `OPENSSL_init_ssl'
/usr/bin/ld: server.cc:(.text._ZN2li11ssl_contextC2ERKNSt7__cxx1112basic_stringIcSt11char_traitsIcESaIcEEES8_S8_[_ZN2li11ssl_contextC5ERKNSt7__cxx1112basic_stringIcSt11char_traitsIcESaIcEEES8_S8_]+0x5b): undefined reference to `TLS_server_method'
/usr/bin/ld: server.cc:(.text._ZN2li11ssl_contextC2ERKNSt7__cxx1112basic_stringIcSt11char_traitsIcESaIcEEES8_S8_[_ZN2li11ssl_contextC5ERKNSt7__cxx1112basic_stringIcSt11char_traitsIcESaIcEEES8_S8_]+0x6b): undefined reference to `SSL_CTX_new'
/usr/bin/ld: server.cc:(.text._ZN2li11ssl_contextC2ERKNSt7__cxx1112basic_stringIcSt11char_traitsIcESaIcEEES8_S8_[_ZN2li11ssl_contextC5ERKNSt7__cxx1112basic_stringIcSt11char_traitsIcESaIcEEES8_S8_]+0x99): undefined reference to `ERR_print_errors_fp'
/usr/bin/ld: server.cc:(.text._ZN2li11ssl_contextC2ERKNSt7__cxx1112basic_stringIcSt11char_traitsIcESaIcEEES8_S8_[_ZN2li11ssl_contextC5ERKNSt7__cxx1112basic_stringIcSt11char_traitsIcESaIcEEES8_S8_]+0xd5): undefined reference to `SSL_CTX_set_cipher_list'
/usr/bin/ld: server.cc:(.text._ZN2li11ssl_contextC2ERKNSt7__cxx1112basic_stringIcSt11char_traitsIcESaIcEEES8_S8_[_ZN2li11ssl_contextC5ERKNSt7__cxx1112basic_stringIcSt11char_traitsIcESaIcEEES8_S8_]+0xf8): undefined reference to `ERR_print_errors_fp'
/usr/bin/ld: server.cc:(.text._ZN2li11ssl_contextC2ERKNSt7__cxx1112basic_stringIcSt11char_traitsIcESaIcEEES8_S8_[_ZN2li11ssl_contextC5ERKNSt7__cxx1112basic_stringIcSt11char_traitsIcESaIcEEES8_S8_]+0x128): undefined reference to `SSL_CTX_use_certificate_file'
/usr/bin/ld: server.cc:(.text._ZN2li11ssl_contextC2ERKNSt7__cxx1112basic_stringIcSt11char_traitsIcESaIcEEES8_S8_[_ZN2li11ssl_contextC5ERKNSt7__cxx1112basic_stringIcSt11char_traitsIcESaIcEEES8_S8_]+0x140): undefined reference to `ERR_print_errors_fp'
/usr/bin/ld: server.cc:(.text._ZN2li11ssl_contextC2ERKNSt7__cxx1112basic_stringIcSt11char_traitsIcESaIcEEES8_S8_[_ZN2li11ssl_contextC5ERKNSt7__cxx1112basic_stringIcSt11char_traitsIcESaIcEEES8_S8_]+0x170): undefined reference to `SSL_CTX_use_PrivateKey_file'
/usr/bin/ld: server.cc:(.text._ZN2li11ssl_contextC2ERKNSt7__cxx1112basic_stringIcSt11char_traitsIcESaIcEEES8_S8_[_ZN2li11ssl_contextC5ERKNSt7__cxx1112basic_stringIcSt11char_traitsIcESaIcEEES8_S8_]+0x188): undefined reference to `ERR_print_errors_fp'
/usr/bin/ld: CMakeFiles/my_api.dir/src/server.cc.o: in function `li::async_fiber_context::ssl_handshake(std::unique_ptr<li::ssl_context, std::default_delete<li::ssl_context> >&)':
server.cc:(.text._ZN2li19async_fiber_context13ssl_handshakeERSt10unique_ptrINS_11ssl_contextESt14default_deleteIS2_EE[_ZN2li19async_fiber_context13ssl_handshakeERSt10unique_ptrINS_11ssl_contextESt14default_deleteIS2_EE]+0x44): undefined reference to `SSL_new'
/usr/bin/ld: server.cc:(.text._ZN2li19async_fiber_context13ssl_handshakeERSt10unique_ptrINS_11ssl_contextESt14default_deleteIS2_EE[_ZN2li19async_fiber_context13ssl_handshakeERSt10unique_ptrINS_11ssl_contextESt14default_deleteIS2_EE]+0x65): undefined reference to `SSL_set_fd'
/usr/bin/ld: server.cc:(.text._ZN2li19async_fiber_context13ssl_handshakeERSt10unique_ptrINS_11ssl_contextESt14default_deleteIS2_EE[_ZN2li19async_fiber_context13ssl_handshakeERSt10unique_ptrINS_11ssl_contextESt14default_deleteIS2_EE]+0x75): undefined reference to `SSL_accept'
/usr/bin/ld: server.cc:(.text._ZN2li19async_fiber_context13ssl_handshakeERSt10unique_ptrINS_11ssl_contextESt14default_deleteIS2_EE[_ZN2li19async_fiber_context13ssl_handshakeERSt10unique_ptrINS_11ssl_contextESt14default_deleteIS2_EE]+0xa0): undefined reference to `SSL_get_error'
/usr/bin/ld: server.cc:(.text._ZN2li19async_fiber_context13ssl_handshakeERSt10unique_ptrINS_11ssl_contextESt14default_deleteIS2_EE[_ZN2li19async_fiber_context13ssl_handshakeERSt10unique_ptrINS_11ssl_contextESt14default_deleteIS2_EE]+0xcc): undefined reference to `ERR_print_errors_fp'
/usr/bin/ld: CMakeFiles/my_api.dir/src/server.cc.o: in function `li::async_fiber_context::~async_fiber_context()':
server.cc:(.text._ZN2li19async_fiber_contextD2Ev[_ZN2li19async_fiber_contextD5Ev]+0x29): undefined reference to `SSL_shutdown'
/usr/bin/ld: server.cc:(.text._ZN2li19async_fiber_contextD2Ev[_ZN2li19async_fiber_contextD5Ev]+0x39): undefined reference to `SSL_free'
/usr/bin/ld: CMakeFiles/my_api.dir/src/server.cc.o: in function `li::async_fiber_context::read_impl(char*, int)':
server.cc:(.text._ZN2li19async_fiber_context9read_implEPci[_ZN2li19async_fiber_context9read_implEPci]+0x3a): undefined reference to `SSL_read'
/usr/bin/ld: CMakeFiles/my_api.dir/src/server.cc.o: in function `li::async_fiber_context::write_impl(char const*, int)':
server.cc:(.text._ZN2li19async_fiber_context10write_implEPKci[_ZN2li19async_fiber_context10write_implEPKci]+0x3a): undefined reference to `SSL_write'
/usr/bin/ld: CMakeFiles/my_api.dir/src/server.cc.o: in function `_ZNSt6threadC1IZN2li16start_tcp_serverIZNS1_15http_async_impl19make_http_processorIZNS1_10http_serveIJEEEvNS1_3apiINS1_12http_requestENS1_13http_responseEEEiDpT_EUlRT_E_EEDaSC_EUlSD_E_EEvNSt7__cxx1112basic_stringIcSt11char_traitsIcESaIcEEEiiiSC_SL_SL_SL_EUlvE_JEvEEOSC_DpOT0_':
server.cc:(.text._ZNSt6threadC2IZN2li16start_tcp_serverIZNS1_15http_async_impl19make_http_processorIZNS1_10http_serveIJEEEvNS1_3apiINS1_12http_requestENS1_13http_responseEEEiDpT_EUlRT_E_EEDaSC_EUlSD_E_EEvNSt7__cxx1112basic_stringIcSt11char_traitsIcESaIcEEEiiiSC_SL_SL_SL_EUlvE_JEvEEOSC_DpOT0_[_ZNSt6threadC5IZN2li16start_tcp_serverIZNS1_15http_async_impl19make_http_processorIZNS1_10http_serveIJEEEvNS1_3apiINS1_12http_requestENS1_13http_responseEEEiDpT_EUlRT_E_EEDaSC_EUlSD_E_EEvNSt7__cxx1112basic_stringIcSt11char_traitsIcESaIcEEEiiiSC_SL_SL_SL_EUlvE_JEvEEOSC_DpOT0_]+0x33): undefined reference to `pthread_create'
/usr/bin/ld: CMakeFiles/my_api.dir/src/server.cc.o: in function `_ZN5boost7context6callccIZN2li13async_reactor10event_loopIZNS2_15http_async_impl19make_http_processorIZNS2_10http_serveIJEEEvNS2_3apiINS2_12http_requestENS2_13http_responseEEEiDpT_EUlRT_E_EEDaSE_EUlSF_E_EEviSE_EUlONS0_12continuationEE0_vEESI_OSE_':
server.cc:(.text._ZN5boost7context6callccIZN2li13async_reactor10event_loopIZNS2_15http_async_impl19make_http_processorIZNS2_10http_serveIJEEEvNS2_3apiINS2_12http_requestENS2_13http_responseEEEiDpT_EUlRT_E_EEDaSE_EUlSF_E_EEviSE_EUlONS0_12continuationEE0_vEESI_OSE_[_ZN5boost7context6callccIZN2li13async_reactor10event_loopIZNS2_15http_async_impl19make_http_processorIZNS2_10http_serveIJEEEvNS2_3apiINS2_12http_requestENS2_13http_responseEEEiDpT_EUlRT_E_EEDaSE_EUlSF_E_EEviSE_EUlONS0_12continuationEE0_vEESI_OSE_]+0x34): undefined reference to `boost::context::stack_traits::default_size()'
/usr/bin/ld: CMakeFiles/my_api.dir/src/server.cc.o: in function `_ZNO5boost7context12continuation11resume_withIZN2li13async_reactor10event_loopIZNS3_15http_async_impl19make_http_processorIZNS3_10http_serveIJEEEvNS3_3apiINS3_12http_requestENS3_13http_responseEEEiDpT_EUlRT_E_EEDaSF_EUlSG_E_EEviSF_EUlOSF_E_EES1_SJ_':
server.cc:(.text._ZNO5boost7context12continuation11resume_withIZN2li13async_reactor10event_loopIZNS3_15http_async_impl19make_http_processorIZNS3_10http_serveIJEEEvNS3_3apiINS3_12http_requestENS3_13http_responseEEEiDpT_EUlRT_E_EEDaSF_EUlSG_E_EEviSF_EUlOSF_E_EES1_SJ_[_ZNO5boost7context12continuation11resume_withIZN2li13async_reactor10event_loopIZNS3_15http_async_impl19make_http_processorIZNS3_10http_serveIJEEEvNS3_3apiINS3_12http_requestENS3_13http_responseEEEiDpT_EUlRT_E_EEDaSF_EUlSG_E_EEviSF_EUlOSF_E_EES1_SJ_]+0xa0): undefined reference to `ontop_fcontext'
/usr/bin/ld: CMakeFiles/my_api.dir/src/server.cc.o: in function `_ZN5boost7context6detail15create_context1INS1_6recordINS0_12continuationENS0_21basic_fixedsize_stackINS0_12stack_traitsEEEZN2li13async_reactor10event_loopIZNS8_15http_async_impl19make_http_processorIZNS8_10http_serveIJEEEvNS8_3apiINS8_12http_requestENS8_13http_responseEEEiDpT_EUlRT_E_EEDaSK_EUlSL_E_EEviSK_EUlOS4_E0_EES7_SP_EEPvOT0_OT1_':
server.cc:(.text._ZN5boost7context6detail15create_context1INS1_6recordINS0_12continuationENS0_21basic_fixedsize_stackINS0_12stack_traitsEEEZN2li13async_reactor10event_loopIZNS8_15http_async_impl19make_http_processorIZNS8_10http_serveIJEEEvNS8_3apiINS8_12http_requestENS8_13http_responseEEEiDpT_EUlRT_E_EEDaSK_EUlSL_E_EEviSK_EUlOS4_E0_EES7_SP_EEPvOT0_OT1_[_ZN5boost7context6detail15create_context1INS1_6recordINS0_12continuationENS0_21basic_fixedsize_stackINS0_12stack_traitsEEEZN2li13async_reactor10event_loopIZNS8_15http_async_impl19make_http_processorIZNS8_10http_serveIJEEEvNS8_3apiINS8_12http_requestENS8_13http_responseEEEiDpT_EUlRT_E_EEDaSK_EUlSL_E_EEviSK_EUlOS4_E0_EES7_SP_EEPvOT0_OT1_]+0x104): undefined reference to `make_fcontext'
/usr/bin/ld: server.cc:(.text._ZN5boost7context6detail15create_context1INS1_6recordINS0_12continuationENS0_21basic_fixedsize_stackINS0_12stack_traitsEEEZN2li13async_reactor10event_loopIZNS8_15http_async_impl19make_http_processorIZNS8_10http_serveIJEEEvNS8_3apiINS8_12http_requestENS8_13http_responseEEEiDpT_EUlRT_E_EEDaSK_EUlSL_E_EEviSK_EUlOS4_E0_EES7_SP_EEPvOT0_OT1_[_ZN5boost7context6detail15create_context1INS1_6recordINS0_12continuationENS0_21basic_fixedsize_stackINS0_12stack_traitsEEEZN2li13async_reactor10event_loopIZNS8_15http_async_impl19make_http_processorIZNS8_10http_serveIJEEEvNS8_3apiINS8_12http_requestENS8_13http_responseEEEiDpT_EUlRT_E_EEDaSK_EUlSL_E_EEviSK_EUlOS4_E0_EES7_SP_EEPvOT0_OT1_]+0x141): undefined reference to `jump_fcontext'
/usr/bin/ld: CMakeFiles/my_api.dir/src/server.cc.o: in function `_ZN5boost7context6detail13context_entryINS1_6recordINS0_12continuationENS0_21basic_fixedsize_stackINS0_12stack_traitsEEEZN2li13async_reactor10event_loopIZNS8_15http_async_impl19make_http_processorIZNS8_10http_serveIJEEEvNS8_3apiINS8_12http_requestENS8_13http_responseEEEiDpT_EUlRT_E_EEDaSK_EUlSL_E_EEviSK_EUlOS4_E0_EEEEvNS1_10transfer_tE':
server.cc:(.text._ZN5boost7context6detail13context_entryINS1_6recordINS0_12continuationENS0_21basic_fixedsize_stackINS0_12stack_traitsEEEZN2li13async_reactor10event_loopIZNS8_15http_async_impl19make_http_processorIZNS8_10http_serveIJEEEvNS8_3apiINS8_12http_requestENS8_13http_responseEEEiDpT_EUlRT_E_EEDaSK_EUlSL_E_EEviSK_EUlOS4_E0_EEEEvNS1_10transfer_tE[_ZN5boost7context6detail13context_entryINS1_6recordINS0_12continuationENS0_21basic_fixedsize_stackINS0_12stack_traitsEEEZN2li13async_reactor10event_loopIZNS8_15http_async_impl19make_http_processorIZNS8_10http_serveIJEEEvNS8_3apiINS8_12http_requestENS8_13http_responseEEEiDpT_EUlRT_E_EEDaSK_EUlSL_E_EEviSK_EUlOS4_E0_EEEEvNS1_10transfer_tE]+0x80): undefined reference to `jump_fcontext'
/usr/bin/ld: server.cc:(.text._ZN5boost7context6detail13context_entryINS1_6recordINS0_12continuationENS0_21basic_fixedsize_stackINS0_12stack_traitsEEEZN2li13async_reactor10event_loopIZNS8_15http_async_impl19make_http_processorIZNS8_10http_serveIJEEEvNS8_3apiINS8_12http_requestENS8_13http_responseEEEiDpT_EUlRT_E_EEDaSK_EUlSL_E_EEviSK_EUlOS4_E0_EEEEvNS1_10transfer_tE[_ZN5boost7context6detail13context_entryINS1_6recordINS0_12continuationENS0_21basic_fixedsize_stackINS0_12stack_traitsEEEZN2li13async_reactor10event_loopIZNS8_15http_async_impl19make_http_processorIZNS8_10http_serveIJEEEvNS8_3apiINS8_12http_requestENS8_13http_responseEEEiDpT_EUlRT_E_EEDaSK_EUlSL_E_EEviSK_EUlOS4_E0_EEEEvNS1_10transfer_tE]+0xe1): undefined reference to `ontop_fcontext'
/usr/bin/ld: CMakeFiles/my_api.dir/src/server.cc.o: in function `std::thread::thread<li::http_serve<>(li::api<li::http_request, li::http_response>, int)::{lambda()#2}, , void>(li::http_serve<>(li::api<li::http_request, li::http_response>, int)::{lambda()#2}&&)':
server.cc:(.text._ZNSt6threadC2IZN2li10http_serveIJEEEvNS1_3apiINS1_12http_requestENS1_13http_responseEEEiDpT_EUlvE0_JEvEEOT_DpOT0_[_ZNSt6threadC5IZN2li10http_serveIJEEEvNS1_3apiINS1_12http_requestENS1_13http_responseEEEiDpT_EUlvE0_JEvEEOT_DpOT0_]+0x33): undefined reference to `pthread_create'
/usr/bin/ld: CMakeFiles/my_api.dir/src/server.cc.o: in function `std::thread::thread<li::http_serve<>(li::api<li::http_request, li::http_response>, int)::{lambda()#3}, , void>(li::http_serve<>(li::api<li::http_request, li::http_response>, int)::{lambda()#3}&&)':
server.cc:(.text._ZNSt6threadC2IZN2li10http_serveIJEEEvNS1_3apiINS1_12http_requestENS1_13http_responseEEEiDpT_EUlvE1_JEvEEOT_DpOT0_[_ZNSt6threadC5IZN2li10http_serveIJEEEvNS1_3apiINS1_12http_requestENS1_13http_responseEEEiDpT_EUlvE1_JEvEEOT_DpOT0_]+0x3f): undefined reference to `pthread_create'
collect2: error: ld returned 1 exit status
make[2]: *** [CMakeFiles/my_api.dir/build.make:84: my_api] Error 1
make[1]: *** [CMakeFiles/Makefile2:77: CMakeFiles/my_api.dir/all] Error 2
make: *** [Makefile:84: all] Error 2
vipulgupta2048 commented 2 years ago

I have tried to follow instructions the best I could but it isn't working. Please do let me know if I am missing something?

vipulgupta2048 commented 2 years ago

Found the issue! Missed linking my libraries with the binary

cmake_minimum_required(VERSION 3.0)
set(CMAKE_CXX_STANDARD 17)

project(my_api)

find_package(CURL REQUIRED)
find_package(Boost REQUIRED context)
find_package(Threads REQUIRED)
find_package(OpenSSL REQUIRED)

include_directories(${CURL_INCLUDE_DIRS} ${OPENSSL_INCLUDE_DIR})

set(LIBS ${CURL_LIBRARIES} ${Boost_LIBRARIES} ${CMAKE_THREAD_LIBS_INIT} ${OPENSSL_LIBRARIES})

# Directory where lithium headers are located if not in the default include path.
include_directories(/home/vipulgupta2048/work/cpp-hello-world/include)

add_custom_target(symbols_generation COMMAND bin/li_symbol_generator ${CMAKE_CURRENT_SOURCE_DIR})

add_executable(my_api src/server.cc)
add_dependencies(my_api symbols_generation)
target_link_libraries(my_api ${LIBS})