OpenWrt Forum Archive

Topic: Header errors when compiling linux-rpcapd

The content of this topic has been archived on 7 Apr 2018. There are no obvious gaps in this topic, but there may still be some posts missing at the end.

Background (AKA what I'm really trying to achieve): I am trying to compile a working version of linux-rpcapd (a linux port of WinPcap's Remote Packet CAPture Daemon) for my OpenWRT router (TP-LINK TL-WR941ND, mips, ar71xx).

I have followed the howto, successfully built the toolchain, got a working environment and compiled several working test programs (including a small program that uses functions from string.h). however, when I attempt to compile rpcapd:

kanop@foo:~/md$ STAGING_DIR=/media/casper-rw/openwrt/buildroot/trunk/staging_dir
kanop@foo:~/md$ export STAGING_DIR
kanop@foo:~/md$ PATH=$PATH:/media/casper-rw/openwrt/buildroot/trunk/staging_dir/toolchain-mips_r2_gcc-4.6-linaro_uClibc-0.9.33.2/bin
kanop@foo:~/md$ export PATH
kanop@foo:~/md$ make CC=mips-openwrt-linux-uclibc-gcc LD=mips-openwrt-linux-uclibc-ld
mips-openwrt-linux-uclibc-gcc -pthread -D_DEBUG -g -Wall -DHAVE_REMOTE -DHAVE_SNPRINTF -static -Ilibpcap/ -c daemon.c
In file included from daemon.c:37:0:
/media/casper-rw/openwrt/buildroot/trunk/staging_dir/toolchain-mips_r2_gcc-4.6-linaro_uClibc-0.9.33.2/lib/gcc/mips-openwrt-linux-uclibc/4.6.3/../../../../mips-openwrt-linux-uclibc/sys-include/string.h:451:15: error: expected declaration specifiers or '...' before '(' token
/media/casper-rw/openwrt/buildroot/trunk/staging_dir/toolchain-mips_r2_gcc-4.6-linaro_uClibc-0.9.33.2/lib/gcc/mips-openwrt-linux-uclibc/4.6.3/../../../../mips-openwrt-linux-uclibc/sys-include/string.h:451:15: error: expected declaration specifiers or '...' before '(' token
/media/casper-rw/openwrt/buildroot/trunk/staging_dir/toolchain-mips_r2_gcc-4.6-linaro_uClibc-0.9.33.2/lib/gcc/mips-openwrt-linux-uclibc/4.6.3/../../../../mips-openwrt-linux-uclibc/sys-include/string.h:451:15: error: expected declaration specifiers or '...' before '(' token
/media/casper-rw/openwrt/buildroot/trunk/staging_dir/toolchain-mips_r2_gcc-4.6-linaro_uClibc-0.9.33.2/lib/gcc/mips-openwrt-linux-uclibc/4.6.3/../../../../mips-openwrt-linux-uclibc/sys-include/string.h:451:15: error: expected ')' before ',' token
daemon.c: In function 'daemon_AuthUserPwd':
daemon.c:684:2: warning: implicit declaration of function 'crypt' [-Wimplicit-function-declaration]
daemon.c: In function 'daemon_startcapture':
daemon.c:1070:2: warning: pointer targets in passing argument 3 of 'daemon_unpackapplyfilter' differ in signedness [-Wpointer-sign]
daemon.c:68:5: note: expected 'int *' but argument is of type 'uint32 *'
daemon.c: In function 'daemon_updatefilter':
daemon.c:1270:2: warning: pointer targets in passing argument 3 of 'daemon_unpackapplyfilter' differ in signedness [-Wpointer-sign]
daemon.c:1199:5: note: expected 'int *' but argument is of type 'uint32 *'
make: *** [daemon.o] Error 1

