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 · 5 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.

@aberaud
Copy link
Member

aberaud commented Dec 17, 2024

Thanks for the report,
What version of {fmt} do you use ?
Thanks

@d3cod3
Copy link
Author

d3cod3 commented Dec 18, 2024

fmt (GNU coreutils) 8.32

libfmt8 8.1.1+ds1-2
libfmt-dev 8.1.1+ds1-2

@ghenry
Copy link
Collaborator

ghenry commented Dec 26, 2024

Just got this testing on macOS on Sonoma. .configure didn't complain about no libfmnt:

In file included from ../include/opendht/dht.h:23:
../include/opendht/infohash.h:25:10: fatal error: 'fmt/core.h' file not found
   25 | #include <fmt/core.h>

I guess core.h is from a newer libfmt as doing brew install fmt sorted it:

brew install fmt
==> Downloading https://ghcr.io/v2/homebrew/core/fmt/manifests/11.1.0
################################################################################################################################# 100.0%
==> Fetching fmt
==> Downloading https://ghcr.io/v2/homebrew/core/fmt/blobs/sha256:43c8236da42ea4aaecd53306e72751f0d40d70c9e2b7a806cc184eab0549ba07
################################################################################################################################# 100.0%
==> Pouring fmt--11.1.0.arm64_sonoma.bottle.tar.gz
🍺  /opt/homebrew/Cellar/fmt/11.1.0: 29 files, 1MB
==> Running `brew cleanup fmt`..

Time to update the version check inconfigure.ac?

@ghenry
Copy link
Collaborator

ghenry commented Dec 26, 2024

I also get this after updating, so maybe a new issue to review configure.ac version checks in general?

../include/opendht/peer_discovery.h:28:10: fatal error: 'asio/steady_timer.hpp' file not found
   28 | #include <asio/steady_timer.hpp>

@ghenry
Copy link
Collaborator

ghenry commented Dec 26, 2024

I also get this after updating, so maybe a new issue to review configure.ac version checks in general?

../include/opendht/peer_discovery.h:28:10: fatal error: 'asio/steady_timer.hpp' file not found
   28 | #include <asio/steady_timer.hpp>

Which was fixed by:

==> Downloading https://ghcr.io/v2/homebrew/core/asio/manifests/1.30.2
################################################################################################################################# 100.0%
==> Fetching asio
==> Downloading https://ghcr.io/v2/homebrew/core/asio/blobs/sha256:8904055a14a4247b64b0b0109092dc16ec9b041a80b5575d41b19f4f68fa948d
################################################################################################################################# 100.0%
==> Pouring asio--1.30.2.arm64_sonoma.bottle.tar.gz
🍺  /opt/homebrew/Cellar/asio/1.30.2: 1,158 files, 39.2MB
==> Running `brew cleanup asio`.

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

3 participants