本文共 15283 字,大约阅读时间需要 50 分钟。
日志器代码
log.h
#ifndef __SYLAR_LOG_H__#define __SYLAR_LOG_H__#include "singletojn.h"#include "util.h"#include #include #include #include #include #include #include #include #include #include #include
log.cc
#include "log.h"#include #include #include #include #include
util.h
#ifndef __SYLAR_UTIL_H__#define __SYLAR_UTIL_H__#include #include #include #include #include #include namespace sylar { pid_t GetThreadId();uint32_t GetFiberId();}#endif
util.cc
#include "util.h"#include namespace sylar { pid_t GetThreadId() { return syscall(SYS_gettid); }uint32_t GetFiberId(){ return 0;}}
singleton.h
#ifndef __SYLAR_SINGLETON_H__#define __SYLAR_SINGLETON_H__#include namespace sylar { template class Singleton { public: static T *GetInstance() { static T v; return &v; }};template class SingletonPtr { public: static std::shared_ptr GetInstance() { static std::shared_ptr v(new T); return v; }};}#endif
test.cc
#include "util.h"#include namespace sylar { pid_t GetThreadId() { return syscall(SYS_gettid); }uint32_t GetFiberId(){ return 0;}}
cmake_minimum_required(VERSION 2.8)project(sylar)set(CMAKE_VERBOSE_MAKEFILE ON)set(CMAKE_CXX_FLAGS "$ENV{CXXFLAGS} -rdynamic -O0 -g -std=c++11 -Wall -Wno-deprecated -Werror -Wno-unused-function")set(LIB_SRC sylar/log.cc sylar/util.cc )add_library(sylar SHARED ${LIB_SRC})#add_library(sylar_static STATIC ${LIB_SRC})#SET_TARGET_PROPERTIES(sylar_static PROPERTIES OUTPUT_NAME "sylar")add_executable(test tests/test.cc)add_dependencies(test sylar)target_link_libraries(test sylar)SET(EXECUTABLE_OUTPUT_PATH ${PROJECT_SOURCE_DIR}/bin)SET(LIBRARY_OUTPUT_PATH ${PROJECT_SOURCE_DIR}/lib)
转载地址:https://blog.csdn.net/m0_55292629/article/details/125262528 如侵犯您的版权,请留言回复原文章的地址,我们会给您删除此文章,给您带来不便请您谅解!