编译生成spdlog_app可执行程序
#Makefile
# 编译器
#COMPLITE=arm-none-linux-gnueabi-
#COMPLITE=/root/share/nuvoton_cross/arm_linux_4.8/bin/arm-nuvoton-linux-uclibceabi-
#/root/share/nuvoton_cross/host/usr/bin/
COMPLITE=arm-nuvoton-linux-gnueabi-
CC=$(COMPLITE)gcc
CXX=$(COMPLITE)g++
LD=$(COMPLITE)ld
# 编译选项
CFLAGS = -Wall
# 目标文件
TARGET = spdlog_app
OBJ_DIR = build
# 源文件
# 当前目录下的.cpp
#SRCS = $(wildcard *.cpp)
#其他目录下的.cpp
SRCS += $(wildcard src/*.cpp)
SRCS_C= $(wildcard src/*.c)
CFLAGS=-I./
CPPFLAGS=-I./
LDFLAGS=-L./
LIBS=-lpthread -levent -lrt
#LIBS=
CFLAGS += -Wall
CPPFLAGS += -W -Wall -std=c++11 -Wno-psabi -lc
CFLAGS += -I ./include
CPPFLAGS += -I ./include
#-Wall -fPIC -shared
# 头文件
#CFLAGS += -Imodule1/inc
#CFLAGS += -Imodule2/inc
#CFLAGS += -Ipath/to/include2
# LIB
#CFLAGS += -Lpath/to/lib1
#CFLAGS += -Lpath/to/lib2
#添加宏定义
#CFLAGS += -DANDROID_OS
# 对象文件和中间文件目录
OBJS = $(SRCS:%.cpp=$(OBJ_DIR)/%.o)
OBJS += $(SRCS_C:%.c=$(OBJ_DIR)/%.o)
# 默认构建目标
all: $(TARGET)
# 生成可执行文件
$(TARGET): $(OBJS)
$(CXX) $(LDFLAGS) $(LIBS) -o $@ $^
# 生成根目录下的目标文件
$(OBJ_DIR)/%.o: %.cpp | $(OBJ_DIR)
#创建文件夹很关键,不然会fail
@mkdir -p $(dir $@)
$(CXX) $(CPPFLAGS) -c $< -o $@
# 生成根目录下的目标文件
$(OBJ_DIR)/%.o: %.c | $(OBJ_DIR)
#创建文件夹很关键,不然会fail
@mkdir -p $(dir $@)
$(CC) $(CFLAGS) -c $< -o $@
# 创建中间文件目录
$(OBJ_DIR):
mkdir -p $(OBJ_DIR)
clean:
@echo "clean:"
rm -rf $(OBJ_DIR)
rm -rf $(TARGET)
@echo "clean ok"
设置交叉编译工具链环境变量
root@ubuntu:~# source my_toolchain.sh
root@ubuntu:~# cat my_toolchain.sh
export PATH=$PATH:/root/share/nuvoton_cross/host/usr/bin
export PKG_CONFIG_LIBDIR=/root/share/nuvoton_cross/host/usr/lib/pkgconfig:/root/share/nuvoton_cross/host/usr/share/pkgconfig:$PKG_CONFIG_LIBDIR
export PKG_CONFIG_SYSROOT_DIR=/root/share/nuvoton_cross/host/usr/arm-nuvoton-linux-gnueabi/sysroot:$PKG_CONFIG_SYSROOT_DIR
root@ubuntu:~#
源码目录如下:
root@ubuntu:~/share/gateway/spdlog_wrap# tree
.
├── build
│ └── src
│ ├── spdlogWrap.o
│ └── test_main.o
├── include
│ ├── spdlog
│ │ ├── async.h
│ │ ├── async_logger.h
│ │ ├── common.h
│ │ ├── details
│ │ │ ├── async_logger_impl.h
│ │ │ ├── circular_q.h
│ │ │ ├── console_globals.h
│ │ │ ├── file_helper.h
│ │ │ ├── fmt_helper.h
│ │ │ ├── logger_impl.h
│ │ │ ├── log_msg.h
│ │ │ ├── mpmc_blocking_q.h
│ │ │ ├── null_mutex.h
│ │ │ ├── os.h
│ │ │ ├── pattern_formatter.h
│ │ │ ├── periodic_worker.h
│ │ │ ├── registry.h
│ │ │ └── thread_pool.h
│ │ ├── fmt
│ │ │ ├── bin_to_hex.h
│ │ │ ├── bundled
│ │ │ │ ├── chrono.h
│ │ │ │ ├── color.h
│ │ │ │ ├── core.h
│ │ │ │ ├── format.h
│ │ │ │ ├── format-inl.h
│ │ │ │ ├── LICENSE.rst
│ │ │ │ ├── locale.h
│ │ │ │ ├── ostream.h
│ │ │ │ ├── posix.h
│ │ │ │ ├── printf.h
│ │ │ │ ├── ranges.h
│ │ │ │ └── time.h
│ │ │ ├── fmt.h
│ │ │ └── ostr.h
│ │ ├── formatter.h
│ │ ├── logger.h
│ │ ├── sinks
│ │ │ ├── android_sink.h
│ │ │ ├── ansicolor_sink.h
│ │ │ ├── base_sink.h
│ │ │ ├── basic_file_sink.h
│ │ │ ├── daily_file_sink.h
│ │ │ ├── dist_sink.h
│ │ │ ├── msvc_sink.h
│ │ │ ├── null_sink.h
│ │ │ ├── ostream_sink.h
│ │ │ ├── rotating_file_sink.h
│ │ │ ├── sink.h
│ │ │ ├── stdout_color_sinks.h
│ │ │ ├── stdout_sinks.h
│ │ │ ├── syslog_sink.h
│ │ │ └── wincolor_sink.h
│ │ ├── spdlog.h
│ │ ├── tweakme.h
│ │ └── version.h
│ ├── spdlogWrap.h
│ └── spdlogWrapM.h
├── makefile
├── spdlog_app
└── src
├── spdlogWrap.cpp
└── test_main.cpp
9 directories, 60 files
root@ubuntu:~/share/gateway/spdlog_wrap#
root@ubuntu:~/share/gateway/spdlog_wrap# make clean
clean:
rm -rf build
rm -rf spdlog_app
clean ok
root@ubuntu:~/share/gateway/spdlog_wrap# make all
mkdir -p build
arm-nuvoton-linux-gnueabi-g++ -I./ -W -Wall -std=c++11 -Wno-psabi -lc -I ./include -c src/test_main.cpp -o build/src/test_main.o
arm-nuvoton-linux-gnueabi-g++ -I./ -W -Wall -std=c++11 -Wno-psabi -lc -I ./include -c src/spdlogWrap.cpp -o build/src/spdlogWrap.o
src/spdlogWrap.cpp:22:10: warning: unused parameter ‘queuesize’ [-Wunused-parameter]
bool spdlogWrap::Initspdlog(const char* logfile, unsigned int queuesize, unsigned int filesize, unsigned int backnum,\
^
arm-nuvoton-linux-gnueabi-g++ -L./ -lpthread -levent -lrt -o spdlog_app build/src/test_main.o build/src/spdlogWrap.o
root@ubuntu:~/share/gateway/spdlog_wrap# ls -la
total 1408
drwxr-xr-x 5 root root 4096 Nov 27 22:04 .
drwxr-xr-x 7 root root 4096 Nov 17 20:20 ..
drwxr-xr-x 3 root root 4096 Nov 27 22:03 build
drwxr-xr-x 3 root root 4096 Nov 25 20:59 include
-rwxr--r-- 1 root root 1687 Nov 17 19:18 makefile
-rwxr-xr-x 1 root root 1416036 Nov 27 22:04 spdlog_app
drwxr-xr-x 2 root root 4096 Nov 25 21:14 src
root@ubuntu:~/share/gateway/spdlog_wrap#