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.
Related
I use a Linux environment for code development and testing of a program and now I want to compile an Windows ".exe" file so that my program can run on Windows OS, after some internet research I tried to modified my makefile to use x86_64-w64-mingw32-g++ instead of g++ as its compiler but now I get a segmentation fault at the end of the compilation and I am not sure how to debug this. My makefile is below:
PROGRAM=output.exe
COMPILER=x86_64-w64-mingw32-g++
# PROGRAM=output
# COMPILER=g++
#BIN_FOLDER=bin
DEPS += Defs.h Structs.h
CXXFLAGS+=`sdl2-config --cflags`
CXXFLAGS+=-DVERSION=$(VERSION) -DREVISION=$(REVISION) -DDATA_DIR=\"$(DATA_DIR)\"
CXXFLAGS+=-Wall -Wempty-body -Werror -Werror=maybe-uninitialized -Warray-bounds
CXXFLAGS+=-g -lefence -std=c++20 -fopenmp
LDFLAGS+=-L/usr/local/lib -lSDL2 -lSDL2_mixer -lSDL2_image -lSDL2_ttf -fopenmp src/ECS/*.cpp #-pg
FILENAME:= $(patsubst %.cpp,%.o,$(wildcard src/*.cpp))
$(PROGRAM):$(FILENAME)
$(COMPILER) $(FILENAME) -o $# $(LDFLAGS)
clean:
rm src/*.o
this compiles without a problem in g++ but when using the mingw32 compiler I get this error:
x86_64-w64-mingw32-g++ src/ActionManager.o src/AStar.o ...[a bunch of .o files] -o output.exe
collect2: fatal error: ld terminated with signal 11 [Segmentation fault], core dumped
compilation terminated.
make: *** [makefile:26: output.exe] Error 1
I tried compiling a simple helloWorld.cpp program using x86_64-w64-mingw32-g++ like this: x86_64-w64-mingw32-g++ 01_hello_world.c -o windowshello.exe and that works fine.
I also tried deleting all my LDFLAGS just to see what would happen and I get the same result.
Could anyone point me into the right direction as to how I might debug this? Is this a particular part of my code that is causing this or am I going about this entirely wrong?
Just a disclaimer I'm not too experienced with Make files, so forgive me if the answer is simple! I have a Make file that compiles several .cpp & .h files into .o files, and then produces an executable. I am using g++ as the compiler currently. I'd like to adapt this file to allow for openmpi multi-core computing. To note: I'm on a Windows 11 x 64 architecture, using Cygwin to build run this cpp code. I also would like this to run on MacOS systems as well.
In particular, the parallelization macros are only in 1 .cpp file, what I'd consider the 'main' file of this project (mag_spec_tracker.cpp). I don't know if that makes a difference here but thought it could be useful to let be known.
My current Makefile is below - note I added a line to try and grab the mpicc compile flags, but I am unsure on how to use them here.
IDIR = include
CXX = g++
CXXFLAGS = -I$(IDIR) -std=c++17
ODIR = obj
_DEPS = my_functions.h particle.h beam.h threevector.h threematrix.h screen.h magnet.h
DEPS = $(patsubst %,$(IDIR)/%,$(_DEPS))
_OBJ = my_functions.o particle.o beam.o mag_spec_tracker.o screen.o magnet.o
OBJ = $(patsubst %,$(ODIR)/%,$(_OBJ))
$(ODIR)/%.o: %.cpp $(DEPS)
$(CXX) -c -o $# $< $(CXXFLAGS)
run: $(OBJ)
$(CXX) -o $# $^ $(CXXFLAGS)
.PHONY: clean
clean:
rm -f $(ODIR)/*.o *~ core $(IDIR)/*~
I have tried adding lines into the Makefile to get the mpi compile flags based on other reference I've found online, but was unsure how to adapt my current code to add these flags to allow for correct usage of openmpi. The lines I added to grab compile flags were:
MPI_COMPILE_FLAGS = $(shell mpicc --showme:compile)
MPI_LINK_FLAGS = $(shell mpicc --showme:link)
Thank you in advance!
Update (12/6/2022)
Responding to the comment from Matzeri ('for opempi the compiler is mpicc not gcc. for c++ is mpicxx not g++'), I replaced 'g++' in my makefile with 'mpicxx' and recieved the following error:
$ make
mpicxx -c -o obj/mag_spec_tracker.o mag_spec_tracker.cpp -Iinclude -std=c++17
mpicxx -o run obj/my_functions.o obj/particle.o obj/beam.o obj/mag_spec_tracker.o obj/screen.o obj/magnet.o -Iinclude -std=c++17
C:/Users/Jason/mingw64/bin/../lib/gcc/x86_64-w64-mingw32/12.2.0/../../../../x86_64-w64-mingw32/bin/ld.exe: cannot find -lmpi_cxx: No such file or directory
C:/Users/Jason/mingw64/bin/../lib/gcc/x86_64-w64-mingw32/12.2.0/../../../../x86_64-w64-mingw32/bin/ld.exe: cannot find -lmpi: No such file or directory
C:/Users/Jason/mingw64/bin/../lib/gcc/x86_64-w64-mingw32/12.2.0/../../../../x86_64-w64-mingw32/bin/ld.exe: cannot find -lopen-rte: No such file or directory
C:/Users/Jason/mingw64/bin/../lib/gcc/x86_64-w64-mingw32/12.2.0/../../../../x86_64-w64-mingw32/bin/ld.exe: cannot find -lopen-pal: No such file or directory
collect2.exe: error: ld returned 1 exit status
make: *** [Makefile:19: run] Error 1
I notice that its looking for an ld executable in 'mingw64'. I tried removing that directory (previously I had installed mingw64, but switched to cygwin), and got the following error:
$ make
mpicxx -o run obj/my_functions.o obj/particle.o obj/beam.o obj/mag_spec_tracker.o obj/screen.o obj/magnet.o -Iinclude -std=c++17
--------------------------------------------------------------------------
The Open MPI wrapper compiler was unable to find the specified compiler
g++ in your PATH.
Note that this compiler was either specified at configure time or in
one of several possible environment variables.
--------------------------------------------------------------------------
make: *** [Makefile:19: run] Error 1
I also added c:\cygwin\bin to my environment paths, and this issue still occurs. I confirmed that mpicxx is in that bin folder.
Any ideas?
I wrote a C++ software using GTK2 library for UI.
It'a simple software that analyze a map coded on XML file to calculate the shortest path between two points and draw it on the image (I'm using Cairo library for this).
The compilation (with makefile) gave no errors but when I execute the program the window appears empty.If I try to compile with debug option (-g) and execute the program with ddd for debugging it returnS "no debugging symbols found".
makefile is
CXXFLAGS += -Wall `pkg-config --cflags --libs gtk+-2.0`
ObjectsMy = main.o interface.o callback.o map.o path.o draw.o
NaViGaToR: DependenciesMy $(ObjectsMy)
g++ -g $(ObjectsMy) -o NaViGaToR `pkg-config gtk+-2.0 --cflags --libs`
DependenciesMy:
g++ -MM main.cpp interface.cpp callback.cpp map.cpp path.cpp draw.cpp
> DependenciesMy
-include DependenciesMy
.PHONY: clean cleanall
clean:
rm $(ObjectsMy) DependenciesMy
rm $ map.png
cleanall:
rm $(ObjectsMy) NaViGaToR DependenciesMy
rm $ map.png
Can you see some error in this?
You are passing -g to the linker and not to the compiler. If there's no debugging info in the object files there won't be any in the executable. You need to add -g to the CXXFLAGS.
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)
So I'm having trouble compiling my application which is using yaml-cpp
I'm including "yaml.h" in my source files (just like the examples in the yaml-cpp wiki) but when I try compiling the application I get the following error:
g++ -c -o entityresourcemanager.o entityresourcemanager.cpp
entityresourcemanager.cpp:2:18: error: yaml.h: No such file or directory
make: *** [entityresourcemanager.o] Error 1
my makefile looks like this:
CC = g++
CFLAGS = -Wall
APPNAME = game
UNAME = uname
OBJECTS := $(patsubst %.cpp,%.o,$(wildcard *.cpp))
mac: $(OBJECTS)
$(CC) `pkg-config --cflags --libs sdl` `pkg-config --cflags --libs yaml-cpp` $(CFLAGS) -o $(APPNAME) $(OBJECTS)
pkg-config --cflags --libs yaml-cpp returns:
-I/usr/local/include/yaml-cpp -L/usr/local/lib -lyaml-cpp
and yaml.h is indeed located in /usr/local/include/yaml-cpp
Any idea what I could do?
Thanks
Your default target is "mac" and you have rule how to build it. It depends on object files and you do not have any rules how to build those, so make is using its implicit rules. Those rules do just that:
g++ -c -o entityresourcemanager.o entityresourcemanager.cpp
As you can see there is no -I/usr/local/... part here.
The easiest way to fix that is to change CPPFLAGS and LDFLAGS value globally:
YAML_CFLAGS := $(shell pkg-config --cflags yaml-cpp)
YAML_LDFLAGS := $(shell pkg-config --libs yaml-cpp)
SDL_CFLAGS := $(shell pkg-config --cflags sdl)
SDL_LDFLAGS := $(shell pkg-config --libs sdl)
CPPFLAGS += $(YAML_CFLAGS) $(SDL_CFLAGS)
LDFLAGS += $(YAML_LDFLAGS) $(SDL_LDFLAGS)
mac: $(OBJECTS)
$(CXX) -o $(APPNAME) $(OBJECTS) $(LDFLAGS)
CPPFLAGS value is used by implicit rules that build object files from cpp files, so now compiler should find yaml headers.
Edit:
LDFLAGS probably should go after OBJECTS
Don't you mismatch your include directory?
-I/usr/local/include
instead of
-I/usr/local/include/yaml-cpp