I should mention the same code compiles flawlessly under Ubuntu (gcc version 4.4.3 (Ubuntu 4.4.3-4ubuntu5.1)).
I have also tried the other gcc binary (which seems to be the same version anyway), mips-openwrt-linux-uclibc-gcc-4.6.3, but the results have not changed.

Update:
I have worked around the issue by making a local copy and commenting lines 451-452 in string.h:

extern size_t strlcpy(char *__restrict dst, const char *__restrict src,
                      size_t n) __THROW __nonnull ((1, 2));

I still get more trouble though. I found out that WinPcap's libpcap fork needs to be compiled seperately and then rpcapd should get linked with it. I followed the same procedure and got a missing header:

mips-openwrt-linux-uclibc-gcc -static -O2 -fPIC -I.  -DHAVE_CONFIG_H  -D_U_="__attribute__((unused))" -DHAVE_REMOTE  -c ./pcap-linux.c
mips-openwrt-linux-uclibc-gcc -static -O2 -fPIC -I.  -DHAVE_CONFIG_H  -D_U_="__attribute__((unused))" -DHAVE_REMOTE  -c ./pcap-usb-linux.c
mips-openwrt-linux-uclibc-gcc -static -O2 -fPIC -I.  -DHAVE_CONFIG_H  -D_U_="__attribute__((unused))" -DHAVE_REMOTE  -c ./pcap-bt-linux.c
./pcap-bt-linux.c:60:33: fatal error: bluetooth/bluetooth.h: No such file or directory
compilation terminated.
make: *** [pcap-bt-linux.o] Error 1

(Last edited by kanop on 11 Oct 2012, 12:31)

kanop wrote:

Update:
I have worked around the issue by making a local copy and commenting lines 451-452 in string.h:

extern size_t strlcpy(char *__restrict dst, const char *__restrict src,
                      size_t n) __THROW __nonnull ((1, 2));

I still get more trouble though. I found out that WinPcap's libpcap fork needs to be compiled seperately and then rpcapd should get linked with it. I followed the same procedure and got a missing header:

mips-openwrt-linux-uclibc-gcc -static -O2 -fPIC -I.  -DHAVE_CONFIG_H  -D_U_="__attribute__((unused))" -DHAVE_REMOTE  -c ./pcap-linux.c
mips-openwrt-linux-uclibc-gcc -static -O2 -fPIC -I.  -DHAVE_CONFIG_H  -D_U_="__attribute__((unused))" -DHAVE_REMOTE  -c ./pcap-usb-linux.c
mips-openwrt-linux-uclibc-gcc -static -O2 -fPIC -I.  -DHAVE_CONFIG_H  -D_U_="__attribute__((unused))" -DHAVE_REMOTE  -c ./pcap-bt-linux.c
./pcap-bt-linux.c:60:33: fatal error: bluetooth/bluetooth.h: No such file or directory
compilation terminated.
make: *** [pcap-bt-linux.o] Error 1

The above error message indicated that your system doesn't have the bluetooth/bluetooth.h file (at least the compiler didn't find it). Perhaps, a bluetooth package is one of the prerequisites.

Thanks for the help, I had to edit the makefile and add /usr/include/ to the include dirs.
Okay, so I worked around a few more issues and right now this seems to be the last bit for libpcap (it compiled without bluetooth but rpcapd needs the bluetooth part for some functions):

mips-openwrt-linux-uclibc-gcc -static -O2 -fPIC -I. -I/usr/include/ -DHAVE_CONFIG_H  -D_U_="__attribute__((unused))" -DHAVE_REMOTE  -c ./pcap-bt-linux.c
./pcap-bt-linux.c: In function 'bt_read_linux':
./pcap-bt-linux.c:317:21: error: invalid 'asm': invalid use of '%w'
./pcap-bt-linux.c:317:21: error: invalid 'asm': invalid use of '%w'
make: *** [pcap-bt-linux.o] Error 1

I don't get it really, the error is in the middle of a fairly standard line that does not involve any format operations whatsoever.
http://www.opensource.apple.com/source/ … bt-linux.c

