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

Compile error on ubuntu: error: ‘format’ is not a constant expression #731

Open
d3cod3 opened this issue Oct 29, 2024 · 0 comments
Open

Comments

@d3cod3
Copy link

d3cod3 commented Oct 29, 2024

I've having a compile error on ubuntu boxes while trying to compile a custom chat application.
The problem came from the logger->warn("Public address changed: {}", addrs); line inside the getDhtConfig method ( copied from dhtchat.cpp example )

/usr/include/opendht/logger.h: In instantiation of ‘void dht::log::Logger::warn(S&&, Args&& ...) const [with S = const char (&)[27]; Args = {std::vector<dht::SockAddr, std::allocator<dht::SockAddr> >&}]’:
/home/user/Development/of_v0.12.0_linux64gcc6_release_Mosaic/addons/ofxOpenDHT/src/ofxOpenDHT.cpp:167:25:   required from here
/usr/include/opendht/logger.h:68:46: error: ‘format’ is not a constant expression
   68 |         logger(LogLevel::warning, fmt::format(format, args...));

same error on ubuntu 21.04 and 22.04

Solved wrapping the format string in fmt::runtime to disable compile-time checks

in logger.h file

changed this:

 template<typename S, typename... Args>
    inline void debug(S&& format, Args&&... args) const {
        logger(LogLevel::debug, fmt::format(format, args...));
    }
    template<typename S, typename... Args>
    inline void warn(S&& format, Args&&... args) const {
        logger(LogLevel::warning, fmt::format(format, args...));
    }
    template<typename S, typename... Args>
    inline void error(S&& format, Args&&... args) const {
        logger(LogLevel::error, fmt::format(format, args...));
    }

to this:

 template<typename S, typename... Args>
    inline void debug(S&& format, Args&&... args) const {
        logger(LogLevel::debug, fmt::format(fmt::runtime(format), args...));
    }
    template<typename S, typename... Args>
    inline void warn(S&& format, Args&&... args) const {
        logger(LogLevel::warning, fmt::format(fmt::runtime(format), args...));
    }
    template<typename S, typename... Args>
    inline void error(S&& format, Args&&... args) const {
        logger(LogLevel::error, fmt::format(fmt::runtime(format), args...));
    }

Don't now if this can cause problems, but now is compiling fine.

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

1 participant