Having some trouble while using glog in openwrt

Hi! I have installed openwrt to my router(Xiaomi R3P Pro) . I want to build software using Google glog but I'm having some problem. I installed glog to my router using command opkg install glog. I wrote code something like below and tried to build with my toolchain's g++(mipsel-openwrt-linux-g++).

#include <iostream>
#include <glog/logging.h>

int main(int argc, char *argv[])
    return 0;

But it fails to build and show error below.

/home/pol4bear/test/openwrt/staging_dir/toolchain-mipsel_24kc_gcc-8.3.0_musl/lib/gcc/mipsel-openwrt-linux-musl/8.3.0/../../../../mipsel-openwrt-linux-musl/bin/ld: /tmp/ccnP9Rwu.o: in function `main':
main.cpp:(.text+0xb8): undefined reference to `google::InitGoogleLogging(char const*)'

I fixed this same problem by build library myself when I tried to use libpcap. But if I build glog using command below it succefully built.

CC=~/mi/mipsel-openwrt-linux-gcc ./configure --host=mipsel-openwrt-linux-musl --prefix=$HOME/glog
make install

But when I build using library I built my ld returns error below.

/home/pol4bear/test/openwrt/staging_dir/toolchain-mipsel_24kc_gcc-8.3.0_musl/lib/gcc/mipsel-openwrt-linux-musl/8.3.0/../../../../mipsel-openwrt-linux-musl/bin/ld: skipping incompatible /home/pol4bear/test/openwrt/staging_dir/toolchain-mipsel_24kc_gcc-8.3.0_musl/lib/gcc/mipsel-openwrt-linux-musl/8.3.0/../../../../mipsel-openwrt-linux-musl/lib/libglog.so when searching for -lglog

If I build library myself I can get static library libglog.a ether but compiler throws error that elf format are wrong.

Is there anything I can try else?

You need to have the dependency in your Makefile...

Or if you are using the compiler directly, you have to compile the library inside your SDK or build root.

Show us your Makefile or how you are compiling your source code.

1 Like

This is the content of my Makefile. I'm trying to build using toolchain and my glog library compiled with my toolchain too. I built openwrt SDK but I don't know how to use it.

CXX             = ~/mi/mipsel-openwrt-linux-g++ -std=c++14
SRCS    = $(wildcard *.cpp)
OBJS    = $(SRCS:.cpp=.o)
TARGET  = test
LIBS    = -pthread -lssl -lcrypto -lpcap -lglog

        $(CXX) -o $@ $(SRCS) $(LIBS)

clean :
        rm -f $(TARGET)
        rm -f *.o

I tried to build my program using mipsel-openwrt-linux-gcc but it failed with error "could not find -lpthread" . But g++ works well.

You should create a proper OpenWRT package...