FOR TIPS, gUIDES & TUTORIALS

subscribe to our Youtube

GO TO YOUTUBE

14455 questions

17168 answers

28195 comments

0 members

We are migrating to our new platform at https://community.teltonika.lt. Moving forward, you can continue discussions on this new platform. This current platform will be temporarily maintained for reference purposes.
0 votes
342 views 0 comments
by anonymous

Hi all,

I succeeded to build helloworld.c following the openwrt guide and installing the file on the router, however, I have big troubles in installing the cpp version. I don't get what I am missing in the make file as I manage to get an executable, and installing it on the modem but it looks like l can't really run it, the error I get is:

/usr/bin/helloworld: line 1: syntax error: unexpected word (expecting ")")

It is not really a syntax error as I managed to build successfully the file and run it on my host arch, therefore I suspect is a dependency I am missing, could you please tell me if I am doing something wrong? Thanks!

include $(TOPDIR)/rules.mk

# Name, version and release number

# The name and version of your package are used to define the variable to point to the build directory of your package: $(PKG_BUILD_DIR)

PKG_NAME:=helloworld

PKG_VERSION:=1.0

PKG_RELEASE:=1

# Source settings (i.e. where to find the source codes)

# This is a custom variable, used below

SOURCE_DIR:=/build_mnt/helloworld

include $(INCLUDE_DIR)/package.mk

# Package definition; instructs on how and where our package will appear in the overall configuration menu ('make menuconfig')

define Package/helloworld

SECTION:=examples

CATEGORY:=Examples

TITLE:=Hello, World!

endef

# Package description; a more verbose description on what our package does

define Package/helloworld/description

A simple "Hello, world!" -application.

endef

# Package preparation instructions; create the build directory and copy the source code. 

# The last command is necessary to ensure our preparation instructions remain compatible with the patching system.

define Build/Prepare

mkdir -p $(PKG_BUILD_DIR)

cp $(SOURCE_DIR)/* $(PKG_BUILD_DIR)

$(Build/Patch)

endef

# Package build instructions; invoke the target-specific compiler to first compile the source file, and then to link the file into the final executable

define Build/Compile

$(TARGET_CXX) $(TARGET_CXXFLAGS) -c $(PKG_BUILD_DIR)/helloworld.cpp -o $(PKG_BUILD_DIR)/helloworld 

endef

# Package install instructions; create a directory inside the package to hold our executable, and then copy the executable we built previously into the folder

define Package/helloworld/install

$(INSTALL_DIR) $(1)/usr/bin

$(INSTALL_BIN) $(PKG_BUILD_DIR)/helloworld $(1)/usr/bin

endef

# This command is always the last, it uses the definitions and variables we give above in order to get the job done

$(eval $(call BuildPackage,helloworld))

1 Answer

0 votes
by anonymous

Hi think I found the solution by myself.

1 - Make sure that  uclibc++ is installed:

./scripts/feeds update ./scripts/feeds install uclibcxx make package/uclibc++/compile

2 - Apply the following makefile (note, I am embedding the Makefile of the program inside the main Makefile)

include $(TOPDIR)/rules.mk
 
# Name, version and release number
# The name and version of your package are used to define the variable to point to the build directory of your package: $(PKG_BUILD_DIR)
PKG_NAME:=helloworld
PKG_VERSION:=1.0
PKG_RELEASE:=1
 
# Source settings (i.e. where to find the source codes)
# This is a custom variable, used below
SOURCE_DIR:=/build_mnt/helloworld
 
# Source settings (i.e. where to find the source codes)
# This is a custom variable, used below
include $(INCLUDE_DIR)/package.mk
 
# Package definition; instructs on how and where our package will appear in the overall configuration menu ('make menuconfig')
define Package/helloworld
SECTION:=examples
CATEGORY:=Examples
TITLE:=Hello, World!
DEPENDS:=+libstdcpp
endef
 
# Package description; a more verbose description on what our package does
define Package/helloworld/description
A simple "Hello, world!" -application.
endef
 
# Package preparation instructions; create the build directory and copy the source code.
# The last command is necessary to ensure our preparation instructions remain compatible with the patching system.
define Build/Prepare
mkdir -p $(PKG_BUILD_DIR)
cp $(SOURCE_DIR)/* $(PKG_BUILD_DIR)
$(Build/Patch)
endef
 
# Package build instructions; invoke the target-specific compiler to first compile the source file, and then to link the file into the final executable
define Build/Compile
$(TARGET_CXX) $(TARGET_CXXFLAGS) -o $(PKG_BUILD_DIR)/helloworld.o -c $(PKG_BUILD_DIR)/helloworld.cpp
$(TARGET_CXX) $(TARGET_LDFLAGS) -o $(PKG_BUILD_DIR)/$1 $(PKG_BUILD_DIR)/helloworld.o
endef
 
# Package install instructions; create a directory inside the package to hold our executable, and then copy the executable we built previously into the folder
define Package/helloworld/install
$(INSTALL_DIR) $(1)/usr/bin
$(INSTALL_BIN) $(PKG_BUILD_DIR)/helloworld $(1)/usr/bin
endef
 
# This command is always the last, it uses the definitions and variables we give above in order to get the job done
$(eval $(call BuildPackage,helloworld))

Best answer