The bogus line:

bthdr->direction = htonl(in != 0);

You cannot use system includes with a cross compiler.

Where do I get the appropriate bluetooth headers, then?

kanop wrote:

Where do I get the appropriate bluetooth headers, then?

Most open-source packages come with some information stored in some text files included in the package source. For a GNU compliant package, usually it is the README file that contains most of the necessary information about the package. This probably includes the prerequisites. Failing that, you will probably wanna contact the author(s) of the package and ask them its prerequisites as well as where to get them.

Well, yesterday I've managed to overcome that bluetooth header thing too by using only specific headers I needed, and some trial and error. I've now got libpcap.a for ar71xx which is awesome smile

The (hopefully) final boss:

mips-openwrt-linux-uclibc-gcc -pthread -D_DEBUG -g -Wall -DHAVE_REMOTE -DHAVE_SNPRINTF -static -Ilibpcap/ -o rpcapd rpcapd.o daemon.o utils.o fileconf.o pcap-remote.o sockutils.o pcap-new.o -Llibpcap/ -lpcap -lcrypt
libpcap//libpcap.a(nametoaddr.o): In function `pcap_nametoaddr':
nametoaddr.c:(.text+0x10): warning: gethostbyname is obsolescent, use getnameinfo() instead.
/media/casper-rw/openwrt/buildroot/trunk/staging_dir/toolchain-mips_r2_gcc-4.6-linaro_uClibc-0.9.33.2/lib/gcc/mips-openwrt-linux-uclibc/4.6.3/../../../../mips-openwrt-linux-uclibc/lib/libpthread.a(pthread_once.os): In function `__pthread_once_internal':
pthread_once.c:(.text.__pthread_once+0x134): undefined reference to `_Unwind_Resume'
pthread_once.c:(.text.__pthread_once+0x138): undefined reference to `_Unwind_Resume'
/media/casper-rw/openwrt/buildroot/trunk/staging_dir/toolchain-mips_r2_gcc-4.6-linaro_uClibc-0.9.33.2/lib/gcc/mips-openwrt-linux-uclibc/4.6.3/../../../../mips-openwrt-linux-uclibc/lib/libpthread.a(pthread_once.os):(.data.DW.ref.__gcc_personality_v0[DW.ref.__gcc_personality_v0]+0x0): undefined reference to `__gcc_personality_v0'
collect2: ld returned 1 exit status
make: *** [rpcapd] Error 1

You may wanna do a make dirclean and make to completely rebuild from ground up to see if that problem still persists.

Today I finally took some time to redo the process.
I installed a clean Buildroot environment, used 'make menuconfig' to get the missing packages,  worked around the string.h bug as mentioned previously on the thread, and tried to compile via the SDK.

The pthread error is still there though, and I know my headers are good because I have just compiled a different package that uses libpthread and it worked fine on the router.
I'm really quite confused here, but my hypothesis is that somehow rpcapd-linux's Makefile is causing it to use the host pthread headers, don't ask me how.

The error:

/home/foo/openwrt/trunk/build_dir/target-mips_r2_uClibc-0.9.33.2/OpenWrt-SDK-ar71xx-for-linux-i686-gcc-4.6-linaro_uClibc-0.9.33.2/staging_dir/toolchain-mips_r2_gcc-4.6-linaro_uClibc-0.9.33.2/bin/../lib/gcc/mips-openwrt-linux-uclibc/4.6.4/../../../../mips-openwrt-linux-uclibc/lib/libpthread.a(pthread_once.os): In function `__pthread_once_internal':
pthread_once.c:(.text.__pthread_once+0x134): undefined reference to `_Unwind_Resume'
pthread_once.c:(.text.__pthread_once+0x138): undefined reference to `_Unwind_Resume'
/home/foo/openwrt/trunk/build_dir/target-mips_r2_uClibc-0.9.33.2/OpenWrt-SDK-ar71xx-for-linux-i686-gcc-4.6-linaro_uClibc-0.9.33.2/staging_dir/toolchain-mips_r2_gcc-4.6-linaro_uClibc-0.9.33.2/bin/../lib/gcc/mips-openwrt-linux-uclibc/4.6.4/../../../../mips-openwrt-linux-uclibc/lib/libpthread.a(pthread_once.os):(.data.DW.ref.__gcc_personality_v0[DW.ref.__gcc_personality_v0]+0x0): undefined reference to `__gcc_personality_v0'

