带有c ++ 11标志的OpenWRT交叉编译

时间:2018-03-21 17:54:14

标签: c++ c++11 openwrt

我是OpenWRT的新手,我需要交叉编译c ++程序。问题是,我仍然收到这个错误:

error: 'to_string' is not a member of 'std'
  "duplicate raw value " + std::to_string(it->first));
                           ^

现在我知道,这是一个问题,在编译过程中没有使用c ++ 11标志。我试图将TARGET_CXXFLAGS添加到Makefile中,但它并没有帮助我。

这是Makefile:

include $(TOPDIR)/rules.mk

PKG_NAME:=gateway
PKG_VERSION:=1.0
PKG_RELEASE:=2
INIT_SCRIPT_NAME:=$(PKG_NAME)

PKG_SOURCE:=$(PKG_NAME)-$(PKG_VERSION).tar.xz
PKG_SOURCE_SUBDIR:=$(PKG_NAME)-$(PKG_VERSION)
PKG_BUILD_DIR:=$(BUILD_DIR)/$(PKG_NAME)-$(PKG_VERSION)
PKG_SOURCE_PROTO:=git
PKG_BUILD_DEPENDS:=+libmosquittopp +poco +zmq +cppzmq +openzwave +cppunit +bluez-libs
PKG_SOURCE_URL:=....
PKG_SOURCE_VERSION:=...

CMAKE_INSTALL:=1

include $(INCLUDE_DIR)/package.mk
include $(INCLUDE_DIR)/cmake.mk

CMAKE_OPTIONS += \
    -DCMAKE_INSTALL_PREFIX=/ \
    -DCMAKE_BUILD_TYPE:STRING=Release

TARGET_CXXFLAGS += -DPOCO_NO_FPENVIRONMENT 
TARGET_CXXFLAGS += -g -std=c++11 -Wall -pedantic

....

感谢您的建议,Jakub。

1 个答案:

答案 0 :(得分:1)

取决于GCC版本和STD lib版本。我可以确认上游的最后一个版本完美无缺。这是我的 test Makefile,它可以帮助你,并为你提供一些线索。

CXX=/media/build/openwrt/staging_dir/toolchain-arm_cortex-a7+neon-vfpv4_gcc-5.5.0_musl_eabi/bin/arm-openwrt-linux-g++

RM=rm -f
LDLIBS=
CPPFLAGS=-Wall -std=c++11
LDFLAGS=-L/media/build/openwrt/staging_dir/target-arm_cortex-a7+neon-vfpv4_musl_eabi/usr/lib
INC=-I. -I/media/build/openwrt/staging_dir/target-arm_cortex-a7+neon-vfpv4_musl_eabi/usr/include


SOURCES=main.cpp
OBJECTS=$(SOURCES:.cpp=.o)
EXECUTABLE = hello

all: $(OBJECTS) $(EXECUTABLE)

$(EXECUTABLE): $(OBJECTS)
    $(CXX) -o $@ $^ $(LDFLAGS) $(LDLIBS)

.cpp.o:
    $(CXX) $(INC) $(CPPFLAGS) -c $<

clean:
    $(RM) $(OBJECTS)

distclean: clean
    $(RM) $(EXECUTABLE)

.PHONY: all clean distclean