I've have my motion detection program written in C++, running correctly in Linux.
Just copy and test in MacOS, but got the error "OpenCV 4.x+ requires enabled C++11":
In file included from video_process.cpp:1:
In file included from ./video_process.h:17:
In file included from ./yolov4.h:1:
In file included from /usr/local/include/opencv2/imgproc.hpp:46:
In file included from /usr/local/include/opencv2/core.hpp:52:
/usr/local/include/opencv2/core/cvdef.h:732:4: error: "OpenCV 4.x+ requires enabled C++11 support"
error "OpenCV 4.x+ requires enabled C++11 support"
^
In file included from video_process.cpp:1:
In file included from ./video_process.h:17:
In file included from ./yolov4.h:1:
In file included from /usr/local/include/opencv2/imgproc.hpp:46:
In file included from /usr/local/include/opencv2/core.hpp:54:
In file included from /usr/local/include/opencv2/core/base.hpp:58:
In file included from /usr/local/include/opencv2/core/cvstd.hpp:81:
I have -std=c++11 in my Makefile, and the code is working correctly in Linux.
What could cause this problem on MacOS?..
Makefile:
CFLAGS = -w -std=c++11 -I/usr/local/lib -I/usr/include/mysql `pkg-config --cflags opencv4` -pthread
LIBS = -L/usr/local/lib/mysql `pkg-config --libs opencv4` -lmysqlclient
OBJS = video_process.o motion_background_diff.o yolov4.o preprocess.o
TARGET = motion_detection
$(TARGET) : $(OBJS)
g++ $(CFLAGS) -o $# $^ $(LIBS)
Related
I am working on the project which has to include the CPLEX tool at some point.
More in detail, I have the following classes implemented
(i.e. the corresponding files): Random.cpp, Instance.cpp, Timer.cpp. Solution.cpp which are included into Hybrid_ea.cpp which also have to include cplex library.
Finally, the project has been executed by running Algorithm.cpp (the main() function defined here).
I want to run the project on Linux platform, creating Makefile which looks like:
TARGET = Algorithm
CXXFLAGS = -ansi -O3
GENOBJS = Random.o
#CPLOBJS = Timer.o Random.o Instance.o Hybrid_ea.o
GREOBJS = Timer.o Random.o Instance.o Solution.o Hybrid_ea.o
SYSTEM = x86-64_linux
LIBFORMAT = static_pic
CPLEXDIR = /home/root/Desktop/projects/software/cplex-12.5/cplex
CONCERTDIR = /home/root/Desktop/projects/software/cplex-12.5/concert
CCC = g++
CCOPT = -m64 -O -fPIC -fexceptions -DNDEBUG -DIL_STD -std=c++11 -fpermissive -w
CPLEXBINDIR = $(CPLEXDIR)/bin/$(BINDIST)
CPLEXLIBDIR = $(CPLEXDIR)/lib/$(SYSTEM)/$(LIBFORMAT)
CONCERTLIBDIR = $(CONCERTDIR)/lib/$(SYSTEM)/$(LIBFORMAT)
CCLNFLAGS = -L$(CPLEXLIBDIR) -lilocplex -lcplex -L$(CONCERTLIBDIR) -lconcert -lm -pthread
CLNFLAGS = -L$(CPLEXLIBDIR) -lcplex -lm -pthread
CONCERTINCDIR = $(CONCERTDIR)/include
CPLEXINCDIR = $(CPLEXDIR)/include
CCFLAGS = $(CCOPT) -I$(CPLEXINCDIR) -I$(CONCERTINCDIR)
all: ${TARGET}
Algorithm: Algorithm.o $(GREOBJS)
$(CCC) $(CCFLAGS) Algorithm.o $(GREOBJS) -o Algorithm $(CCLNFLAGS)
Algorithm.o: Algorithm.cpp
$(CCC) -c $(CCFLAGS) Algorithm.cpp -o Algorithm.o
clean:
#rm -f *~ *.o ${TARGET} core
The linking process is somehow wrong. I checked, my CPLEX version is the right one since the others, simpler projects can be executed;
The full output given when trying to compile the project:
g++ -c -m64 -O -fPIC -fexceptions -DNDEBUG -DIL_STD -std=c++11 -fpermissive -w -I/home/root/Desktop/projects/LCAPS_software/cplex-12.5/cplex/include -I/home/root/Desktop/projects/LCAPS_software/cplex-12.5/concert/include Algorithm.cpp -o Algorithm.o
g++ -ansi -O3 -c -o Timer.o Timer.cc
g++ -ansi -O3 -c -o Random.o Random.cc
g++ -ansi -O3 -c -o Instance.o Instance.cpp
g++ -ansi -O3 -c -o Solution.o Solution.cpp
g++ -ansi -O3 -c -o hybrid_ea.o hybrid_ea.cpp
In file included from hybrid_ea.cpp:22:0:
hybrid_ea.h:39:10: fatal error: ilcplex/ilocplex.h: No such file or directory
#include <ilcplex/ilocplex.h>
^~~~~~~~~~~~~~~~~~~~
compilation terminated.
<builtin>: recipe for target 'hybrid_ea.o' failed
make: *** [hybrid_ea.o] Error 1
Any help would be appreciated.
Only the file Algorithm.cpp is compiled with appropriate options for finding the CPLEX include files:
-I/home/root/Desktop/projects/LCAPS_software/cplex-12.5/cplex/include
-I/home/root/Desktop/projects/LCAPS_software/cplex-12.5/concert/include
As hybrid_ea.h also tries to include some CPLEX header files, the compilation of hybrid_ea.cpp should also have the options above.
If the makefile that you posted in your question is complete, then I suspect that the issue is the following: you didn't define a specific command to compile any .cc or .cpp file, except for Algorithm.cpp. Therefore, all other files are compiled using a default command g++ -ansi -O3 -c -o [file].o [file].cpp. And this default command doesn't have the include directives for the location of the CPLEX libraries.
As explained in ftp://ftp.gnu.org/old-gnu/Manuals/make-3.79.1/html_chapter/make_10.html, these files are compiled using make's implicit rules. The implicit rule for C++ files is to use $(CXX) -c $(CPPFLAGS) $(CXXFLAGS). Notice how this rule uses CPPFLAGS and CXXFLAGS rather than the variable CCFLAGS that you defined at the end of your makefile to include the proper include directives.
So changing the end of your makefile to the following should work:
CPPFLAGS = $(CCOPT) -I$(CPLEXINCDIR) -I$(CONCERTINCDIR)
all: ${TARGET}
Algorithm: Algorithm.o $(GREOBJS)
$(CCC) $(CCFLAGS) Algorithm.o $(GREOBJS) -o Algorithm $(CCLNFLAGS)
clean:
#rm -f *~ *.o ${TARGET} core
Once you define the variable CPPFLAGS, it will be used automatically to compile any .cpp file that you have in your project.
I have an app which uses Gtkmm for UI and I can compile it with a command line (saved in a script), and have read/tried to use a Makefile for it. See below:
SRCDIR = src
BINDIR = bin
OBJECTS = $(SRCDIR)/Dependency_1.o $(SRCDIR)/Dependencies_2.o $(SRCDIR)/Dependencies_N.o $(SRCDIR)/Gtkmm_Definitions.o App_Gtkmm.o
GTKFLAGS = `pkg-config --cflags gtkmm-3.0`
LIBS = `pkg-config --libs gtkmm-3.0`
CXX = g++
CXXFLAGS = -Wall -pthread -mms-bitfields
debug: EXEC = App_Gtkmm_debug
debug: $(OBJECTS)
$(CXX) $(CXXFLAGS) $(GTKFLAGS) -o $(BINDIR)/$(EXEC) $(OBJECTS) $(LIBS)
clean:
rm $(SRCDIR)/*.o $(BINDIR)/App_Gtkmm*
There is another target which I omitted for simplicity. The file structure is: Dependencies_X have class definitions which are just standard C++; Gtkmm_Definitions.hpp/.cpp have the Gtkmm-related declarations and definitions (gtkmm.h is included here) and App_Gtkmm.cpp is the main program.
When running "make debug", it will compile just part of the sources in the 1st pass and stop with some errors, that are gone when I run a 2nd time. This already seems a problem. Then it will stop when trying to compile Gtkmm_Definitions, saying it can't find gtkmm.h.
In file included from src/Gtkmm_Definitions.cpp:1:0:
src/Gtkmm_Definitions.hpp:1:10: fatal error: gtkmm.h: No such file or directory
#include <gtkmm.h>
^~~~~~~~~
compilation terminated.
make: *** [<builtin>: src/Gtkmm_Definitions.o] Error 1
However, this command line compiles without any problem:
g++ -Wall -pthread -mms-bitfields src/Dependencies_1.cpp src/Dependencies_N.cpp src/Gtkmm_Definitions.cpp App_Gtkmm.cpp -o bin/App_Gtkmm_debug `
pkg-config --cflags gtkmm-3.0 --libs gtkmm-3.0
Can you guys spot anything wrong in this Makefile? I have already tried a great deal of variables change of order, concatenation and online advices here and there.
I'm currently working on an R package which uses C++ code and includes external libraries (dlib, boost and an optimization library developed in the group). We're using Rcpp to integrate R and C++, but the problem is the package always fails to compile, and none of the similar questions I've found out there have worked for me.
The report generated by R CMD check is:
* installing *source* package 'IRTppExperimental' ...
** libs
*** arch - i386
c:/Rtools/mingw_32/bin/g++ -std=c++0x -I"C:/PROGRA~1/R/R-33~1.1/include" -DNDEBUG -I"C:/Users/Camilo/Documents/R/win-library/3.3/Rcpp/include" -I"d:/Compiler/gcc-4.9.3/local330/include" -I../src/include -O2 -Wall -mtune=core2 -c RcppExports.cpp -o RcppExports.o
c:/Rtools/mingw_32/bin/g++ -std=c++0x -I"C:/PROGRA~1/R/R-33~1.1/include" -DNDEBUG -I"C:/Users/Camilo/Documents/R/win-library/3.3/Rcpp/include" -I"d:/Compiler/gcc-4.9.3/local330/include" -I../src/include -O2 -Wall -mtune=core2 -c rcpp_hello_world.cpp -o rcpp_hello_world.o
c:/Rtools/mingw_32/bin/g++ -std=c++0x -I"C:/PROGRA~1/R/R-33~1.1/include" -DNDEBUG -I"C:/Users/Camilo/Documents/R/win-library/3.3/Rcpp/include" -I"d:/Compiler/gcc-4.9.3/local330/include" -I../src/include -O2 -Wall -mtune=core2 -c test_multi.cpp -o test_multi.o
c:/Rtools/mingw_32/bin/g++ -shared -s -static-libgcc -o IRTppExperimental.dll tmp.def RcppExports.o rcpp_hello_world.o test_multi.o -LC:/PROGRA~1/R/R-33~1.1/bin/i386 -lRlapack -LC:/PROGRA~1/R/R-33~1.1/bin/i386 -lRblas IRTppExperimental.dll -L../src/include -Ld:/Compiler/gcc-4.9.3/local330/lib/i386 -Ld:/Compiler/gcc-4.9.3/local330/lib -LC:/PROGRA~1/R/R-33~1.1/bin/i386 -lR
g++.exe: error: IRTppExperimental.dll: No such file or directory
no DLL was created
ERROR: compilation failed for package 'IRTppExperimental'
* removing 'C:/Users/Camilo/Documents/UNAL/MIRT/Tests/Temps/IRTppExperimental.Rcheck/IRTppExperimental'
And the Makevars/Makevars.win files are as follows:
INCFOLDER = ../src/include
PKG_LIBS += $(LAPACK_LIBS) $(BLAS_LIBS) $(FPICFLAGS) $(SHLIB)
PKG_LIBS += -L$(INCFOLDER)
PKG_CXXFLAGS+=-I$(INCFOLDER)
CXXFLAGS+="-fno-stack-protector"
CXX_STD = CXX11
Lastly, the NAMESPACE file reads:
exportPattern("^[[:alpha:]]+")
importFrom(Rcpp,sourceCpp)
useDynLib(IRTppExperimental)
All the c++ source files are inside the src folder, including the external libraries. The package was created using the Rcpp.package.skeleton function, and used the compileAtributes function to create the RcppExports source files.
EDIT: As pointed out by Coatless, here is github link of the project: https://github.com/SICSresearch/IRTpp/tree/Uni-Multi-Merging
I have seen that there are other questions concerning the problem of "fatal error: 'atomic' file not found", but unfortunately in noone I found a solution that works for me.
So I explain the problem: I am using a mac-os-x environment, I am a new user of mac. I need to compile a C++ code, named 'ASICs_Analysis' with a makefile. In the code I use root framework version 5.34/34.
When I try to compile using the command "make", I obtain this error:
In file included from /Users/danieleninci/IFAE/software/root/include/TObject.h:31:
/Users/danieleninci/IFAE/software/root/include/Rtypes.h:38:10: fatal error: 'atomic' file not found
#include <atomic>
^
1 error generated.
make: *** [ASICs_Analysis] Error 1
I include the 'atomic' file in the code but I have the same error.
The makefile I am using is this:
CXX = $(shell root-config --cxx)
CXXFLAGS = $(shell root-config --cflags) -std=c++11
LDFLAGS = $(shell root-config --libs) -L$(ROOTSYS)/lib
SOURCES = $(wildcard *.cpp)
TARGET = ASICs_Analysis
all: $(TARGET)
$(TARGET): $(SOURCES)
$(CXX) $(CXXFLAGS) $^ -o $# $(LDFLAGS)
.PHONY: clean
clean:
rm $(TARGET)
I tried to follow what was proposed in Qt 5.1 Beta Error using std::atomic c++11 feature , but it does not work for me.
Other info about the compiler installed:
gcc: i686-apple-darwin11-llvm-gcc-4.2 (GCC) 4.2.1
clang: Apple LLVM version 4.2 (clang-425.0.24) (based on LLVM 3.2svn)
Target: x86_64-apple-darwin11.4.2
Thread model: posix
Xcode: 4.6
I don't know with what this error could be related, maybe with the compiler? What is it going wrong?
Thank you for the help.
I am trying to run a opencv c++ project from ubuntu. I ve installed properly the opencv, I ve managed to run a simple opencv cpp file. I am trying to run my MSVC++ code. I put in the same file cpp and header files. I ve created the following makefile:
CC=g++
CFLAGS = `pkg-config --cflags opencv`
LIBS = `pkg-config --libs opencv`
executable: program.o Detection.o prediction.o
$(CC) -o executable $(LIBS) program.o Detection.o prediction
program.o:
$(CC) $(CFLAGS) -c program.cpp
Detection.o:
$(CC) $(CFLAGS) -c Detection.cpp
prediction.o:
$(CC) $(CFLAGS) -c prediction.cpp
I am receiving fatal error: core.hpp: No such file or directory
compilation terminated. Any idea for what I ve got to do??
Not a solution, but several marks about your makefile:
'prediction.o' on linkage line (maybe a wrong copy-paste)
I am not sure but it is not recommanded to put space when initialize your variables CFLAGS and LIBS
It is not necessary to precise source compilation
CC=g++
CFLAGS=pkg-config --cflags opencv
LIBS=pkg-config --libs opencv
executable: program.cpp Detection.cpp prediction.cpp
$(CC) program.cpp Detection.cpp prediction.cpp -o executable $(LIBS) $(CFLAGS)