I’m trying to package multiple 3rd parties into C++20 modules.
We are using CMake.
Latest CMake Versions have import std
support.
I have already packed some 3rd parties (like fmt) and everything working fine, however some spdlog stuff does not seam to work.
Since CMake does not yet import header units I’m using the “using” keyword to export all needed definitions
This is my module
// Global module fragment where #includes can happen
module;
//included headers will not be exported to the client
#include <spdlog/spdlog.h>
#include <spdlog/sinks/rotating_file_sink.h>
#include <spdlog/sinks/sink.h>
#include <spdlog/details/null_mutex.h>
#include <spdlog/sinks/stdout_color_sinks.h>
#include <spdlog/sinks/basic_file_sink.h>
#include <spdlog/sinks/daily_file_sink.h> //< this include causes the error
// first thing after the Global module fragment must be a module command
export module my_spdlog;
export
{
namespace spdlog::sinks
{
using ::spdlog::sinks::daily_file_sink_mt; //< this definition causes the error
using ::spdlog::sinks::rotating_file_sink_mt;
using ::spdlog::sinks::base_sink;
using ::spdlog::sinks::sink;
using ::spdlog::sinks::stdout_color_sink_mt;
using ::spdlog::sinks::basic_file_sink_mt;
}
namespace spdlog::details
{
using ::spdlog::details::console_mutex;
using ::spdlog::details::console_nullmutex;
using ::spdlog::details::registry;
using ::spdlog::details::null_mutex;
}
namespace spdlog
{
using ::spdlog::trace;
using ::spdlog::debug;
using ::spdlog::info;
using ::spdlog::warn;
using ::spdlog::error;
using ::spdlog::critical;
using ::spdlog::set_default_logger;
using ::spdlog::default_logger;
using ::spdlog::create;
using ::spdlog::drop_all;
using ::spdlog::set_level;
using ::spdlog::get;
using ::spdlog::register_logger;
using ::spdlog::set_error_handler;
using ::spdlog::flush_every;
using ::spdlog::set_pattern;
using ::spdlog::logger;
using ::spdlog::get;
using ::spdlog::drop;
using ::spdlog::set_pattern;
using ::spdlog::set_level;
using ::spdlog::set_error_handler;
using ::spdlog::register_logger;
using ::spdlog::set_default_logger;
using ::spdlog::default_logger;
using ::spdlog::flush_every;
using ::spdlog::sink_ptr;
using ::spdlog::stdout_color_mt;
using ::spdlog::stderr_color_mt;
using ::spdlog::spdlog_ex;
}
}
module: private;
//possible to include headers here, but they will not be exported to the client
This is a translation unit which consumes the module
#include <gtest/gtest.h>
import my_spdlog;
TEST(CxxModuleTest, spdlog)
{
const std::string strFilename = "test.log";
constexpr size_t nMaxFileSize = 1024 * 1024 * 5;
constexpr size_t nMaxFileCount = 3;
spdlog::sinks::rotating_file_sink_mt sink(strFilename, nMaxFileSize, nMaxFileCount);
spdlog::sinks::stdout_color_sink_mt console_sink;
}
now when compiling this I’m getting a compiler warning (which is treated as an error)
C5304
a declaration designated by the using-declaration 'std::mktime' exported from this module has internal linkage and using such a name outside the module is ill-formed; consider declaring 'time_t mktime(tm *const )' 'inline' to use it outside of this module
Do you have an idea how to fix this.
Should I redeclare mktime()?
(Obviously I can disable this warning but this is not what i want 😉
thx guys for your help 🙂