I am new in OpenWRT and I need to crosscompile c++ program. The problem is, I am still getting this error:
error: 'to_string' is not a member of 'std'
"duplicate raw value " + std::to_string(it->first));
^
Now I know, it's problem, that there isn't used c++11 flag during compilation. I tried to add TARGET_CXXFLAGS into Makefile, but it didn't help me.
Here is the 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
....
Thank you for your advice, Jakub.
Depends on GCC version and STD lib version. I can confirm that the last version from upstream works perfectly. Here is my test Makefile which may help you and give you some clues.
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
Related
I am working with an ecological model PEAT-DOS-TEM. I am working in Vagrant ubuntu/trusty64 on a PC. The code I got from GitHub has a Makefile. When i run the command "make" I get this error as a result:
"make: *** No rule to make target 'obj/TEM.o', needed by 'dos-tem'. Stop."
I didn't write this makefile and I don't know C++ very well, if you know how to help me please explain as you would to a beginner. Thank you.
Here is my Makefile:
CC=g++
CFLAGS= -c -Wall -ansi -O0 -g -fPIC
LIBS=-lnetcdf_c++ -lnetcdf
LIBDIR=-Lnetcdf/libs
INCLUDES=-Inetcdf/includes
SOURCES= src/TEM.o \
src/atmosphere/AtmosUtil.o \
OBJECTS= TEM.o\
AtmosUtil.o \
GIT_SHA := $(shell git describe --abbrev=6 --dirty --always --tags)
TEMOBJ= obj/TEM.o
dos-tem: $(SOURCES) $(TEMOBJ)
$(CC) -o peat-dos-tem $(OBJECTS) $(TEMOBJ) $(LIBDIR) $(LIBS)
lib: $(SOURCES)
$(CC) -o libDOSTEM.so -shared $(INCLUDES) $(OBJECTS) $(LIBDIR) $(LIBS)
.cpp.o:
$(CC) $(CFLAGS) $(INCLUDES) $<
clean:
rm -f $(OBJECTS) DVMDOSTEM TEM.o libDOSTEM.so* *~
You have asked make to build a file obj/TEM.o:
TEMOBJ= obj/TEM.o
dos-tem: $(SOURCES) $(TEMOBJ)
(why do you list $(SOURCES) as a prerequisite?) but you have no rule to build that file. This rule:
.cpp.o:
$(CC) $(CFLAGS) $(INCLUDES) $<
will tell make how to build a file X.o from a file X.cpp; in your case the X is obj/TEM so this rule only works if make can find (or build) a file named obj/TEM.cpp which it can't.
So, turns out the Vagrant box I was using just needed to be updated. The original code is working. Thanks for all the help.
First check if you have installed c++ compiler by typing g++ in terminal.
Than to compile type in terminal: gcc sourcefile_name.cpp -o outputfile.exe
Finally, to run the code, type: outputfile.exe
Hope it helped
I am trying to compile my C++ code using the GNU compiler under Linux using the following Makefile
CXX=gcc #icpc
RM=rm -f
CPPFLAGS=-g -O3 -fopenmp
CFLAGS= -Wall -c
OPENMP = -fopenmp
BIN = theVeecode_$(CXX)
LIBS= -L /path-to-boost/boost_1_53_0/stage/lib/ -lboost_regex
CPPSRCS=mathtools.cpp time_.cpp read_input.cpp vee_ao_calc.cpp vee_mo_calc.cpp write_int2e.cpp memory_check.cpp
OBJS=$(subst .cpp,.o,$(CPPSRCS))
OBJS+=$(COBJS)
all: $(BIN)
$(BIN): $(OBJS)
$(CXX) main.cpp $(OPENMP) -o $(BIN) $(OBJS) $(LIBS)
clean:
$(RM) $(OBJS) $(BIN)
dist-clean: clean
$(RM) $(BIN)
When I run the make command, I get the following error messages:
gcc -g -O3 -fopenmp -c -o read_input.o read_input.cpp
read_input.cpp:9:27: error: boost/regex.hpp: No such file or directory
read_input.cpp: In function 'void input::read_n_occ()':
read_input.cpp:95: error: 'boost' has not been declared
read_input.cpp:95: error: 'regex_search' was not declared in this scope
make: *** [read_input.o] Error 1
The read_input.cpp file starts with
#... // other includes
#include <boost/regex.hpp>
using namespace std;
namespace xxx
{
//some code here
}
The library path "/path-to-boost/boost_1_53_0/stage/lib/" contains the files
libboost_regex.a, libboost_regex.so and libboost_regex.so.1.53.0.
I don't understand why the compiler doesn't find the library files. Does anyone have any ideas why it's not working and how to fix it?
Thanks in advance.
As it turned out, the problem was in the Makefile. More specifically, the path to the boost library was not included during the compilation of the .cpp files using boost. Fixed it by adding the library explicitly in the compilation step:
%.o: %.cpp $(DEPS)
$(CXX) -c -o $# $< $(CPPFLAGS) $(LIBS)
Finally, the Makefile is as follows:
CXX=gcc #icpc
RM=rm -f
CPPFLAGS=-g -O3 -fopenmp
OPENMP = -fopenmp
BIN = theVeecode_$(CXX)
LIBS= -I /path-to-boost/boost_1_53_0/
LIBS+= -L /path-to-boost/boost_1_53_0/stage/lib/ -lboost_regex
CPPSRCS=mathtools.cpp time_.cpp read_input.cpp vee_ao_calc.cpp vee_mo_calc.cpp write_int2e.cpp memory_check.cpp
OBJS=$(subst .cpp,.o,$(CPPSRCS))
DEPS=Vector3.h mathtools.h memory_check.h read_input.h time_.h vee_ao_calc.h vee_mo_calc.h write_int2e.h
%.o: %.cpp $(DEPS)
$(CXX) -c -o $# $< $(CPPFLAGS) $(LIBS)
$(BIN): $(OBJS)
$(CXX) main.cpp $(OPENMP) -o $(BIN) $(OBJS) $(LIBS)
clean:
$(RM) $(OBJS) $(BIN)
dist-clean: clean
$(RM) $(BIN)
To get the word out there;
For my case, I was missing the libboost-dev package.
On debian, you can install it with sudo apt install libboost-dev
I have the following makefile:
CFLAGS=-c -Wall -std=c++11
MCFLAGS=-c -Wall -std=c++11
LDFLAGS= -shared
MLDFLAGS=
MSOURCES=main.cpp MCC.cpp Point3D.cpp
SOURCES= mainDLL.cpp MCC.cpp Point3D.cpp
OBJECTS=$(SOURCES:.cpp=.o)
MOBJECTS=$(MSOURCES:.cpp=.o)
EXECUTABLE=h2r.dll
MEXECUTABLE=h2r
CC=i686-w64-mingw32-g++
CC=g++
all: clean $(MSOURCES) $(MEXECUTABLE)
dll: clean $(SOURCES) $(EXECUTABLE)
$(MEXECUTABLE): $(MOBJECTS)
$(CC) $(MLDFLAGS) $(MOBJECTS) -o $#
$(EXECUTABLE): $(OBJECTS)
$(CC) $(LDFLAGS) $(OBJECTS) -o $#
.cpp.o:
$(CC) $(CFLAGS) $< -o $#
clean:
rm *.o $(MEXECUTABLE) $(EXECUTABLE)
How can I initialize the CC with the cross compiler(CC=i686-w64-mingw32-g++) when the make dll command is emitted and how can I use the gnu compiler when the make all is emitted?
To set a variable based on what target is being executed you can do something like:
all: CC=g++
all: clean $(MSOURCES) $(MEXECUTABLE)
dll: CC=i686-w64-mingw32-g++
dll: clean $(SOURCES) $(EXECUTABLE)
Define two different CC instead of redefining the one. Since you have different rules for the all and dll, you can just use the other compiler in the other rule. Somehow like this:
CCDLL=i686-w64-mingw32-g++
CCALL=g++
all: clean $(MSOURCES) $(MEXECUTABLE)
dll: clean $(SOURCES) $(EXECUTABLE)
$(MEXECUTABLE): $(MOBJECTS)
$(CCALL) $(MLDFLAGS) $(MOBJECTS) -o $#
$(EXECUTABLE): $(OBJECTS)
$(CCDLL) $(LDFLAGS) $(OBJECTS) -o $#
Your overwriting whatever is in the CC variable. Why don't you just have:
CC_DLL=i686-w64-mingw32-g++
CC=g++
And simply use the relevant one in your targets.
I'm trying to compile a simple program from the terminal that utilizes the condition_variable class. Upon building, I get the following error:
This file requires compiler and library support for the ISO C++ 2011 standard. This support is currently experimental, and must be enabled with the -std=c++11 or -std=gnu++11 compiler options.
In researching this error here, I added the necessary flag to my make file, but I'm still getting the same error.
Here is my makefile:
CXX= g++ $(CCFLAGS)
MAIN= main.o
DATACLASS= dataclass.o
OBJS = $(MAIN) $(DATACLASS)
LIBS= -pthread
CCFLAGS= -g -std=c++11
all: main
main: $(MAIN) $(DATACLASS)
$(CXX) -o main $(MAIN) $(DATACLASS) $(LIBS)
dataclass: $(DATACLASS)
$(CXX) -o dataclass $(DATACLASS) $(LIBS)
clean:
rm -f $(OBJS) $(OBJS:.o=.d)
realclean:
rm -f $(OBJS) $(OBJS:.o=.d) main
%.d: %.cc
$(SHELL) -ec '$(CC) -M $(CPPFLAGS) $< \
| sed '\''s/\($*\)\.o[ :]*/\1.o $# : /g'\'' > $#; \
[ -s $# ] || rm -f $#'
include $(OBJS:.o=.d)
I'm sure I'm missing something small and stupid as I'm new to makefiles, but any help would be greatly appreciated.
Rewrite CXX to CXX = g++
Change CCFLAGS to CXXFLAGS = -g -std=c++11, and
Rewrite your rules to $(CXX) $(CXXFLAGS) ....
$(CXX) $(CXXFLAGS) will then be replaced with g++ -g -std=c++11. This is more of a standard method for defining a makefile. Here is a snippet of the resulting makefile.
CXX = g++
MAIN = main.o
DATACLASS = dataclass.o
OBJS = $(MAIN) $(DATACLASS)
LIBS = -pthread
CXXFLAGS = -g -std=c++11
all: main
main: $(OBJS)
$(CXX) $(CXXFLAGS) $? -o $# $(LIBS)
As a side note, are you sure this rule should be defined as such?
dataclass: $(DATACLASS)
$(CXX) $(CXXFLAGS) $? -o $# $(LIBS)
Should the target not be dataclass.o or $(DATACLASS) and the prerequisite some other file?
Note: I've also included some make automatic variables to tidy up the makefile rules.
$? - is replaced by all prerequisites
$# - is replaced by the target name
(On Linux, trying to set up SDL) I'm having a time with makefiles, I'm finding them hard to learn. Here is the error I'm getting.
g++: error: game.exe: No such file or directory
make: *** [game.exe] Error 1
Here is my makefile. (Any suggestions on making it better would be great. I've just kind of slapped together whatever I could find to work.)
#Game Make file
TARGET = game.exe
OBJS = App.o\
App_OnInit.o\
App_OnEvent.o\
App_OnLoop.o\
App_OnRender.o \
App_OnCleanup.o\
SDL_CFLAGS := $(shell sdl-config --cflags)
SDL_LDFLAGS := $(shell sdl-config --libs)
CFLAGS = -Wall -o
LIBS =
LDFLAGS =
$(TARGET): $(OBJS)
g++ $(CFLAGS) $(SDL_CFLAGS) $# $(LDFLAGS) $(OBJS) $(SDL_LDFLAGS) $(LIBS)
%.o: src/%.cpp
g++ -c $(SDL_CFLAGS) $< $(SDL_LDFLAGS)
.PHONY: clean
clean:
rm -f $(TARGET) $(OBJS)
You could either exchange $(CFLAGS) and $(SDL_CFLAGS) in the rule to make $(TARGET) or better remove -o from CFLAGS and put it directly before $#:
...
CFLAGS = -Wall
...
$(TARGET): $(OBJS)
g++ $(CFLAGS) $(SDL_CFLAGS) -o $# $(LDFLAGS) $(OBJS) $(SDL_LDFLAGS) $(LIBS)
-o option should immediately precede the name of the executable file to be produced. In your original Makefile it is part of $(CFLAGS) and is followed by the C flags of the SDL library. Therefore the compiler tries to link in game.exe (the $#) instead of producing an executable file by that name.