Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Unable to build hello-world on local install #62

Closed
wbmartin opened this issue Mar 21, 2021 · 4 comments
Closed

Unable to build hello-world on local install #62

wbmartin opened this issue Mar 21, 2021 · 4 comments

Comments

@wbmartin
Copy link

First, wanted to thank you for offering this tool to the community. I've been interested since I saw it win the TechEmpower Benchmark (Congratulations!). I am admittedly a bit rusty with my C++, so I may be missing something obvious. I ran the CLI/docker install and it worked great the first time, but complained about the port being already in use on subsequent runs. I can go back to that method if you suggest. I decided to try the local install on a new debian buster install.

I stumbled on the prerequisites needed, but I think I got past that with this:

apt-get install libcurl4-openssl-dev
apt-get install libboost-all-dev

I also had to modify the install.sh g++ command, adding " -lstdc++fs" in two places to get it to build, guessing it is a debian quirk related to the filesystem library.

g++ -O3 -DNDEBUG -lstdc++fs -std=c++17 $DIR/libraries/symbol/symbol/symbol_generator.cc -o $PREFIX/bin/li_symbol_generator -lstdc++fs

Then I tried a fresh project with a copy of the hello_world script in my_api.cc (to follow the cmake_project_template):

#include "lithium_http_server.hh"

int main() {

  // Define an api with one HTTP GET route.
  li::http_api api;
  api.get("/hello_world") = [&](li::http_request& request, li::http_response& response) {
    response.write("hello world.");
  };

  // Start a http server.
  li::http_serve(api, 12345);

}

and the CMakeLists.txt from the cmake_project_template, removing the mysql and sqllite

cmake_minimum_required(VERSION 2.8)
set(CMAKE_CXX_STANDARD 17)

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

include_directories(${CURL_INCLUDE_DIRS} ${OPENSSL_INCLUDE_DIR} ${PostgreSQL_INCLUDE_DIRS})

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

# Directory where lithium headers are located if not in the default include path.
include_directories($ENV{HOME}/local/include)

add_custom_target(symbols_generation COMMAND li_symbol_generator ${CMAKE_CURRENT_SOURCE_DIR})

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


Then ran

mkdir build
cd build
cmake ..
make

but unfortunately I receive this error message:

[  0%] Built target symbols_generation
[ 50%] Building CXX object CMakeFiles/my_api.dir/my_api.cc.o
In file included from /home/brandon/proj/li-test-proj/my_api.cc:1:
/usr/local/include/lithium_http_server.hh: In instantiation of ‘auto li::http_serve(li::api<li::http_request, li::http_response>, int, O ...) [with O = {}]’:
/home/brandon/proj/li-test-proj/my_api.cc:12:28:   required from here
/usr/local/include/lithium_http_server.hh:6753:5: error: ‘this’ is not a constant expression
     if constexpr (has_key(options, s::ssl_key))
     ^~
/usr/local/include/lithium_http_server.hh:6755:28: error: non-constant condition for static assertion
       static_assert(has_key(options, s::ssl_certificate), "You need to provide both the ssl_certificate option and the ssl_key option.");
                     ~~~~~~~^~~~~~~~~~~~~~~~~~~~~~~~~~~~~
/usr/local/include/lithium_http_server.hh:6755:28: error: ‘this’ is not a constant expression
/usr/local/include/lithium_http_server.hh:6756:37: error: ‘const struct li::metamap<>’ has no member named ‘ssl_key’
       std::string ssl_key = options.ssl_key;
                             ~~~~~~~~^~~~~~~
/usr/local/include/lithium_http_server.hh:6757:38: error: ‘const struct li::metamap<>’ has no member named ‘ssl_certificate’
       std::string ssl_cert = options.ssl_certificate;
                              ~~~~~~~~^~~~~~~~~~~~~~~
/usr/local/include/lithium_http_server.hh:6759:7: error: ‘this’ is not a constant expression
       if constexpr (has_key(options, s::ssl_ciphers))
       ^~
/usr/local/include/lithium_http_server.hh:6761:31: error: ‘const struct li::metamap<>’ has no member named ‘ssl_ciphers’
         ssl_ciphers = options.ssl_ciphers;
                       ~~~~~~~~^~~~~~~~~~~
make[2]: *** [CMakeFiles/my_api.dir/build.make:63: CMakeFiles/my_api.dir/my_api.cc.o] Error 1
make[1]: *** [CMakeFiles/Makefile2:105: CMakeFiles/my_api.dir/all] Error 2
make: *** [Makefile:84: all] Error 2

I wanted to see if you could offer any suggestions as to what I did wrong?

@matt-42
Copy link
Owner

matt-42 commented Mar 22, 2021

Hi @wbmartin,
Thanks for the feedback, which version of g++ are you using ?

@wbmartin
Copy link
Author

Thanks for the quick response @matt-42. g++ -v yields "gcc version 8.3.0 (Debian 8.3.0-6)

@matt-42
Copy link
Owner

matt-42 commented Mar 22, 2021

gcc 8.3 is not supported, can you upgrade to g++ 9.3 or a more recent version ? It should work with this version.

@wbmartin
Copy link
Author

wbmartin commented Mar 22, 2021

@matt-42 that fixed it nicely. Thanks for the great support.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

No branches or pull requests

2 participants