This is my Makefile
```
1.output:main.o StackLinked.o
2.g++ main.o StackLinked.o
3.main.o:main.cpp config.h
4.g++ -c main.cpp StackLinked.cpp
5.StackLinked.o:StackLinked.cpp StackLinked.h Stack.h
6.g++ -c StackLinked.cpp
```
my output is just
g++ main.o StackLinked.o
Related
Is there a simple way to achieve the following with a simple suffix rule (or other way)?
SRC = a.c b.c c.c d.c e.c
ASM = a.s b.s c.s d.s e.s
$(ASM) : $(SRC)
gcc -S -O0 a.s a.c
gcc -S -O0 b.s b.c
...
gcc -S -O0 e.s e.c
You should probably split the target for every assembly output, something along the lines of (not tested):
SRC = a.c b.c c.c d.c e.c
ASM = $(SRC:.c=.s)
%.s: %.c
gcc -S -O0 $<
Considering that gcc -S x.c produces an x.s by default (see gcc(1)).
I'm trying to add function iceemdan() to the open source library libeemd.c. I'm trying to debug it with an IDE. The make file's first call to clang result's in clang's inability to find the gsl library, even though it is present and the make file upon which the IDE's make file is based has no trouble linking to gsl.
Here's the make file output (gsl errors and context only) using the Codelite IDE make file:
Executing Pre Build commands ...
Done
make[1]: Leaving directory '/Users/Common/iceemdan-dev/iceemdan-dev/iceemdan-clang'
make[1]: Entering directory '/Users/Common/iceemdan-dev/iceemdan-dev/iceemdan-clang'
clang -o ./Debug/iceemdan-clang #"iceemdan-clang.txt" -L.
Undefined symbols for architecture x86_64:
"_gsl_linalg_solve_tridiag", referenced from:
_emd_evaluate_spline in main.c.o
"_gsl_poly_dd_eval", referenced from:
_emd_evaluate_spline in main.c.o
"_gsl_poly_dd_init", referenced from:
_emd_evaluate_spline in main.c.o
"_gsl_ran_gaussian", referenced from:
_iceemdan in main.c.o
_eemd in main.c.o
_ceemdan in main.c.o
"_gsl_rng_alloc", referenced from:
_allocate_eemd_workspace in main.c.o
"_gsl_rng_free", referenced from:
_free_eemd_workspace in main.c.o
"_gsl_rng_mt19937", referenced from:
_allocate_eemd_workspace in main.c.o
"_gsl_rng_set", referenced from:
_set_rng_seed in main.c.o
"_gsl_set_error_handler_off", referenced from:
_iceemdan in main.c.o
_eemd in main.c.o
_ceemdan in main.c.o
_emd_evaluate_spline in main.c.o
"_gsl_sf_sin", referenced from:
_main in main.c.o
"_gsl_stats_sd", referenced from:
_iceemdan in main.c.o
_eemd in main.c.o
_ceemdan in main.c.o
"_gsl_strerror", referenced from:
_emd_evaluate_spline in main.c.o
"_gsl_vector_view_array", referenced from:
_emd_evaluate_spline in main.c.o
ld: symbol(s) not found for architecture x86_64
clang: error: linker command failed with exit code 1 (use -v to see invocation)
make[1]: *** [iceemdan-clang.mk:82: Debug/iceemdan-clang] Error 1
make[1]: Leaving directory '/Users/Common/iceemdan-dev/iceemdan-dev/iceemdan-clang'
make: *** [Makefile:5: All] Error 2
This make file, a modification of the package make file to run on the Mac, works:
.PHONY: all clean install uninstall
version := 1.4.1
gsl_flags := $(shell pkg-config --libs --cflags gsl)
ifeq ($(gsl_flags),)
$(error Failed to query GSL complilation flags from pkg-config)
endif
gsl_flags += -DHAVE_INLINE
commonflags := -Wall -Wextra -std=c99 -pedantic -Wno-unknown-pragmas -Wshadow -Wpointer-arith
commonflags += $(CFLAGS)
commonflags += -g -DEEMD_DEBUG=0
#commonflags += -fopenmp
commonflags += -DCLANG
PREFIX ?= /usr
SONAME = -soname
ifeq ($(shell uname -s),Darwin)
SONAME = -install_name
endif
define uninstall_msg
If you used $(PREFIX) as the prefix when running `make install`,
you can undo the install by removing these files:
$(PREFIX)/include/eemd.h
$(PREFIX)/lib/libeemd.a
$(PREFIX)/lib/libeemd.so
$(PREFIX)/lib/libeemd.so.$(version)
endef
export uninstall_msg
all: libeemd.so.$(version) libeemd.a eemd.h
clean:
rm -f libeemd.so libeemd.so.$(version) libeemd.a eemd.h obj/eemd.o
rm -rf obj
install:
install -d $(PREFIX)/include
install -d $(PREFIX)/lib
install -m644 eemd.h $(PREFIX)/include
install -m644 libeemd.a $(PREFIX)/lib
install libeemd.so.$(version) $(PREFIX)/lib
cp -Pf libeemd.so $(PREFIX)/lib
uninstall:
#echo "$$uninstall_msg"
obj:
mkdir -p obj
obj/eemd.o: src/eemd.c src/eemd.h | obj
clang $(commonflags) -c $< $(gsl_flags) -o $#
libeemd.a: obj/eemd.o
$(AR) rcs $# $^
libeemd.so.$(version): src/eemd.c src/eemd.h
clang $(commonflags) $< -fPIC -shared -Wl,$(SONAME),$# $(gsl_flags) -o $#
ln -sf $# libeemd.so
eemd.h: src/eemd.h
cp $< $#
The Codelite second level make file is here. (The first level merely calls it.) I'm running in a different directory to avoid overwriting my good code.
##
## Auto Generated makefile by CodeLite IDE
## any manual changes will be erased
##
## Debug
ProjectName :=iceemdan-clang
ConfigurationName :=Debug
WorkspacePath :=/Users/Common/iceemdan-dev/iceemdan-dev
ProjectPath :=/Users/Common/iceemdan-dev/iceemdan-dev/iceemdan-clang
IntermediateDirectory :=./Debug
OutDir := $(IntermediateDirectory)
CurrentFileName :=
CurrentFilePath :=
CurrentFileFullPath :=
User :=Coleman Family
Date :=08/08/2018
CodeLitePath :="/Users/Common/Library/Application Support/CodeLite"
LinkerName :=clang
SharedObjectLinkerName :=clang -shared -fPIC
ObjectSuffix :=.o
DependSuffix :=
PreprocessSuffix :=.o.i
DebugSwitch :=-gstab
IncludeSwitch :=-I
LibrarySwitch :=-l
OutputSwitch :=-o
LibraryPathSwitch :=-L
PreprocessorSwitch :=-D
SourceSwitch :=-c
OutputFile :=$(IntermediateDirectory)/$(ProjectName)
Preprocessors :=
ObjectSwitch :=-o
ArchiveOutputSwitch :=
PreprocessOnlySwitch :=-E
ObjectsFileList :="iceemdan-clang.txt"
PCHCompileFlags :=
MakeDirCommand :=mkdir -p
LinkOptions :=
IncludePath := $(IncludeSwitch). $(IncludeSwitch).
IncludePCH :=
RcIncludePath :=
Libs :=
ArLibs :=
LibPath := $(LibraryPathSwitch).
##
## Common variables
## AR, CXX, CC, AS, CXXFLAGS and CFLAGS can be overriden using an environment variables
##
AR := ar rcus
CXX := clang++
CC := clang
CXXFLAGS := -g -O0 -Wall $(Preprocessors)
CFLAGS := $(commonflags) $< -fPIC -shared -Wl $# $(gsl_flags) -o $# $(Preprocessors)
ASFLAGS :=
AS := llvm-as
##
## User defined environment variables
##
CodeLiteDir:=/Applications/codelite.app/Contents/SharedSupport/
PATH:=/Users/Common/usr/local/bin:/Library/Frameworks/Python.framework/Versions/2.7/bin:/Library/Frameworks/Python.framework/Versions/3.5/bin:/opt/local/bin:/opt/local/sbin:/Library/Frameworks/Python.framework/Versions/2.7/bin:/usr/local/bin:/usr/bin:/bin:/usr/sbin:/sbin:/opt/X11/bin:/Library/TeX/texbin:/opt/local/include
Srcs=main.c
Objects0=$(IntermediateDirectory)/main.c$(ObjectSuffix)
Objects=$(Objects0)
##
## Main Build Targets
##
.PHONY: all clean PreBuild PrePreBuild PostBuild MakeIntermediateDirs
all: $(OutputFile)
$(OutputFile): $(IntermediateDirectory)/.d $(Objects)
#$(MakeDirCommand) $(#D)
#echo "" > $(IntermediateDirectory)/.d
#echo $(Objects0) > $(ObjectsFileList)
$(LinkerName) $(OutputSwitch)$(OutputFile) #$(ObjectsFileList) $(LibPath) $(Libs) $(LinkOptions)
MakeIntermediateDirs:
#test -d ./Debug || $(MakeDirCommand) ./Debug
$(IntermediateDirectory)/.d:
#test -d ./Debug || $(MakeDirCommand) ./Debug
PreBuild:
#echo Executing Pre Build commands ...
$(eval gsl_flags = -L/opt/local/lib -lgsl -lgslcblas -lm -I/opt/local/include -DHAVE_INLINE)
$(eval commonflags := -Wall -Wextra -std=c99 -pedantic -Wno-unknown-pragmas -Wshadow -Wpointer-arith)
$(eval commonflags += $(CFLAGS))
$(eval commonflags += -g -DEEMD_DEBUG=0)
$(eval commonflags += -DCLANG)
$(eval PREFIX ?= /usr)
#echo Done
# all
Debug/main.c.o: main.c
#src/eemd.h | Debug
clang $(commonflags) -c $< $(gsl_flags) -o $#
Debug/main.c.a: Debug/main.c.o
$(AR) rcs $# $^
eemd: main.c src/eemd.h
clang $(commonflags) $< -fPIC -shared -Wl, ,$# $(gsl_flags) -o $#
My apologies for the length of this post. In the past, I've only run unmodified make files, not debug them. So, a lot of this is new and not transparent to me. I'd appreciate any help.
I had to trick the command for building main.c.o using global variables.
Compiling error
I am quite new to Fortran coding.
Currently, I have a makefile which has been previously used by original authors to compile the Fortran codes in Linux. However, I cannot understand what needs to be changed in the previous makefile to run it in Windows-based compiler Silverfrost FTN95.
While trying to compile in FTN95 I encountered the following error:
C:\Users\Geo-TGS\Documents\landslidemodel\src\TRIGRS>MAKE TPX
mpif90 -w -O3 -w -O3 -c ssizgrd.f95
process_begin: CreateProcess(NULL, mpif90 -w -O3 -w -O3 -c ssizgrd.f95, ...) failed.
make (e=2): The system cannot find the file specified.
makefile:59: recipe for target `ssizgrd.o' failed
MAKE: *** [ssizgrd.o] Error 2
C:\Users\Geo-TGS\Documents\landslidemodel\src\TRIGRS>make trg
mpif90 -w -O3 -w -O3 -c grids.f95
process_begin: CreateProcess(NULL, mpif90 -w -O3 -w -O3 -c grids.f95, ...) failed.
make (e=2): The system cannot find the file specified.
makefile:59: recipe for target `grids.o' failed
make: *** [grids.o] Error 2
Below is the Makefile code:
TRG = trg
PRG = prg
TPX = tpx
OBJT90 = trigrs.o flux.o prpijz.o svxmdv.o svijz.o dzero_brac.o
OBJT95 = grids.o input_vars.o model_vars.o dsimps.o input_file_defs.o iverson.o pstpi.o satfin.o savage.o steady.o trini.o unsinf.o ivestp.o pstpf.o rnoff.o satinf.o smallt.o svgstp.o unsfin.o unsth.o ssizgrd.o svlist.o
OBJT77 = calerf.o dbsct.o derfc.o irdgrd.o irdswm.o isvgrd.o roots.o srdgrd.o srdswm.o ssvgrd.o
OBJP90 = trigrs_p.o partial_p.o flux.o flux_p.o prpijz.o svxmdv.o svijz.o dzero_brac.o srdgrd_p.o irdgrd_p.o
OBJP95 = modules_p.o grids.o input_vars.o model_vars.o dsimps.o input_file_defs.o iverson.o pstpi.o pstpi_p.o satfin.o satfin_p.o savage.o steady.o trini.o trini_p.o unsinf.o unsinf_p.o ivestp.o ivestp_p.o pstpf.o pstpf_p.o rnoff.o satinf.o satinf_p.o smallt.o svgstp.o svgstp_p.o unsfin.o unsfin_p.o unsth.o unsth_p.o ssizgrd.o ssizgrd_p.o svlist.o rnoff_p.o steady_p.o
OBJP77 = calerf.o dbsct.o derfc.o irdgrd.o irdswm.o irdswm_p.o isvgrd.o roots.o srdgrd.o srdswm.o srdswm_p.o ssvgrd.o
OBJX90 = tpindx.o nxtcel.o
OBJX95 = ssizgrd.o
OBJX77 = isvgrd.o mpfldr.o rdflodir.o sindex.o slofac.o srdgrd1.o
LIBS =
CC = gcc -O3
CCFLAGS = -lgsl -lgslcblas -lm
FC = ftn95 -w -O3
FFLAGS =
F90 = f95 -w -O3
MPIF90 = mpif90 -w -O3
F90FLAGS = -w -O3
LDFLAGS = -w -O3
all: $(TRG) $(PRG)
#-----------------------------------------------------------------
$(TRG): $(OBJT95) $(OBJT90) $(OBJT77)
$(F90) $(CCLIBS) $(LDFLAGS) -o $# $(OBJT95) $(OBJT90) $(OBJT77) $(CCFLAGS) $(LIBS)
$(PRG): $(OBJP95) $(OBJP90) $(OBJP77)
$(MPIF90) $(CCLIBS) $(LDFLAGS) -o $# $(OBJP95) $(OBJP90) $(OBJP77)
$(CCFLAGS) $(LIBS)
$(TPX): $(OBJX95) $(OBJX90) $(OBJX77)
$(F90) $(CCLIBS) $(LDFLAGS) -o $# $(OBJX95) $(OBJX90) $(OBJX77) $(CCFLAGS) $(LIBS)
#-----------------------------------------------------------------
clean:
rm -f $(TRG) $(TPX) $(PRG)
rm -rf $(OBJT95) $(OBJT90) $(OBJT77) $(OBJP95) $(OBJP90) $(OBJP77)
rm -rf $(OBJX95) $(OBJX90) $(OBJX77)
rm -rf *.mod *.exe *.stackdump
.SUFFIXES: $(SUFFIXES) .f90 .f .c .f95
.f90.o:
$(MPIF90) $(F90FLAGS) -c $<
.f.o:
$(MPIF90) $(F90FLAGS) -c $<
.c.o:
$(CC) $(CCINCLUDE) -c -w $<
.f95.o:
$(MPIF90) $(F90FLAGS) -c $<
What changes need to be made for the code to compile?
This is my makefile:
OBJECTS = main.o
CFLAGS = -g -wall
NAME = make
CC = gcc
build: $(OBJECTS)
$(CC) $(CFLAGS) $(OBJECTS) -o $(NAME)
I'm getting below error when I tried to make(Applied tab before gcc command) :
makefile:6: *** missing separator. Stop.
How can I fix this?
First of all, it looks like you have spaces instead of tab.
As for the Makefile itself, I'd make it little bit simpler. For a source file main.c:
int main() {
return 0;
}
I would go with Makefile:
CFLAGS = -g -wall
CC = gcc
main: main.c
$(CC) $(CFLAGS) $< -o $#
I have the following make file:
CC = gcc
CCDEPMODE = depmode=gcc3
CFLAGS = -g -O2 -W -Wall -Wno-unused -Wno-multichar
COMPONENTHEADER = Q_OBJECT
CPP = gcc -E
CPPFLAGS = -I/usr/include/Inventor/annex -D_REENTRANT -I/usr/share/qt3/include
CXX = g++
CXXCPP = g++ -E
CXXDEPMODE = depmode=gcc3
CXXFLAGS = -g -O2 -fno-exceptions -W -Wall -Wno-unused -Wno-multichar -Woverloaded- virtual
CYGPATH_W = echo
GUI = QT
Gui = Qt
INCLUDES =
LIBS = -lSoQt -lqt-mt -lXmu -lXi -lCoin -lGL -lXext -lSM -lICE -lX11 -ldl -lpthread -lm -lcxcore -lcv -lhighgui -lcvaux
OBJS = MathTools.o PointCloud.o ExtractFeatures.o Tile.o Shape.o RoadDynamic.o
SRCS = MathTools.cpp PointCloud.cpp ExtractFeatures.cpp Tile.cpp Shape.cpp RoadDynamic.cpp main.cpp
HDRS = constants.h Shape.h MathTools.h PointCloud.h ExtractFeatures.h Tile.h RoadDynamic.h
WIDGET = QWidget *
all: main
main: main.o ${OBJS}
${CC} ${CFLAGS} ${INCLUDES} -o $# main.o ${OBJS} ${LIBS}
.c.o:
${CC} ${CFLAGS} ${INCLUDES} -c $<
depend:
makedepend ${SRCS}
clean:
rm *.o core *~
tar:
tar cf code.tar Makefile *.c *.h testfile1
print:
more Makefile $(HDRS) $(SRCS) | enscript -2r -p listing.ps
I am wondering why when I run make the output is
g++ -g -O2 -fno-exceptions -W -Wall -Wno-unused -Wno-multichar -Woverloaded-virtual -I/usr/include/Inventor/annex -D_REENTRANT -I/usr/share/qt4/include -c -o main.o main.cpp
instead of:
gcc -g -O2 -W -Wall -Wno-unused -Wno-multichar ...
it seems the cxx variables are overriding the cc variables. Why is that?
also what does the "include =" do in this case? It doesn't seem to be set to anything.
Thank you
Because your object files are apparently built from .cpp files. You have no explicit rule for building .o files from .cpp files, so Make uses the implicit rule $(CXX) $(CPPFLAGS) $(CXXFLAGS) -c.