1

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.

George Pippos
  • 81
  • 1
  • 1
  • 5
  • What is `_logger`? What is `SpdLogLogger::Info`, what is `_logger->info`? How has `logger-Warn(...)` compiled? You are showing some `Warn`, but the error is in `Info`. You are hiding the important information. – 273K Oct 11 '21 at 05:57
  • 3
    `if (logger) { logger-Warn(` this won't compile. Please show a [mcve] – phuclv Oct 11 '21 at 06:48
  • I've updated the question with more info. Let me know if it is still insufficient. – George Pippos Oct 11 '21 at 14:21
  • Still not a [mcve]. We should be able to paste your code into a file and get the same error when we compile. Currently it can't be built because we don't have the declaration of `spdlog::async_logger`. – Nate Eldredge Oct 12 '21 at 13:41
  • Sorry, I'm not going to copy the declaration for that because it's part of the spdlog library. If I do that, I would be copying most of the library to my question which is unreasonable. Having said that, you can find the library headers here: https://github.com/gabime/spdlog/tree/v1.x/include/spdlog – George Pippos Oct 12 '21 at 23:22
  • After adding a semicolon after the _logger declaration and the closing }; of your class it seems to compile. https://godbolt.org/z/6oK47M1sq What is different in that example relative to your code? Any idea? – Stefan v.K. Nov 11 '21 at 10:46

0 Answers0