I'm doing some modifications to an existing project which is pretty big, so it's built with the autotools. The modifications involve the Ibex library, so I've added an #include "ibex.h" in one of the source files. The library is properly installed on my system, I have the following files:
/usr/local/lib/libibex.a
/usr/local/include/ibex/ibex.h
/usr/local/share/pkgconfig/ibex.pc
Results of the pkg-config commands:
$ pkg-config --libs ibex
-L/usr/local/lib -libex -lprim -lClp -lCoinUtils -lm
$ pkg-config --cflags ibex
-frounding-math -ffloat-store -I/usr/local/include -I/usr/local/include/ibex
The original Makefile.am corresponding to the compil unit I want to get to use ibex, is as follows:
noinst_LTLIBRARIES = liblrasolver.la
AM_CPPFLAGS=$(config_includedirs)
liblrasolver_la_SOURCES = LAVar.h LAVar.C Delta.h Delta.C LRASolver.h LRASolver.C LAArray.h LAArray.C LARow.h LARow.C LAColumn.h LAColumn.C
if WANT_LIBRARY
include_HEADERS = Delta.h LAArray.h LAColumn.h LARow.h LAVar.h LRASolver.h
endif
I modified it this way:
noinst_LTLIBRARIES = liblrasolver.la
AM_CPPFLAGS=$(config_includedirs) `pkg-config --cflags ibex`
AM_LDFLAGS=`pkg-config --libs ibex` -lblas -llapack
liblrasolver_la_SOURCES = LAVar.h LAVar.C Delta.h Delta.C LRASolver.h LRASolver.C LAArray.h LAArray.C LARow.h LARow.C LAColumn.h LAColumn.C
if WANT_LIBRARY
include_HEADERS = Delta.h LAArray.h LAColumn.h LARow.h LAVar.h LRASolver.h
endif
Came to this modification by looking into the generic Makefile provided along with ibex sources to compile ibex projects:
SRCS=$(wildcard *.cpp)
BINS=$(SRCS:.cpp=)
CXXFLAGS := $(shell pkg-config --cflags ibex)
LIBS := $(shell pkg-config --libs ibex) -lblas -llapack
ifeq ($(DEBUG), yes)
CXXFLAGS := $(CXXFLAGS) -O0 -g -pg -Wall -frounding-math
else
CXXFLAGS := $(CXXFLAGS) -O3 -DNDEBUG -Wno-deprecated -frounding-math
endif
all: $(BINS)
% : %.cpp
$(CXX) $(CPPFLAGS) $(CXXFLAGS) -o $# $< $(LIBS)
clean:
rm -f $(BINS)
Ok, autoreconf works, as well as ./configure (though its output never talks about "ibex" which I find suspicious already). But make fails. Doesn't find the header:
../../../src/tsolvers/lrasolver/LRASolver.h:38:18: fatal error: ibex.h: No such file or directory
#include "ibex.h"
You're not using pkg-config correctly. You should use the PKG_CHECK_MODULES macro, see for reference https://autotools.io/pkgconfig/pkg_check_modules.html (full disclosure: I wrote that.)
You're also using AM_LDFLAGS incorrectly since libraries are not ldflags. You should use _LIBADD.
Related
I have been trying to set up my coding environment for GUI development in c++ recently, with little success. I use Manjaro Linux with Visual Studio Code, but for some reason, I always seem to get include errors when including files that I know are there.
Most recently, I tried to set up gtkmm-4.0 by installing the package and the documentation. I double checked in /usr/include/ to ensure the packages were all present, but I still am getting include errors:
cannot open source file "gtkmm.h" and
gtkmm.h:No such file or directory
At this point, all the code I have is:
#include <gtkmm.h>
#include <iostream>
int main(int argc, char* argv[]){
return 0;
}
Makefile:
exec = game.out
sources = $(wildcard src/*.cpp)
objects = $(sources:.cpp=.o)
flags = -g $(shell pkg-config gtkmm-4.0 --cflags)
libs = $(shell pkg-config gtkmm-4.0 --libs)
$(exec): $(objects)
g++ $(objects) $(flags) -o $(exec) $(libs)
%.o: %.cpp include/%.h
g++ -c $(flags) $< -o $#
install:
make
cp ./game.out /usr/local/bin/game
clean:
-rm *.out
-rm *.o
-rm src/*.o
I have scoured the internet for answers, but everything I found was either for a different os/environment or just didn't
#Galik and #John helped me solve this!
What I had to do was use g++ src/main.cpp -o main $(pkg-config gtkmm-4.0 --cflags --libs) to compile my code, then run the executable.
Thank you both for your help and guidance!!
You need to install pkg-configand add this to the compiler flags in your Makefile:
flags = -g $(shell pkg-config gtkmm-2.4 --cflags)
libs = $(shell pkg-config gtkmm-2.4 --libs)
# ...
$(exec): $(objects)
g++ $(objects) $(flags) -o $(exec) $(libs)
The tool pkg-config has a database of the correct paths for supporting libraries.
Depending on your version if gtkmm, you may need to substitute gtkmm-3.0, if you have version 3.0.
So I am using nvidia's deepstream sdk and trying to modify the makefile of one of the sample examples given as I wish to link and add my own libraries. This is the makefile being employed where I am setting the path of the CUSTOM_LIB to point to the location of my library. The issue is the project gets compiled successfully but during run time, its unable to find the custom library. I performed ldd on the executable generated and there also it was showing the library as 'not found'. I think it's something to do with rpath but I am not sure about that.
APP:= sample
TARGET_DEVICE = $(shell gcc -dumpmachine | cut -f1 -d -)
NVDS_VERSION:=4.0
LIB_INSTALL_DIR?=/opt/nvidia/deepstream/deepstream-$(NVDS_VERSION)/lib/
ifeq ($(TARGET_DEVICE),aarch64)
CFLAGS:= -DPLATFORM_TEGRA
endif
CUDA_VER:=10.0
CC:=g++
SRCS:= $(wildcard ../src/*.c)
#SRCS+= $(wildcard ../../apps-common/src/*.c)
#SRCS+=
INCS:= $(wildcard ../include/*.h)
PKGS:= gstreamer-1.0 gstreamer-video-1.0 x11 opencv
OBJS:= $(SRCS:.c=.o)
CFLAGS+= -I../include -I/usr/include -I$(CUSTOM_LIB)/include -I/usr/local/cuda-10.0/targets/aarch64-linux/include/ -I/usr/include/jsoncpp -DDS_VERSION_MINOR=0 -DDS_VERSION_MAJOR=4 -fpermissive -Wnarrowing
LIBS+= -L$(LIB_INSTALL_DIR) -L/usr/lib/aarch64-linux-gnu -L$(CUSTOM_LIB)/lib -L/usr/lib/aarch64-linux-gnu/ -lcurl -letlic -letolm -lssl -lcrypto -llogger -lpthread -lsqlite3 -ljsoncpp -lnvdsgst_meta -lnvbufsurface -lnvbufsurftransform -lnvds_meta -lnvdsgst_helper -lnvds_utils -lm -L/usr/local/cuda-$(CUDA_VER)/lib64/ -lcudart \
-lgstrtspserver-1.0 -Wl,-rpath,$(LIB_INSTALL_DIR)
CFLAGS+= `pkg-config --cflags $(PKGS)`
LIBS+= `pkg-config --libs $(PKGS)`
all: $(APP)
debug: CXXFLAGS += -DDEBUG -g
debug: CFLAGS += -DDEBUG -g
debug: $(APP)
%.o: %.c $(INCS) Makefile
$(CC) -c -o $# $(CFLAGS) $<
$(APP): $(OBJS) Makefile
$(CC) -o $(APP) $(OBJS) $(LIBS)
clean:
rm -rf $(OBJS) $(APP)
You need to set rpath to a colon-separated list of directories where your libraries are found. You only add LIB_INSTALL_DIR but not CUSTOM_LIB_DIR. Generally everything you pass to -L you need to pass to -rpath too, unless there is a specific reason not to. For example, if you are building a package that has more than a single library and you are going to install in a standard place like /usr/lib, you don't have to add the directory where libraries temporarily live to -rpath. If you are going to install to a non-standard directory, add that directory.
I have opencv3 installed through home-brew and pkg-config can find the linkers too by
pkg-config --cflags --libs opencv
the outputs contains -lopencv_core, but when I add that in Makefile like this
CC=clang++
CFLAGS= -Wall -g -std=c++0x
LFLAGS= -I/usr/local/Cellar/opencv3/3.2.0/include -I/usr/local/Cellar/opencv3/3.2.0/bin -I/usr/local/Cellar/opencv3/3.2.0/lib -lopencv_core
CFILES=blah.cpp
HFILES=blah.hpp
OFILES=blah.o
all: main
%.o: %.cpp $(HFILES)
$(CC) -c $(CFLAGS) $< -o $# $(LFLAGS)
main: $(OFILES) $(HFILES)
$(CC) $(CFLAGS) $(OFILES) -o main $(LFLAGS)
it says
ld: library not found for -lopencv_core
clang: error: linker command failed with exit code 1 (use -v to see invocation)
How should I link that to gcc?
Assuming you want CFLAGS to be the options for compilation and LFLAGS to
be the options for linkage, the settings:
CFLAGS= -Wall -g -std=c++0x
LFLAGS= -I/usr/local/Cellar/opencv3/3.2.0/include -I/usr/local/Cellar/opencv3/3.2.0/bin -I/usr/local/Cellar/opencv3/3.2.0/lib -lopencv_core
are confused.
The -I path option is meaningful for compilation and meaningless for linkage. It
tells the preprocessor to search in path for header files that you #include in
the source code. There will be header files in:
/usr/local/Cellar/opencv3/3.2.0/include
There will be no header files in:
/usr/local/Cellar/opencv3/3.2.0/bin
just executables, which are irrelevant to building your program. And there will be no header files in:
/usr/local/Cellar/opencv3/3.2.0/lib
just static and or dynamic libraries.
The library libopencv_core that linker can't find is presumably
in /usr/local/Cellar/opencv3/3.2.0/lib. The way to tell the
linker to search there for the library is:
-L/usr/local/Cellar/opencv3/3.2.0/lib -lopencv_core
So these settings make sense:
CFLAGS := -Wall -g -std=c++0x -I/usr/local/Cellar/opencv3/3.2.0/include
LFLAGS := -L/usr/local/Cellar/opencv3/3.2.0/lib -lopencv_core
However, to compile and link an opencv program you would probably be better
leaving it to pkg-config to get the options right:
CFLAGS := -Wall -g -std=c++0x $(shell pkg-config --cflags opencv)
LFLAGS := $(shell pkg-config --libs opencv)
The -l option looks in the usual places for the mentioned library. Where and what it looks varies by OS, which you didn't mention. Possibly it can be fixed by adding -L /usr/local/lib or some other path to where you know the libraries are.
I have did some reading on "Merging Makefiles", one suggest I should leave the two Makefiles separate in different folders [1]. For me this look counter intuitive, because I have the following situation:
I have 3 source files (main.cpp flexibility.cpp constraints.cpp) one of them (flexibility.cpp) is making use of the COIN-OR Linear Programming library (Clp) When installing this library on my computer it makes sample Makefiles, which I have adjust the Makefile and it currently makes a good working binary.
# Copyright (C) 2006 International Business Machines and others.
# All Rights Reserved.
# This file is distributed under the Eclipse Public License.
# $Id: Makefile.in 726 2006-04-17 04:16:00Z andreasw $
##########################################################################
# You can modify this example makefile to fit for your own program. #
# Usually, you only need to change the five CHANGEME entries below. #
##########################################################################
# To compile other examples, either changed the following line, or
# add the argument DRIVER=problem_name to make
DRIVER = main
# CHANGEME: This should be the name of your executable
EXE = clp
# CHANGEME: Here is the name of all object files corresponding to the source
# code that you wrote in order to define the problem statement
OBJS = $(DRIVER).o constraints.o flexibility.o
# CHANGEME: Additional libraries
ADDLIBS =
# CHANGEME: Additional flags for compilation (e.g., include flags)
ADDINCFLAGS =
# CHANGEME: Directory to the sources for the (example) problem definition
# files
SRCDIR = .
##########################################################################
# Usually, you don't have to change anything below. Note that if you #
# change certain compiler options, you might have to recompile the #
# COIN package. #
##########################################################################
COIN_HAS_PKGCONFIG = TRUE
COIN_CXX_IS_CL = #TRUE
COIN_HAS_SAMPLE = TRUE
COIN_HAS_NETLIB = #TRUE
# C++ Compiler command
CXX = g++
# C++ Compiler options
CXXFLAGS = -O3 -pipe -DNDEBUG -pedantic-errors -Wparentheses -Wreturn-type -Wcast-qual -Wall -Wpointer-arith -Wwrite-strings -Wconversion -Wno-unknown-pragmas -Wno-long-long -DCLP_BUILD
# additional C++ Compiler options for linking
CXXLINKFLAGS = -Wl,--rpath -Wl,/home/martijn/Downloads/COIN/coin-Clp/lib
# C Compiler command
CC = gcc
# C Compiler options
CFLAGS = -O3 -pipe -DNDEBUG -pedantic-errors -Wimplicit -Wparentheses -Wsequence-point -Wreturn-type -Wcast-qual -Wall -Wno-unknown-pragmas -Wno-long-long -DCLP_BUILD
# Sample data directory
ifeq ($(COIN_HAS_SAMPLE), TRUE)
ifeq ($(COIN_HAS_PKGCONFIG), TRUE)
CXXFLAGS += -DSAMPLEDIR=\"`PKG_CONFIG_PATH=/home/martijn/Downloads/COIN/coin-Clp/lib64/pkgconfig:/home/martijn/Downloads/COIN/coin-Clp/lib/pkgconfig:/home/martijn/Downloads/COIN/coin-Clp/share/pkgconfig: pkg-config --variable=datadir coindatasample`\"
CFLAGS += -DSAMPLEDIR=\"`PKG_CONFIG_PATH=/home/martijn/Downloads/COIN/coin-Clp/lib64/pkgconfig:/home/martijn/Downloads/COIN/coin-Clp/lib/pkgconfig:/home/martijn/Downloads/COIN/coin-Clp/share/pkgconfig: pkg-config --variable=datadir coindatasample`\"
else
CXXFLAGS += -DSAMPLEDIR=\"\"
CFLAGS += -DSAMPLEDIR=\"\"
endif
endif
# Netlib data directory
ifeq ($(COIN_HAS_NETLIB), TRUE)
ifeq ($(COIN_HAS_PKGCONFIG), TRUE)
CXXFLAGS += -DNETLIBDIR=\"`PKG_CONFIG_PATH=/home/martijn/Downloads/COIN/coin-Clp/lib64/pkgconfig:/home/martijn/Downloads/COIN/coin-Clp/lib/pkgconfig:/home/martijn/Downloads/COIN/coin-Clp/share/pkgconfig: pkg-config --variable=datadir coindatanetlib`\"
CFLAGS += -DNETLIBDIR=\"`PKG_CONFIG_PATH=/home/martijn/Downloads/COIN/coin-Clp/lib64/pkgconfig:/home/martijn/Downloads/COIN/coin-Clp/lib/pkgconfig:/home/martijn/Downloads/COIN/coin-Clp/share/pkgconfig: pkg-config --variable=datadir coindatanetlib`\"
else
CXXFLAGS += -DNETLIBDIR=\"\"
CFLAGS += -DNETLIBDIR=\"\"
endif
endif
# Include directories (we use the CYGPATH_W variables to allow compilation with Windows compilers)
ifeq ($(COIN_HAS_PKGCONFIG), TRUE)
INCL = `PKG_CONFIG_PATH=/home/martijn/Downloads/COIN/coin-Clp/lib64/pkgconfig:/home/martijn/Downloads/COIN/coin-Clp/lib/pkgconfig:/home/martijn/Downloads/COIN/coin-Clp/share/pkgconfig: pkg-config --cflags clp`
else
INCL =
endif
INCL += $(ADDINCFLAGS)
# Linker flags
ifeq ($(COIN_HAS_PKGCONFIG), TRUE)
LIBS = `PKG_CONFIG_PATH=/home/martijn/Downloads/COIN/coin-Clp/lib64/pkgconfig:/home/martijn/Downloads/COIN/coin-Clp/lib/pkgconfig:/home/martijn/Downloads/COIN/coin-Clp/share/pkgconfig: pkg-config --libs clp`
else
ifeq ($(COIN_CXX_IS_CL), TRUE)
LIBS = -link -libpath:`$(CYGPATH_W) /home/martijn/Downloads/COIN/coin-Clp/lib` libClp.lib
else
LIBS = -L/home/martijn/Downloads/COIN/coin-Clp/lib -lClp
endif
endif
# The following is necessary under cygwin, if native compilers are used
CYGPATH_W = echo
# Here we list all possible generated objects or executables to delete them
CLEANFILES = clp \
main.o \
flexibility.o \
constraints.o \
all: $(EXE)
.SUFFIXES: .cpp .c .o .obj
$(EXE): $(OBJS)
bla=;\
for file in $(OBJS); do bla="$$bla `$(CYGPATH_W) $$file`"; done; \
$(CXX) $(CXXLINKFLAGS) $(CXXFLAGS) -o $# $$bla $(LIBS) $(ADDLIBS)
clean:
rm -rf $(CLEANFILES)
.cpp.o:
$(CXX) $(CXXFLAGS) $(INCL) -c -o $# `test -f '$<' || echo '$(SRCDIR)/'`$<
.cpp.obj:
$(CXX) $(CXXFLAGS) $(INCL) -c -o $# `if test -f '$<'; then $(CYGPATH_W) '$<'; else $(CYGPATH_W) '$(SRCDIR)/$<'; fi`
.c.o:
$(CC) $(CFLAGS) $(INCL) -c -o $# `test -f '$<' || echo '$(SRCDIR)/'`$<
.c.obj:
$(CC) $(CFLAGS) $(INCL) -c -o $# `if test -f '$<'; then $(CYGPATH_W) '$<'; else $(CYGPATH_W) '$(SRCDIR)/$<'; fi`
The other Makefile compiles a lot of code and makes use of bison and flex. This one is also made by someone else. I am able to alter this Makefile when I want to add some code. This Makefile also makes a binary.
CFLAGS=-Wall
LDLIBS=-LC:/GnuWin32/lib -lfl -lm
LSOURCES=lex.l
YSOURCES=grammar.ypp
CSOURCES=debug.cpp esta_plus.cpp heap.cpp main.cpp stjn.cpp timing.cpp tmsp.cpp token.cpp chaining.cpp flexibility.cpp exceptions.cpp
HSOURCES=$(CSOURCES:.cpp=.h) includes.h
OBJECTS=$(LSOURCES:.l=.o) $(YSOURCES:.ypp=.tab.o) $(CSOURCES:.cpp=.o)
all: solver
solver: CFLAGS+=-g -O0 -DDEBUG
solver: $(OBJECTS) main.o debug.o
g++ $(CFLAGS) -o $# $^ $(LDLIBS)
solver.release: CFLAGS+=-O5
solver.release: $(OBJECTS) main.o
g++ $(CFLAGS) -o $# $^ $(LDLIBS)
%.o: %.cpp
g++ -c $(CFLAGS) -o $# $<
lex.cpp: lex.l grammar.tab.cpp grammar.tab.hpp
flex -o$# $<
%.tab.cpp %.tab.hpp: %.ypp
bison --verbose -d $<
ifneq ($(LSOURCES),)
$(LSOURCES:.l=.cpp): $(YSOURCES:.y=.tab.h)
endif
-include $(OBJECTS:.o=.d)
clean:
rm -f $(OBJECTS) $(OBJECTS:.o=.d) $(YSOURCES:.ypp=.tab.cpp) $(YSOURCES:.ypp=.tab.hpp) $(YSOURCES:.ypp=.output) $(LSOURCES:.l=.cpp) solver solver.release 2>/dev/null
.PHONY: all clean debug release
Both of these Makefiles are, for me, hard to understand. I don't know what they exactly do. What I want is to merge the two of them so I get only one binary. The code compiled in the second Makefile should be the result. I want to add flexibility.cpp and constraints.cpp to the second Makefile, but when I do. I get the problem following problem:
flexibility.h:4:26: fatal error: ClpSimplex.hpp: No such file or directory
#include "ClpSimplex.hpp"
So the compiler can't find the Clp library. I also tried to copy-paste more code from the first Makefile into the second, but it still gives me that same error.
Q: Can you please help me with merging the two makefiles or pointing out a more elegant way?
Q: In this case is it indeed better to merge the two Makefiles?
I also tried to use cmake, but I gave upon that one quickly, because I don't know much about flex and bison.
g++ -O3 -pipe -DNDEBUG -pedantic-errors -Wparentheses -Wreturn-type -Wcast-qual -Wall -Wpointer-arith -Wwrite-strings -Wconversion -Wno-unknown-pragmas -Wno-long-long -DCLP_BUILD -DSAMPLEDIR=\"`PKG_CONFIG_PATH=/home/martijn/Downloads/COIN/coin-Clp/lib64/pkgconfig:/home/martijn/Downloads/COIN/coin-Clp/lib/pkgconfig:/home/martijn/Downloads/COIN/coin-Clp/share/pkgconfig: pkg-config --variable=datadir coindatasample`\" `PKG_CONFIG_PATH=/home/martijn/Downloads/COIN/coin-Clp/lib64/pkgconfig:/home/martijn/Downloads/COIN/coin-Clp/lib/pkgconfig:/home/martijn/Downloads/COIN/coin-Clp/share/pkgconfig: pkg-config --cflags clp` -c -o main.o `test -f 'main.cpp' || echo './'`main.cpp
g++ -O3 -pipe -DNDEBUG -pedantic-errors -Wparentheses -Wreturn-type -Wcast-qual -Wall -Wpointer-arith -Wwrite-strings -Wconversion -Wno-unknown-pragmas -Wno-long-long -DCLP_BUILD -DSAMPLEDIR=\"`PKG_CONFIG_PATH=/home/martijn/Downloads/COIN/coin-Clp/lib64/pkgconfig:/home/martijn/Downloads/COIN/coin-Clp/lib/pkgconfig:/home/martijn/Downloads/COIN/coin-Clp/share/pkgconfig: pkg-config --variable=datadir coindatasample`\" `PKG_CONFIG_PATH=/home/martijn/Downloads/COIN/coin-Clp/lib64/pkgconfig:/home/martijn/Downloads/COIN/coin-Clp/lib/pkgconfig:/home/martijn/Downloads/COIN/coin-Clp/share/pkgconfig: pkg-config --cflags clp` -c -o constraints.o `test -f 'constraints.cpp' || echo './'`constraints.cpp
g++ -O3 -pipe -DNDEBUG -pedantic-errors -Wparentheses -Wreturn-type -Wcast-qual -Wall -Wpointer-arith -Wwrite-strings -Wconversion -Wno-unknown-pragmas -Wno-long-long -DCLP_BUILD -DSAMPLEDIR=\"`PKG_CONFIG_PATH=/home/martijn/Downloads/COIN/coin-Clp/lib64/pkgconfig:/home/martijn/Downloads/COIN/coin-Clp/lib/pkgconfig:/home/martijn/Downloads/COIN/coin-Clp/share/pkgconfig: pkg-config --variable=datadir coindatasample`\" `PKG_CONFIG_PATH=/home/martijn/Downloads/COIN/coin-Clp/lib64/pkgconfig:/home/martijn/Downloads/COIN/coin-Clp/lib/pkgconfig:/home/martijn/Downloads/COIN/coin-Clp/share/pkgconfig: pkg-config --cflags clp` -c -o flexibility.o `test -f 'flexibility.cpp' || echo './'`flexibility.cpp
bla=;\
for file in main.o constraints.o flexibility.o; do bla="$bla `echo $file`"; done; \
g++ -Wl,--rpath -Wl,/home/martijn/Downloads/COIN/coin-Clp/lib -O3 -pipe -DNDEBUG -pedantic-errors -Wparentheses -Wreturn-type -Wcast-qual -Wall -Wpointer-arith -Wwrite-strings -Wconversion -Wno-unknown-pragmas -Wno-long-long -DCLP_BUILD -DSAMPLEDIR=\"`PKG_CONFIG_PATH=/home/martijn/Downloads/COIN/coin-Clp/lib64/pkgconfig:/home/martijn/Downloads/COIN/coin-Clp/lib/pkgconfig:/home/martijn/Downloads/COIN/coin-Clp/share/pkgconfig: pkg-config --variable=datadir coindatasample`\" -o clp $bla `PKG_CONFIG_PATH=/home/martijn/Downloads/COIN/coin-Clp/lib64/pkgconfig:/home/martijn/Downloads/COIN/coin-Clp/lib/pkgconfig:/home/martijn/Downloads/COIN/coin-Clp/share/pkgconfig: pkg-config --libs clp`
This is coming out of the first Makefile, looks like there are some errors in it? Printing things like echo looks really stupid.
What I want is to merge the two of them so I get only one binary.
I believe you have a complete wrong understanding what make does and what a Makefile is good for and there is a big misunderstanding what the concept of libraries, modules and programs ( binaries ) is.
As a first hint:
You can have multiple Makefiles in one directory. They can have every name you want to give them! "Makefile" is only the standard name which is searched first from the make command. Typical names are *.mk for modules of makefiles.
The next thing is, that there is no problem to call a makefile directly from make with another name. Simply use make -f xyz.mk to get this makefile in action.
The next thing is, that you can also include one makefile from another with "include".
I have not enough time to create your makefiles at all. But you should start with a little analyses:
What are your sources
What are your intermediate products / libraries / object - files
which objects will be linked to final product or libraries
which are the final products build up.
After that you can simply build your makefile toolchain. But you have start with some basic reading and some experiments with make.
I have run the first Makefile and used the output on the terminal to edit the second Makefile. I also have added the -std=c++11 flag which solved a few errors. The thing is compiling with the included libraries. I should be able to move on without any problems.
The working result with a few warnings:
CFLAGS=-Wall
LDLIBS=-LC:/GnuWin32/lib -lfl -lm
LSOURCES=lex.l
YSOURCES=grammar.ypp
CSOURCES=debug.cpp esta_plus.cpp heap.cpp main.cpp stjn.cpp timing.cpp tmsp.cpp token.cpp chaining.cpp exceptions.cpp constraints.cpp flexibility.cpp
HSOURCES=$(CSOURCES:.cpp=.h) includes.h
OBJECTS=$(LSOURCES:.l=.o) $(YSOURCES:.ypp=.tab.o) $(CSOURCES:.cpp=.o)
# C++ Compiler options
CXXFLAGS = -std=c++11 -O3 -pipe -DNDEBUG -pedantic-errors -Wparentheses -Wreturn-type -Wcast-qual -Wall -Wpointer-arith -Wwrite-strings -Wconversion -Wno-unknown-pragmas -Wno-long-long -DCLP_BUILD
EXTRAFLAG = -std=c++11 -Wl,--rpath -Wl,/home/martijn/Downloads/COIN/coin-Clp/lib -O3 -pipe -DNDEBUG -pedantic-errors -Wparentheses -Wreturn-type -Wcast-qual -Wall -Wpointer-arith -Wwrite-strings -Wconversion -Wno-unknown-pragmas -Wno-long-long -DCLP_BUILD -DSAMPLEDIR=\"`PKG_CONFIG_PATH=/home/martijn/Downloads/COIN/coin-Clp/lib64/pkgconfig:/home/martijn/Downloads/COIN/coin-Clp/lib/pkgconfig:/home/martijn/Downloads/COIN/coin-Clp/share/pkgconfig: pkg-config --variable=datadir coindatasample`\"
EXTRALIB = `PKG_CONFIG_PATH=/home/martijn/Downloads/COIN/coin-Clp/lib64/pkgconfig:/home/martijn/Downloads/COIN/coin-Clp/lib/pkgconfig:/home/martijn/Downloads/COIN/coin-Clp/share/pkgconfig: pkg-config --libs clp`
all: solver
solver: CFLAGS+=-g -O0 -DDEBUG
solver: $(OBJECTS) main.o debug.o
g++ $(CFLAGS) $(EXTRAFLAG) -o $# $^ $(LDLIBS) $(EXTRALIB)
solver.release: CFLAGS+=-O5
solver.release: $(OBJECTS) main.o
g++ $(CFLAGS) -o $# $^ $(LDLIBS)
main.o: main.cpp
g++ $(CXXFLAGS) -DSAMPLEDIR=\"`PKG_CONFIG_PATH=/home/martijn/Downloads/COIN/coin-Clp/lib64/pkgconfig:/home/martijn/Downloads/COIN/coin-Clp/lib/pkgconfig:/home/martijn/Downloads/COIN/coin-Clp/share/pkgconfig: pkg-config --variable=datadir coindatasample`\" `PKG_CONFIG_PATH=/home/martijn/Downloads/COIN/coin-Clp/lib64/pkgconfig:/home/martijn/Downloads/COIN/coin-Clp/lib/pkgconfig:/home/martijn/Downloads/COIN/coin-Clp/share/pkgconfig: pkg-config --cflags clp` -c -o main.o `test -f 'main.cpp' || echo './'`main.cpp
flexibility.o: flexibility.cpp
g++ $(CXXFLAGS) -DSAMPLEDIR=\"`PKG_CONFIG_PATH=/home/martijn/Downloads/COIN/coin-Clp/lib64/pkgconfig:/home/martijn/Downloads/COIN/coin-Clp/lib/pkgconfig:/home/martijn/Downloads/COIN/coin-Clp/share/pkgconfig: pkg-config --variable=datadir coindatasample`\" `PKG_CONFIG_PATH=/home/martijn/Downloads/COIN/coin-Clp/lib64/pkgconfig:/home/martijn/Downloads/COIN/coin-Clp/lib/pkgconfig:/home/martijn/Downloads/COIN/coin-Clp/share/pkgconfig: pkg-config --cflags clp` -c -o flexibility.o `test -f 'flexibility.cpp' || echo './'`flexibility.cpp
%.o: %.cpp
g++ -c $(CFLAGS) -o $# $<
lex.cpp: lex.l grammar.tab.cpp grammar.tab.hpp
flex -o$# $<
%.tab.cpp %.tab.hpp: %.ypp
bison --verbose -d $<
ifneq ($(LSOURCES),)
$(LSOURCES:.l=.cpp): $(YSOURCES:.y=.tab.h)
endif
-include $(OBJECTS:.o=.d)
clean:
rm -f $(OBJECTS) $(OBJECTS:.o=.d) $(YSOURCES:.ypp=.tab.cpp) $(YSOURCES:.ypp=.tab.hpp) $(YSOURCES:.ypp=.output) $(LSOURCES:.l=.cpp) solver solver.release 2>/dev/null
.PHONY: all clean debug release
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