OpenWrt Forum Archive

Topic: C++ program does not run despite successful compilation

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

Hi,

I am porting my C++ program for OpenWRT on x86 wrap board. The compilation and installation goes through smooth and the makefile is listed below. After installation when i run the program on the node , i get the error : -ash: FileReader: not found. The program uses iostream.h and fstream.h. Any ideas as to what could be the problem here ?

# This is free software, licensed under the GNU General Public License v2.
# See /LICENSE for more information.
#
# $Id$

include $(TOPDIR)/rules.mk

#These lines concatanate the package name and list the URL location from which the package source code is to be downloaded
PKG_NAME:=filereader
PKG_VERSION:=0.1
PKG_RELEASE:=1

PKG_SOURCE:=$(PKG_NAME)-$(PKG_VERSION).tar.gz
PKG_SOURCE_URL:=http://www.cs.uh.edu/~vivekian/downloads/
PKG_MD5SUM:=376710ec6ba0f9fa27697a425a13b438
PKG_CAT:=zcat

PKG_BUILD_DIR:=$(BUILD_DIR)/$(PKG_NAME)-$(PKG_VERSION)

include $(INCLUDE_DIR)/package.mk

#These lines describe what your package does and its place in the menu config
define Package/filereader
  SECTION:=net
  CATEGORY:=Network
  TITLE:=FileReader is a test package
  DESCRIPTION:=\
    Sample Code  \\\
    Go For it   \\\
    It will save you time !
  URL:=http://www.cs.uh.edu/~vivekian
endef

#These lines describe where your binary images are to be installed
define Package/filereader/install   
    $(INSTALL_DIR) $(1)/usr/bin/
    $(INSTALL_BIN) $(PKG_BUILD_DIR)/FileReader $(1)/usr/bin/
endef


$(eval $(call BuildPackage,filereader))

you are using the hosts g++ compiler. but you have to cross-compile. below is what works for me and creates a cross-compiled binary. check with the 'file' command if FileReader binary is cross-compiled for your target.

Index: packages/net/filereader/patches/100-Makefile.patch
===================================================================
--- packages/net/filereader/patches/100-Makefile.patch  (Revision 0)
+++ packages/net/filereader/patches/100-Makefile.patch  (Revision 0)
@@ -0,0 +1,15 @@
+Index: filereader-0.1/Makefile
+===================================================================
+--- filereader-0.1.orig/Makefile       2007-06-24 01:26:31.000000000 +0200
++++ filereader-0.1/Makefile    2007-06-24 01:26:50.000000000 +0200
+@@ -1,8 +1,8 @@
+ FileReader : FileReader.o
+-      g++ FileReader.o -o FileReader
++      $(CXX) FileReader.o -o FileReader
+ 
+ FileReader.o : FileReader.h FileReader.cpp
+-      g++ -c -Wall -Wno-deprecated FileReader.cpp
++      $(CXX) -c -Wall -Wno-deprecated FileReader.cpp
+ 
+ .PHONY : install 
+ install : 
Index: packages/net/filereader/Makefile
===================================================================
--- packages/net/filereader/Makefile    (Revision 0)
+++ packages/net/filereader/Makefile    (Revision 0)
@@ -0,0 +1,43 @@
+# This is free software, licensed under the GNU General Public License v2.
+# See /LICENSE for more information.
+#
+# $Id$
+
+include $(TOPDIR)/rules.mk
+
+PKG_NAME:=filereader
+PKG_VERSION:=0.1
+PKG_RELEASE:=1
+
+PKG_SOURCE:=$(PKG_NAME)-$(PKG_VERSION).tar.gz
+PKG_SOURCE_URL:=http://www.cs.uh.edu/~vivekian/downloads/
+PKG_MD5SUM:=376710ec6ba0f9fa27697a425a13b438
+PKG_CAT:=zcat
+
+PKG_BUILD_DIR:=$(BUILD_DIR)/$(PKG_NAME)-$(PKG_VERSION)
+
+include $(INCLUDE_DIR)/package.mk
+
+define Package/filereader
+  SECTION:=net
+  CATEGORY:=Network
+  TITLE:=FileReader is a test package
+  DESCRIPTION:=\
+       Sample Code \\\
+       Go For it \\\
+       It will save you time !
+  URL:=http://www.cs.uh.edu/~vivekian
+endef
+
+define Build/Compile
+       $(MAKE) -C $(PKG_BUILD_DIR) \
+               CFLAGS="$(TARGET_CFLAGS)" \
+               CXX="$(TARGET_CROSS)g++"
+endef
+
+define Package/filereader/install
+       $(INSTALL_DIR) $(1)/usr/bin/
+       $(INSTALL_BIN) $(PKG_BUILD_DIR)/FileReader $(1)/usr/bin/
+endef
+
+$(eval $(call BuildPackage,filereader))

(Last edited by forum2006 on 24 Jun 2007, 00:39)

This worked. In addition had to port libstdc++ to meet dependencies. I suppose the same can be done by specifying  uclibc++ as the library to be used during cross linking.

@forum2006 : Forgot to say this !! smile Thanks a bunch for the quick response

The discussion might have continued from here.