Hello,
as you seen here (https://issues.apache.org/jira/browse/THRIFT-177), I
am trying to cross-compile Thrift for the OpenWRT platform.
After a two-night-fight, my result are the following:
- I've created a OpenWRT package for thrift (see the attachment if you
are interested).
- I've successfully compiled the cpp-library (which results in
libthrift, libthriftz and libthriftnb)
- For now, I will not cross-compile the thrift-compiler since I will
compile the thrift definition files on my PC.
Coming to this point, I was very happy and I thought that the story
ends, but now I am faced with a problem I cannot solve myself:
For testing my cross-compilation result, I cross-compiled the cpp-part
of the thrift tutorial. I installed the cross-compiled libraries on the
target device and start the CppServer and the only reaction was
"Segmentation Fault" :-(
I tried to backtrack the problem and I came to the finding, that a
simple hello world program, which is linked to my cross-compiled
thrift-library, causes the "Segmentation Fault". Without linking the
thrift-library, everything is O.K.
=======================
------------
Hello.cpp
------------
#include <iostream>
using namespace std;
int main(int argc, char **argv) {
printf("Hello World!\n");
return 0;
}
1) First try
$ i386-linux-uclibc-g++ -L${LIB_DIR} -levent -lthrift -o Hello Hello.cpp
On the target device:
root@OpenWrt:~# ./Hello
Segmentation fault
2) Second try
$ i386-linux-uclibc-g++ -L${LIB_DIR} -levent -o Hello Hello.cpp
On the target device:
root@OpenWrt:~# ./Hello
Hello World!
======================
I will try to debug it with gdb, but I'm not an expert in this.
So, please, can someone help me?
Kind regards,
Siamak Haschemi
Here is the Makefile:
#
# Copyright (C) 2007 OpenWrt.org
#
# This is free software, licensed under the GNU General Public License v2.
# See /LICENSE for more information.
#
include $(TOPDIR)/rules.mk
PKG_NAME:=thrift
PKG_VERSION:=snapshot
PKG_RELEASE:=1
PKG_SOURCE:=$(PKG_NAME)-HEAD.tgz
#Automatic downloading of the current Thrift HEAD does not work with the URL below
#PKG_SOURCE_URL:=http://gitweb.thrift-rpc.org/?p=thrift.git;a=snapshot;h=HEAD;sf=tgz
PKG_BUILD_DIR:=$(BUILD_DIR)/$(PKG_NAME)
PKG_CAT:=zcat
include $(INCLUDE_DIR)/package.mk
define Package/libthrift/Default
SUBMENU:=Apache Thrift - Cross-language services
SECTION:=lib
CATEGORY:=Libraries
TITLE:=Thrift
URL:=http://incubator.apache.org/thrift
endef
define Package/libthrift/Default/description
Thrift is a software framework for scalable cross-language services
development. It combines a software stack with a code generation
engine to build services that work efficiently and seamlessly between
C++, Java, Python, PHP, Ruby, Erlang, Perl, Haskell, C#, Cocoa,
Smalltalk, and OCaml.
endef
define Package/libthrift
$(call Package/libthrift/Default)
TITLE+= (core)
# DEPENDS:= boost
PROVIDES:=libthrift
endef
define Package/libthrift/description
$(call Package/libthrift/Default/description)
.
libthrift: The core Thrift library contains all the core Thrift code.
It requires boost shared pointers, pthreads, and librt.
endef
define Package/libthriftnb
$(call Package/libthrift/Default)
TITLE+= (non-blocking server)
DEPENDS+= libthrift +libevent
endef
define Package/libthriftnb/description
$(call Package/libthrift/Default/description)
.
libthriftnb: This library contains the Thrift nonblocking server,
which uses libevent. To link this library you will also need to link libevent.
endef
THRIFT_CPP_LIB_DIR=$(PKG_BUILD_DIR)/lib/cpp
THRIFT_HEADERS_DIR=$(1)/usr/include/thrift
CONFIGURE_ARGS+= \
MAKE_FLAGS+= \
define Build/Prepare
wget -O $(TOPDIR)/dl/$(PKG_SOURCE) "http://gitweb.thrift-rpc.org/?p=thrift.git;a=snapshot;h=HEAD;sf=tgz"
$(call Build/Prepare/Default)
endef
define Build/Configure
cd $(PKG_BUILD_DIR) && ./bootstrap.sh
$(call Build/Configure/Default)
endef
MAKE_VARS = \
CFLAGS="$(TARGET_CFLAGS) $(EXTRA_CFLAGS) $(TARGET_CPPFLAGS) $(EXTRA_CPPFLAGS)" \
CXXFLAGS="$(TARGET_CFLAGS) $(EXTRA_CFLAGS) $(TARGET_CPPFLAGS) $(EXTRA_CPPFLAGS)" \
LDFLAGS="$(TARGET_LDFLAGS) $(EXTRA_LDFLAGS)"
MAKE_FLAGS = \
$(TARGET_CONFIGURE_OPTS) \
CROSS="$(TARGET_CROSS)" \
ARCH="$(ARCH)"
MAKE_PATH = .
define Build/Compile/Default
$(MAKE_VARS) \
$(MAKE) -C $(THRIFT_CPP_LIB_DIR) \
DESTDIR="$(PKG_INSTALL_DIR)" \
$(MAKE_FLAGS) \
$(1) \
all install;
endef
define Build/InstallDev
mkdir -p $(1)/usr/include
mkdir -p $(THRIFT_HEADERS_DIR)
mkdir -p $(THRIFT_HEADERS_DIR)/concurrency
mkdir -p $(THRIFT_HEADERS_DIR)/processor
mkdir -p $(THRIFT_HEADERS_DIR)/protocol
mkdir -p $(THRIFT_HEADERS_DIR)/server
mkdir -p $(THRIFT_HEADERS_DIR)/transport
$(INSTALL_DATA) $(THRIFT_CPP_LIB_DIR)/src/concurrency/*.h $(THRIFT_HEADERS_DIR)/concurrency
$(INSTALL_DATA) $(THRIFT_CPP_LIB_DIR)/src/processor/*.h $(THRIFT_HEADERS_DIR)/processor
$(INSTALL_DATA) $(THRIFT_CPP_LIB_DIR)/src/protocol/*.h $(THRIFT_HEADERS_DIR)/protocol
$(INSTALL_DATA) $(THRIFT_CPP_LIB_DIR)/src/server/*.h $(THRIFT_HEADERS_DIR)/server
$(INSTALL_DATA) $(THRIFT_CPP_LIB_DIR)/src/transport/*.h $(THRIFT_HEADERS_DIR)/transport
$(INSTALL_DATA) $(THRIFT_CPP_LIB_DIR)/src/*.h $(THRIFT_HEADERS_DIR)
$(INSTALL_DATA) $(PKG_BUILD_DIR)/config.h $(THRIFT_HEADERS_DIR)/config.h
mkdir -p $(1)/usr/lib
$(CP) $(PKG_INSTALL_DIR)/usr/lib/libthrift* $(1)/usr/lib
$(call Build/InstallDev/Default)
endef
define Build/UninstallDev
rm -rf $(THRIFT_HEADERS_DIR)
rm -rf $(1)/usr/lib/libthrift*
$(call Build/UninstallDev/Default)
endef
define Package/libthrift/install
$(INSTALL_DIR) $(1)/usr/lib
$(CP) $(PKG_INSTALL_DIR)/usr/lib/libthrift.so* $(1)/usr/lib/
$(CP) $(PKG_INSTALL_DIR)/usr/lib/libthriftz.so* $(1)/usr/lib/
endef
define Package/libthriftnb/install
$(INSTALL_DIR) $(1)/usr/lib
$(CP) $(PKG_INSTALL_DIR)/usr/lib/libthriftnb.so* $(1)/usr/lib/
endef
$(eval $(call BuildPackage,libthrift))
$(eval $(call BuildPackage,libthriftnb))
And here is a needed patch:
001-configure.patch
diff -NaurB thrift.orig/aclocal/ax_lib_event.m4 thrift.mod/aclocal/ax_lib_event.m4
--- thrift.orig/aclocal/ax_lib_event.m4 2008-10-21 02:09:23.000000000 +0200
+++ thrift.mod/aclocal/ax_lib_event.m4 2008-10-21 12:03:59.000000000 +0200
@@ -71,7 +71,7 @@
AC_LANG_PUSH([C])
dnl This can be changed to AC_LINK_IFELSE if you are cross-compiling,
dnl but then the version cannot be checked.
- AC_RUN_IFELSE([AC_LANG_PROGRAM([[
+ AC_LINK_IFELSE([AC_LANG_PROGRAM([[
#include <sys/types.h>
#include <event.h>
]], [[
diff -NaurB thrift.orig/aclocal/ax_lib_zlib.m4 thrift.mod/aclocal/ax_lib_zlib.m4
--- thrift.orig/aclocal/ax_lib_zlib.m4 2008-10-21 02:09:23.000000000 +0200
+++ thrift.mod/aclocal/ax_lib_zlib.m4 2008-10-21 12:04:21.000000000 +0200
@@ -69,7 +69,7 @@
# (defined in the library).
AC_LANG_PUSH([C])
dnl This can be changed to AC_LINK_IFELSE if you are cross-compiling.
- AC_RUN_IFELSE([AC_LANG_PROGRAM([[
+ AC_LINK_IFELSE([AC_LANG_PROGRAM([[
#include <zlib.h>
#if ZLIB_VERNUM >= 0x$WANT_ZLIB_VERSION
#else