Skip to content

Implementations of templated methods are missing when splitting into .h and .cc #1008

@jrosdahl

Description

@jrosdahl

Thanks for writing cpp-httplib!

I made an attempt to use the non-header-only version of httplib (in ccache) to reduce the time to recompile code that uses the library. However, the templated implementation of e.g. set_connection_timeout ends up in httplib.cc and therefore results in a linker error since the needed template has not been instantiated.

It looks like these methods are affected:

template <typename T>
T Request::get_header_value(const char *key, size_t id = 0) const;

template <typename T>
T Response::get_header_value(const char *key, size_t id = 0) const;

template <typename... Args>
ssize_t Stream::write_format(const char *fmt, const Args &...args);

template <class Rep, class Period>
Server &Server::set_read_timeout(const std::chrono::duration<Rep, Period> &duration);

template <class Rep, class Period>
Server &set_write_timeout(const std::chrono::duration<Rep, Period> &duration);

template <class Rep, class Period>
Server &set_idle_interval(const std::chrono::duration<Rep, Period> &duration);

template <typename T>
T Result::get_request_header_value(const char *key, size_t id = 0) const;

template <class Rep, class Period>
void ClientImpl::set_connection_timeout(const std::chrono::duration<Rep, Period> &duration);

template <class Rep, class Period>
void ClientImpl::set_read_timeout(const std::chrono::duration<Rep, Period> &duration);

template <class Rep, class Period>
void ClientImpl::set_write_timeout(const std::chrono::duration<Rep, Period> &duration);

template <class Rep, class Period>
void Client::set_connection_timeout(const std::chrono::duration<Rep, Period> &duration);

template <class Rep, class Period>
void Client::set_read_timeout(const std::chrono::duration<Rep, Period> &duration);

template <class Rep, class Period>
void Client::set_write_timeout(const std::chrono::duration<Rep, Period> &duration);

Would you welcome a pull request that moves some or all of these into the header file part? If not, perhaps some caveat text could be added to the Split httplib.h into .h and .cc section?

Related: I tried to modify the test suite to run against a split version to make it possible to verify that the split version works, but I realized it will be impossible to do without moving the tests that depend on details into a separate test file. Is that something that would be of interest?

Metadata

Metadata

Assignees

No one assigned

    Labels

    No labels
    No labels

    Projects

    No projects

    Milestone

    No milestone

    Relationships

    None yet

    Development

    No branches or pull requests

    Issue actions