Discussion:
gcc makefile hello world (linking iostream)
blessman11
2012-06-21 15:14:05 UTC
Permalink
hi

I'm trying to code hello world in GCC, but whilst I get my simple makefile
correctly, the problem comes when I try to use <iostream> or even my own
headerfiles defined outside the folder with my main .cpp file.

so any help?

How should I alter the makefile below to accommodate <iostream> or any
header files out side my main.cpp file folder?
[output]all: hello
-std=c++11

objects = hello.o

edit: $(objects)
cc -o edit $(objects)

$(objects) : hello.h
hello.o : hello.h

.PHONY : clean
clean :
-rm edit $(objects)[/output]
--
View this message in context: http://old.nabble.com/gcc-makefile-hello-world-%28linking-iostream%29-tp34049219p34049219.html
Sent from the gcc - Help mailing list archive at Nabble.com.
Armin K.
2012-06-21 15:46:01 UTC
Permalink
Post by blessman11
hi
I'm trying to code hello world in GCC, but whilst I get my simple makefile
correctly, the problem comes when I try to use <iostream> or even my own
headerfiles defined outside the folder with my main .cpp file.
so any help?
How should I alter the makefile below to accommodate <iostream> or any
header files out side my main.cpp file folder?
[output]all: hello
-std=c++11
objects = hello.o
edit: $(objects)
cc -o edit $(objects)
$(objects) : hello.h
hello.o : hello.h
.PHONY : clean
-rm edit $(objects)[/output]
iostream and .cpp look like C++ to me, but you are trying to use C
compiler. You need to use g++ or c++ instead of cc in the edit ...

I don't know if something is wrong with my client or mailing list, but
how is it possible to automatically set reply address to gcc-help
address instead of sender one?
Jonathan Wakely
2012-06-21 17:45:02 UTC
Permalink
I don't know if something is wrong with my client or mailing list, but how
is it possible to automatically set reply address to gcc-help address
instead of sender one?
You'll need to set that in your mail client.
Jonathan Wakely
2012-06-21 17:43:59 UTC
Permalink
Post by blessman11
hi
I'm trying to code hello world in GCC, but whilst I get my simple makefile
correctly, the problem comes when I try to use <iostream> or even my own
headerfiles defined outside the folder with my main .cpp file.
so any help?
I already answered this question, read my entire reply:

http://gcc.gnu.org/ml/libstdc++/2012-06/msg00068.html
blessman11
2012-06-25 14:23:45 UTC
Permalink
Post by Jonathan Wakely
Post by blessman11
hi
I'm trying to code hello world in GCC, but whilst I get my simple makefile
correctly, the problem comes when I try to use <iostream> or even my own
headerfiles defined outside the folder with my main .cpp file.
so any help?
http://gcc.gnu.org/ml/libstdc++/2012-06/msg00068.html
I thought I had been posting in this thread instead, my bad. But why is it
throwing up errors like that, how can I make my code stop linking with "gcc"
instead of "g++". What else do I have to do beyond what I did?

[output]all: hello
-std=c++11

objects = hello.o

edit: $(objects)
g++ -o edit $(objects)
[/output]
--
View this message in context: http://old.nabble.com/gcc-makefile-hello-world-%28linking-iostream%29-tp34049219p34066873.html
Sent from the gcc - Help mailing list archive at Nabble.com.
Jonathan Wakely
2012-06-25 15:06:23 UTC
Permalink
Post by blessman11
Post by Jonathan Wakely
Post by blessman11
hi
I'm trying to code hello world in GCC, but whilst I get my simple makefile
correctly, the problem comes when I try to use <iostream> or even my own
headerfiles defined outside the folder with my main .cpp file.
so any help?
http://gcc.gnu.org/ml/libstdc++/2012-06/msg00068.html
I thought I had been posting in this thread instead, my bad. But why is it
throwing up errors like that, how can I make my code stop linking with "gcc"
instead of "g++". What else do I have to do beyond what I did?
[output]all: hello
       -std=c++11
 objects = hello.o
 edit: $(objects)
       g++ -o edit $(objects)
 [/output]
You haven't defined a rule for building "hello" so it uses the
implicit rule to link "hello.o" into hello, which is:

$(CC) $(LDFLAGS) hello.o $(LOADLIBES) $(LDLIBS) -o hello

CC is the C compiler, not the C++ compiler, so it doesn't link the C++
runtime libraries.

Your makefile has a rule to build "edit" but you seem to want a target
called "hello" -- why is your rule building "edit" instead? It will
work if you just change "edit" to "hello" or vice versa.

Also, your rule for "all" is invalid, "-std=c++0x" is not a valid
rule, I don't know what you meant that to be.

Loading...