0

I have an issue building my library for aarch64. Note that this code builds and runs fine when building for x86.

I have a macro:

#define LOG_WARN(logger, message, ...) if (logger) { logger->Warn(message, __VA_ARGS__); }

I use it in the code like this:

auto logger = SpdLogLogger("TestLog", "testLog.log");
LOG_WARN(logger, "This is a log message with a number: {:d}.", 10);

And it calls a template member function of my logger class (which is a wrapper for spdlog). Note that you can find spdlog here: https://github.com/gabime/spdlog/tree/v1.x/include/spdlog. I am currently using commit 8826011.

#include "spdlog/spdlog.h"
#include "spdlog/async.h"
#include "spdlog/sinks/stdout_color_sinks.h"
#include "spdlog/sinks/rotating_file_sink.h"

#include <memory>
#include <array>
#include <chrono>

class SpdLogLogger
{
private:
    std::shared_ptr<spdlog::async_logger> _logger

public:
    SpdLogLogger(const char *loggerName, const char *filename,
                 const spdlog::level::level_enum &&logLevel = spdlog::level::level_enum::info)
    {        
        spdlog::init_thread_pool(8192, 4);

        auto stdout_sink = std::make_shared<spdlog::sinks::stdout_color_sink_mt>();
        auto rotating_sink = std::make_shared<spdlog::sinks::rotating_file_sink_mt>(filename, 1024 * 1024 * 10, 3);
        std::array<spdlog::sink_ptr, 2> sinks{stdout_sink, rotating_sink};
        _logger = std::make_shared<spdlog::async_logger>(loggerName, sinks.begin(), sinks.end(), spdlog::thread_pool(),
                                                         spdlog::async_overflow_policy::block);
        // spdlog::register_logger(_logger); // this allows logging from a static context to this log

        _logger->flush_on(spdlog::level::info);      // auto flush when "info" or higher message is logged
        _logger->set_level(logLevel);
        _logger->set_pattern("[%H:%M:%S %z] [%n] [%^---%L---%$] [thread %t] %v");
        spdlog::flush_every(std::chrono::seconds(5));// auto flush every 5 seconds
    }

    ~SpdLogLogger()// override
    {
        _logger->flush();
        spdlog::shutdown();
    }

    template <typename... Args>
    void Warn(const std::string_view &&message, Args &&...args) const
    {
        _logger->warn(message, std::forward<Args>(args)...);
    }

I am building with cmake 3.16.3 (c++20) and gcc 10.3.0 (from the Ubuntu 20.04 repo) on a raspberry pi 4:

SpdLogLogger.h: In instantiation of ‘void SpdLogLogger::Warn(const string_view&&, Args&& ...) const [with Args = {const long unsigned int&}; std::string_view = std::basic_string_view<char>]’:
CallingCode.cpp:34:9:   required from here
SpdLogLogger.h:67:22: error: ‘message’ is not a constant expression
   67 |         _logger->warn(message, std::forward<Args>(args)...);
      |         ~~~~~~~~~~~~~^~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~

I think this is a bug with the aarch64 version of gcc/g++ seeing as the x86 version of this compiles fine but wanted to run this by others to see if it is anything I might be doing.

4

0 回答 0