polewgo.blogg.se

Xinu + write makefile for c program
Xinu + write makefile for c program








PHONY : clean clean : rm -f $(OBJFILES) $(OUT) Re-assign CC to g++ (or to $CXX) so the C++ compiler is used for linking.Īdd -lstdc++ to your LDLIBS in order to add the C++ standard library to the linking process.Īn example Makefile for a C++ project may look like this, if you go with the option of adding the C++ standard library to the list of linked libraries:ĬPPFILES = $( wildcard *.cpp ) OBJFILES = $(CPPFILES.cpp=.o) OUT = mainĬFLAGS = -Wall LDLIBS = -lstdc++ -lm $(OUT) : $(OBJFILES). The result is that the C++ standard library is not available.

xinu + write makefile for c program

So, the implicit rule for linking still uses CC as the linker. o file, there’s no indication from the file extension that it came from a C++ file. This is analogous to the CC variable.įlags are passed using the CCXFLAGS variable, instead of CFLAGS. The compiler used for C++ files is set using CXX, which defaults to g++. C files (all extensions recognized by GNU Make as C++ files) into. (Note: you can also omit the definition of the CC variable, as the cc executable should point to the system-default compiler anyway.) Building C++ projectsĬompiling C++ files works similarly to compiling C files. LDLIBS = -ldependency1 -ldependency2 $(OUT) : $(OBJFILES).

xinu + write makefile for c program

CFILES = $( wildcard *.c ) OBJFILES = $(CFILES.c=.o) OUT = mainĬFLAGS = -Wall -I /additional/include/dir










Xinu + write makefile for c program