Failing to run cpp code using boost library on OpenWrt

Hello,
I am trying to run simple c++ code using boost library on openwrt but keep getting the same error:

root@OpenWrt:~# g++ -I /usr/include/boost hello1.cpp -o hello1 -L /usr/lib -lboost_locale
hello1.cpp:1:10: fatal error: boost/locale.hpp: No such file or directory
 #include <boost/locale.hpp>
          ^~~~~~~~~~~~~~~~~~
compilation terminated.

I already installed boost library but I could not locate the hpp files.

Any ideas please.

You are not supposed to compile code on the router itself, but cross-compile it on your computer.

3 Likes

hello,
I tried to cross-compile code on openWRT SDK but still facing same issue. Below is the cpp code and both makefiles:
<

#include <boost/locale.hpp>
#include <iostream>

#include <ctime>

int main()
{
    using namespace boost::locale;
    using namespace std;
    generator gen;
    locale loc=gen(""); 
    // Create system default locale

    locale::global(loc); 
    // Make it system global
    
    cout.imbue(loc);
    // Set as default locale for output
    
    cout <<format("Today {1,date} at {1,time} we had run our first localization example") % time(0) 
          <<endl;
   
    cout<<"This is how we show numbers in this locale "<<as::number << 103.34 <<endl; 
    cout<<"This is how we show currency in this locale "<<as::currency << 103.34 <<endl; 
    cout<<"This is typical date in the locale "<<as::date << std::time(0) <<endl;
    cout<<"This is typical time in the locale "<<as::time << std::time(0) <<endl;
    cout<<"This is upper case "<<to_upper("Hello World!")<<endl;
    cout<<"This is lower case "<<to_lower("Hello World!")<<endl;
    cout<<"This is title case "<<to_title("Hello World!")<<endl;
    cout<<"This is fold case "<<fold_case("Hello World!")<<endl;
   
}

/>

Makefile

INCLUDE = -I /usr/include/boost
LDFLAGS= -L /usr/lib -lboost_locale
hello1: hello1.o
	$(CXX) hello1.o -o hello1 $(LDFLAGS)
hello1.o: hello1.cpp
	$(CXX) $(CFLAGS) $(INCLUDE) -c hello1.cpp

clean:
	rm *.o hello1

/>
Makefile

include $(TOPDIR)/rules.mk

PKG_NAME:=hello1
PKG_VERSION:=1.0.0
PKG_RELEASE:=1
PKG_BUILD_DIR := $(BUILD_DIR)/$(PKG_NAME)

include $(INCLUDE_DIR)/package.mk

define Package/hello1
 SECTION:=utils
 CATEGORY:=Utilities
 TITLE:=Hello1 -- prints a snarky message
 DEPENDS:=+libstdcpp +libboost_locale
endef

define Package/hello1/description
 If you can't figure out what this program does,
 you're probably brain-dead and need immediate
 medical attention.
endef

define Build/Prepare
	mkdir -p $(PKG_BUILD_DIR)
	$(CP) ./src/* $(PKG_BUILD_DIR)/
endef

define Build/Configure
	$(call Build/Configure/Default,--with-linux-headers=$(LINUX_DIR))
endef

define Package/hello1/install
	$(INSTALL_DIR) $(1)/bin
	$(INSTALL_BIN) $(PKG_BUILD_DIR)/hello1 $(1)/bin/
endef

$(eval $(call BuildPackage,hello1,+libboost_locale))

INCLUDE = -I /usr/include/boost

I think that should be
INCLUDE = -I$(STAGING_DIR_HOSTPKG)/usr/include/boost
but you'll have to check if the file is there. Look at the other -I's to see where to look.

I changed the include as advised but still facing the same issue. when I run the code by itself is working and checked the locale.hpp file under /usr/include/boost and it is there, I face this issue only when I cross-compile it.