1.移植环境:

2.移植glog:

1)解压

shunzhi@ubuntu:~/software$ tar -xvzf glog-0.3.3.tar.gz

2)新建一个安装目录

shunzhi@ubuntu:~/software$ cd glog-0.3.3/  
shunzhi@ubuntu:~/software/glog-0.3.3$ mkdir _install  

3)配置编译环境变量

shunzhi@ubuntu:~/software/glog-0.3.3$ ./configure --host=arm-hisiv500-linux --prefix=/home/shunzhi/software/glog-0.3.3/_install/  

4)编译glog库

shunzhi@ubuntu:~/software/glog-0.3.3$ make
shunzhi@ubuntu:~/software/glog-0.3.3$ make install

5)安装glog库

shunzhi@ubuntu:~/software/glog-0.3.3$ cd _install/
shunzhi@ubuntu:~/software/glog-0.3.3/_install$ ls
include  lib  share
然后将lib目录中的libglog.so.0文件拷贝到3519开发板的/usr/lib目录下。

3.测试:

1)测试程序
glog_hisi.c

    #include <stdio.h>
    #include <iostream>
    #include <sys/stat.h>
    #include <sys/types.h>
    #include <glog/logging.h>
    #include <glog/log_severity.h>

    int main(void)
    {
        char defpath[100] = "./log";
        //创建log文件夹
        mkdir("./log",0777);
        //log初始化
        google::InitGoogleLogging("New");

        FLAGS_colorlogtostderr = true;//设置输出到屏幕的日志显示相应颜色
        //FLAGS_servitysinglelog = true;// 用来按照等级区分log文件
        FLAGS_logbufsecs = 0;//缓冲日志输出,默认为30秒,此处改为立即输出
        FLAGS_max_log_size = 1; //最大日志大小为 100MB
        FLAGS_stop_logging_if_full_disk = true;//当磁盘被写满时,停止日志输出
        google::SetStderrLogging(google::GLOG_INFO); //设置级别 高于 google::INFO 的日志同时输出到屏幕

        //日志名称和输出地址
        char Info[50] = {0};
        char Warn[50] = {0};
        char Error[50] = {0};
        char Fatal[50] = {0};

        strcpy(Info, defpath);
        strcpy(Warn, defpath);
        strcpy(Error, defpath);
        strcpy(Fatal, defpath);

        strcat(Info, "/Info_");
        strcat(Warn, "/Warning_");
        strcat(Error, "/Error_");
        strcat(Fatal, "/Fatal_");
        google::SetLogDestination(google::GLOG_INFO,Info); 
        google::SetLogDestination(google::GLOG_WARNING,Warn); 
        google::SetLogDestination(google::GLOG_ERROR,Error); 
        google::SetLogDestination(google::GLOG_FATAL,Fatal); 
        LOG(INFO) <<"------------------------------"<<std::endl;
        LOG(INFO) <<"---------Creat Log!!!---------\n ";
        LOG(INFO) <<"------------------------------"<<std::endl;

        return 1;
    }
Makefile

    CC = arm-hisiv500-linux-g++
    #CC = g++

    DEMOTAR = glog_hisi
    DEMOOBJ = glog_hisi.o

    CFLAGS += -mcpu=cortex-a7 -mfloat-abi=softfp -mfpu=neon-vfpv4 -mno-unaligned-access -fno-aggressive-loop-optimizations
    CFLAGS += -g -Wall -I/home/shunzhi/software/glog-0.3.3/_install/include
    LDFLAGS += -L/home/shunzhi/software/glog-0.3.3/_install/lib -Wl,-Bdynamic -lglog -lpthread -lrt

    %.o: %.c
        @echo "[Compiling] $< ..."
        @$(CC) $(CFLAGS) -c $<

    all: $(DEMOTAR)

    $(DEMOTAR):$(DEMOOBJ)
        @$(CC) -o $@ $^ $(LDFLAGS)

    .PHONY : clean
    clean:
        rm -rf $(DEMOOBJ) $(DEMOTAR)  

2)编译测试程序

shunzhi@ubuntu:~/workspace/glog$ ls
glog_hisi.c  Makefile
shunzhi@ubuntu:~/workspace/glog$ make
[Compiling] glog_hisi.c ...
shunzhi@ubuntu:~/workspace/glog$ ls
glog_hisi  glog_hisi.c  glog_hisi.o  Makefile
shunzhi@ubuntu:~/workspace/glog$ 

3)测试结果

~/glog # ls
glog_hisi
~/glog # ./glog_hisi 
I0101 15:44:54.473941   273 glog_hisi.c:46] ------------------------------
I0101 15:44:54.475924   273 glog_hisi.c:47] ---------Creat Log!!!---------

I0101 15:44:54.476441   273 glog_hisi.c:48] ------------------------------
~/glog # ls
glog_hisi  log

注:log文件就是生成的日志文件

4.移植库可能遇到的问题

1)执行congfigure配置通过,而且执行make编译也正常,在执行sudo make install是出现了下面的错误:

错误log

make[1]: Entering directory '/home/shunzhi/software/glog-0.3.3'
test -z "/home/shunzhi/software/glog-0.3.3/lib" || /bin/mkdir -p "/home/shunzhi/software/glog-0.3.3/lib"
 /bin/sh ./libtool   --mode=install /usr/bin/install -c   libglog.la '/home/shunzhi/software/glog-0.3.3/lib'
libtool: install: /usr/bin/install -c .libs/libglog.so.0.0.0 /home/shunzhi/software/glog-0.3.3/lib/libglog.so.0.0.0
libtool: install: (cd /home/shunzhi/software/glog-0.3.3/lib && { ln -s -f libglog.so.0.0.0 libglog.so.0 || { rm -f libglog.so.0 && ln -s libglog.so.0.0.0 libglog.so.0; }; })
libtool: install: (cd /home/shunzhi/software/glog-0.3.3/lib && { ln -s -f libglog.so.0.0.0 libglog.so || { rm -f libglog.so && ln -s libglog.so.0.0.0 libglog.so; }; })
libtool: install: /usr/bin/install -c .libs/libglog.lai /home/shunzhi/software/glog-0.3.3/lib/libglog.la
libtool: install: /usr/bin/install -c .libs/libglog.a /home/shunzhi/software/glog-0.3.3/lib/libglog.a
libtool: install: chmod 644 /home/shunzhi/software/glog-0.3.3/lib/libglog.a
libtool: install: arm-hisiv500-linux-ranlib /home/shunzhi/software/glog-0.3.3/lib/libglog.a
./libtool: line 1099: arm-hisiv500-linux-ranlib: command not found
Makefile:697: recipe for target 'install-libLTLIBRARIES' failed
make[1]: *** [install-libLTLIBRARIES] Error 127
make[1]: Leaving directory '/home/shunzhi/software/glog-0.3.3'
Makefile:1428: recipe for target 'install-am' failed
make: *** [install-am] Error 2

错误原因:
是由于环境变量设置的不对,我们交叉工具链root用户下找不到。

解决方案:
按照上述我的配置步骤,新建一个安装目录(shunzhi@ubuntu:~/software/glog-0.3.3$ mkdir _install),然后配置选项中指明安装目录(--prefix=/home/shunzhi/software/glog-0.3.3/_install/),执行make install即可。

Logo

更多推荐