By using this site, you agree to our updated Privacy Policy and our Terms of Use. Manage your Cookies Settings.
445,820 Members | 1,189 Online
Bytes IT Community
+ Ask a Question
Need help? Post your question and get tips & solutions from a community of 445,820 IT Pros & Developers. It's quick & easy.

g++ and make

P: n/a
This might be a little bit off group but I wanted to learn to work with
make in linux so I write this makefile

main: main.cpp ./EscribeHolaMundo.cpp ./EscribeHolaMundo.H
g++ -I. main.cpp ./EscribeHolaMundo.cpp -o main

with

EscribeHolaMundo.cpp

#include <iostream>

void EscribeHolaMundo() {
cout << "Hola Mundo";
}

and

main.cpp

#include <EscribeHolaMundo.H>

int main(int argc, char *argv[]) {
EscribeHolaMundo();
}

now, with this, make doesn't recognize cout

../EscribeHolaMundo.cpp:4: error: `cout' undeclared (first use this
function)

but if I use the old c sintaxis with <iostream.h>, then g++ produces
its warning about the deprecated headers but works. Can somebody tell
me why it doesn't work with <iostream>?

Daniel

Sep 25 '06 #1
Share this Question
Share on Google+
2 Replies


P: n/a
Daniel wrote:
This might be a little bit off group but I wanted to learn to work with
make in linux so I write this makefile

main: main.cpp ./EscribeHolaMundo.cpp ./EscribeHolaMundo.H
g++ -I. main.cpp ./EscribeHolaMundo.cpp -o main

with

EscribeHolaMundo.cpp

#include <iostream>

void EscribeHolaMundo() {
cout << "Hola Mundo";
}

and

main.cpp

#include <EscribeHolaMundo.H>

int main(int argc, char *argv[]) {
EscribeHolaMundo();
}

now, with this, make doesn't recognize cout

./EscribeHolaMundo.cpp:4: error: `cout' undeclared (first use this
function)

but if I use the old c sintaxis with <iostream.h>, then g++ produces
its warning about the deprecated headers but works. Can somebody tell
me why it doesn't work with <iostream>?

Daniel
This has nothing to do with makefiles (neither does this
group). You forgot to write

using namespace std;

after your #include<iostream>

The issue is that the new header files (ones without the .h)
declare symbols in the std namespace, whereas the old ones
(with the .h), which you should avoid, declare the symbols
globally.

HTH,
- J.
Sep 25 '06 #2

P: n/a
>
This has nothing to do with makefiles (neither does this
group). You forgot to write

using namespace std;

after your #include<iostream>

The issue is that the new header files (ones without the .h)
declare symbols in the std namespace, whereas the old ones
(with the .h), which you should avoid, declare the symbols
globally.

HTH,
- J.
Of course, very stupid of me, thanks

Daniel

Sep 25 '06 #3

This discussion thread is closed

Replies have been disabled for this discussion.