trouble with makefile

Hi,

I'm having a bit of trouble making a makefile. So I was wondering if someone can point out what I'm doing wrong...

This happens when I try to compile on my school server... It works fine in visual studio

I'm getting this error:
1
2
3
4
5
6
In file included from /usr/lib/gcc/x86_64-redhat-linux/4.4.7/../../../../include/c++/4.4.7/array:35,
                 from main.cpp:11:

gcc/x86_64-redhat-linux/4.4.7/../../../../include/c++/4.4.7/c++0x_warning.h:31:2: error: 
#error This file requires compiler and library support for the upcoming ISO C++ standard, C++0x. 
This support is currently experimental, and must be enabled with the -std=c++0x or -std=gnu++0x compiler options.


This is my makefile:
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
PROGS := main average summation
CXX = g++
CFLAGS = -std=c++0x
CFLAGS = -Wall
CFLAGS += -g

OBJECTS = average.o summation.o main.o
SOURCES = average.cpp summation.cpp main.cpp 
HEADERS = average.h summation.h


all: ${PROGS}

main: ${OBJECTS}
	${CXX} ${CFLAGS} ${OBJECTS} -o main

average.o: average.cpp average.h
	${CXX} ${CFLAGS} -c average.cpp

summation.o: summation.cpp summation.h
	${CXX} ${CFLAGS} -c summation.cpp

clean:
	rm -f ${PROGS} *.o *~
Last edited on
It sounds like your school server g++/gcc compiler is older and prompting you with "experimental" flags being called. If you are not using any of the new language features http://www.codeproject.com/Articles/71540/Explicating-the-new-C-standard-C-x-and-its-implem just use your schools version of g++ for your compiler flags instead.
3
4
CFLAGS += -std=c++0x
CFLAGS += -Wall


Also, your school is using an outdated version of GCC. Ask them to upgrade it.

Hope this helps.
I don't know what happened, but that error is gone... Now I get something like:
1
2
3
g++ -std=c++0x -g -Wall -c main.o
g++: main.o: No such file or directory
g++: no input files


My current makefile:
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
PROGS := main average summation
CXX = g++
CXXFLAGS = -std=c++0x
CXXFLAGS += -g
CXXFLAGS += -Wall

OBJECTS = main.o average.o summation.o 
SOURCES = main.cpp average.cpp summation.cpp 
HEADERS = average.h summation.h


all: ${PROGS}

main: ${OBJECTS} ${HEADERS}
	${CXX} ${OBJECTS} -o main

${OBJECTS}: ${SOURCES}
	${CXX} ${CXXFLAGS} -c $(@: .o=.cpp)

clean:
	rm -f ${PROGS} *.o *~


Shouldn't the line ${OBJECTS}... create the object files?

edit: seems like school server doesn't like -std=c++0x, because if I remove it, the makefile works
Last edited on
Heh, I didn't look closely enough at your makefile.

There are a number of errors you are making. But I have to ask, specifically, are you trying to build three distinct programs with a single makefile? (Don't do that!)

Undaunted, here's a fairly simple makefile to help out, using implicit rules.

1
2
3
4
5
6
7
8
9
10
11
12
13
14
PROGS     = main average summation
CXX       = g++
CXXFLAGS += -std=c++0x
CXXFLAGS += -g
CXXFLAGS += -Wall -pedantic

all: $(PROGS)

%: %.cpp %.h
	$(CXX) $< $(CXXFLAGS) -o $@

.PHONY: clean
clean:
	rm -f $(PROGS)

You can use it easily:
% gmake average
g++ -std=c++0x -g -Wall -pedantic    average.cpp   -o average

% gmake
g++ -std=c++0x -g -Wall -pedantic    main.cpp   -o main
g++ -std=c++0x -g -Wall -pedantic    summation.cpp   -o summation
Note, you poor saps using Windows will also see average recompiled -- because gmake does not equate "average" with "average.exe". You'll need either a separate makefile or to add some messy conditionals to the file above to get it to not do that -- probably not worth your time for homework. And remember, this is a hack anyway because each makefile really should only be compiling one project.

Hope this helps.
Topic archived. No new replies allowed.