multiple definition一般是在.h头文件定义了变量和函数,解决方法:
使用static或者将函数及变量定义在.c、.cpp文件中。
undefined reference可能是函数定义的命名空间不对。
如果函数在头文件命名空间中声明,源文件的实现部分也要加namespace命名空间(类的话不用加)
#pragma once
#include <string>
#include <stdint.h>
#include <dlt/dlt.h>
namespace xx
{
namespace platform
{
namespace xx
{
static const char *DLT_LOG_APP_ID = "";
static char DLT_LOG_TEXT[1024];
extern DLT_DECLARE_CONTEXT(dlt_context)
/// CLASS NAME macro that retrieves the Class Name when ran from inside a class method. Needs __PRETTY_FUNCTION__ macro available to work and compile
#define __CLASS_NAME__ className(__PRETTY_FUNCTION__)
/// @fn inline std::string className(const std::string& prettyFunction)
/// @brief Function that gets the Class name from the __PRETTY_FUNCTION__ macro
/// @param[in] prettyFunction Pretty Function macro's string value to be parsed
/// @return char*
inline const char* className(const std::string& prettyFunction)
{
size_t colons = prettyFunction.find("::");
if (colons == std::string::npos)
{
return "::";
}
size_t begin = prettyFunction.substr(0,colons).rfind(" ") + 1;
size_t end = colons - begin;
return prettyFunction.substr(begin,end).c_str();
}
#define DLT_INITIALIZER(...) \
do { \
dlt_with_session_id(1); \
dlt_with_timestamp(1); \
dlt_with_ecu_id(1); \
dlt_verbose_mode(); \
DLT_REGISTER_APP(DLT_LOG_APP_ID, "Test Application for Logging"); \
DLT_REGISTER_CONTEXT(dlt_context, __CLASS_NAME__, "Context for Debug"); \
} while (0)
bool dlt_initialize(void);
#define DLT_LOG_ERR(...) sprintf(DLT_LOG_TEXT, __VA_ARGS__); \
DLT_LOG(dlt_context, DLT_LOG_ERROR, DLT_STRING(DLT_LOG_TEXT))
#define DLT_LOG_WARN(...) sprintf(DLT_LOG_TEXT, __VA_ARGS__); \
DLT_LOG(dlt_context, DLT_LOG_WARN, DLT_STRING(DLT_LOG_TEXT))
#define DLT_LOG_INFO(...) sprintf(DLT_LOG_TEXT, __VA_ARGS__); \
DLT_LOG(dlt_context, DLT_LOG_INFO, DLT_STRING(DLT_LOG_TEXT))
#define DLT_LOG_DEBUG(...) sprintf(DLT_LOG_TEXT, __VA_ARGS__); \
DLT_LOG(dlt_context, DLT_LOG_DEBUG, DLT_STRING(DLT_LOG_TEXT))
}
}
}
#include "dlt_log.h"
namespace xx
{
namespace platform
{
namespace xx
{
static const char *DLT_LOG_FILE = "";
static const uint32_t DLT_LOG_FILE_MAX_SIZE = 0x100000;
DLT_DECLARE_CONTEXT(dlt_context)
bool dlt_initialize(void)
{
if (dlt_init_file(DLT_LOG_FILE) < 0) /* log to file */
{
return false;
}
if (dlt_set_filesize_max(DLT_LOG_FILE_MAX_SIZE) < 0)
{
return false;
}
DLT_INITIALIZER( );
return true;
}
}
}
}