The Makefile I "wrote" (more like edited an existing one) for the OpenWRT SDK:

include $(TOPDIR)/rules.mk

PKG_NAME:=rpcapd
PKG_REV:=ea593f0ec4540f861882b151dccd9f8cfbf8b201
PKG_VERSION:=1
PKG_RELEASE:=1

PKG_SOURCE_PROTO:=git
PKG_SOURCE_VERSION:=$(PKG_REV)
PKG_SOURCE_SUBDIR:=$(PKG_NAME)-$(PKG_VERSION)
PKG_SOURCE_URL:=https://github.com/frgtn/rpcapd-linux/
PKG_SOURCE:=$(PKG_SOURCE_SUBDIR).tar.gz

include $(INCLUDE_DIR)/package.mk

define Package/rpcapd
  SECTION:=net
  CATEGORY:=Network
  DEPENDS:=+libpcap +libpthread
  TITLE:=rpcapd
endef

define Package/rpcapd/description
    remote packet capture daemon
endef

MAKE_FLAGS += \
    LDFLAGS="$(TARGET_LDFLAGS)" \
    OSNAME=Linux \
    prefix="/usr" \
    unstable="true"

define Build/Compile
    $(MAKE) -C $(PKG_BUILD_DIR) $(MAKE_FLAGS)
endef

define Package/rpcapd/install
    $(INSTALL_DIR) $(1)/usr/bin
    $(CP) $(PKG_INSTALL_DIR)/usr/bin/* $(1)/usr/bin/
    $(INSTALL_DIR) $(1)/usr/sbin
    $(CP) $(PKG_INSTALL_DIR)/usr/sbin/* $(1)/usr/sbin/
endef

$(eval $(call BuildPackage,rpcapd))

(Last edited by kanop on 15 Nov 2012, 16:54)

I've finally compiled the bastard. The solution was to edit the Makefile that resides in build_dir add -lgcc_eh to the libraries.
I want to emphasize that when compiling under vanilla Ubuntu 12.10, it worked straight from the git repository without any modifications. I have no Idea what caused this bug to occur with the cross-compiling toolchain (maybe GCC version difference?), but oh well...

(Last edited by kanop on 18 Nov 2012, 16:37)

hi kanop,

Even this thread is a bit older, I'll try to get some support here:

I tried to achieve the same thing and got stuck. Even following your hints does not bring the success I'm looking for. I get the same errors and can't resolve the undefined references to Unwind_Resume.

Do you have a straight forward solution to this meanwhile?

I had the same issue, where adding -lgcc_eh to the Makefile didn't fix the _Unwind_Resume problem. The issue turned out to be the fact that libpthread, which has the missing dependency, was being automatically added to the linker command line _after_ gcc_eh. In order to work the library satisfying the dependency must be after the one that requires it on the command line.

The solution is to to edit the Makefile so the line that did read:

LIB     = -lpcap -lcrypt

Now reads:

LIB     = -lpcap -lcrypt -lpthread -lgcc_eh

This forces the linker to link pthread first so it's dependency can be satisfied. The Makefile that I'm referring to is the one that comes with rpcapd not the one kanop posted earlier.

Hopefully this will save someone else the pain I went through.

(Last edited by john.finlay on 14 Nov 2014, 04:45)

The discussion might have continued from here.