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

Lack of inlining prevents import of lithium_http_backend.hh in multiple files #34

Closed
umut-h-toprak opened this issue Sep 13, 2020 · 2 comments
Labels
bug Something isn't working

Comments

@umut-h-toprak
Copy link

Hello and thanks for the library and documentation.

Today I tested a cmake-based project where I attempted to compartmentalize the codebase to define different api endpoints in different files. While doing so, I ran into difficulties while importing lithium_http_backend.hh.

There were "multiple definition" errors for the following variable and function definitions:

 `li::make_json_error(char const*)'; 
 `li::json_no_error()'; 
 `li::detect_encoding(char, char, char, char)'; 
 `li::async_fiber_context::epoll_mod(int, int)'; 
 `li::async_fiber_context::defer_fiber_resume(int)'; 
 `li::async_fiber_context::reassign_fd_to_fiber(int, int)'; 
 `li::url_unescape(std::basic_string_view<char, std::char_traits<char> >)'; 
 `li::http_async_impl::date_buf_size'; 
 `li::http_async_impl::date_buf'; 
 `li::http_benchmark_impl::error(std::__cxx11::basic_string<char, std::char_traits<char>, std::allocator<char> >)'; 
 `li::http_benchmark_close(std::vector<int, std::allocator<int> > const&)'; 
 `li::generate_secret_tracking_id[abi:cxx11]()'; 
 `li::async_fiber_context::epoll_add(int, int)'; 
 `li::async_fiber_context::defer(std::function<void ()> const&)'; 
 `li::http_benchmark_connect(int, int)'; 
 `li::http_benchmark(std::vector<int, std::allocator<int> > const&, int, int, std::basic_string_view<char, std::char_traits<char> >)'; 
 `li::http_async_impl::static_files[abi:cxx11]'; 
 `li::serve_file(std::__cxx11::basic_string<char, std::char_traits<char>, std::allocator<char> > const&, std::basic_string_view<char, std::char_traits<char> >, li::http_res>
 `li::make_url_parser_info[abi:cxx11](std::basic_string_view<char, std::char_traits<char> >)'; 
 `TLS init function for li::http_async_impl::static_files[abi:cxx11]'; 
 `li::ssl_context::openssl_initialized'; 

I manually added "inline" designations to these problematic variables and functions in the "compiled" .hh file. It compiled, and the program seems to work okay, but this is of course a horrible hack and not sustainable.

Am I using the library outside of its intended use practices or was this a bug?

Thank you

@matt-42
Copy link
Owner

matt-42 commented Sep 14, 2020

I'm fixing this bug. thanks for the report

@matt-42 matt-42 added the bug Something isn't working label Sep 14, 2020
@matt-42
Copy link
Owner

matt-42 commented Sep 14, 2020

Fixed in the last master commit. I also added a note about how to avoid multiple definitions: https://github.com/matt-42/lithium/blob/master/INSTALL.md#note-for-projects-linking-multiple-c-files

@matt-42 matt-42 closed this as completed Sep 14, 2020
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
bug Something isn't working
Projects
None yet
Development

No branches or pull requests

2 participants