g++ and make

D

Daniel

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
 
D

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.

Of course, very stupid of me, thanks

Daniel
 
J

Jacek Dziedzic

Daniel said:
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.
 

Ask a Question

Want to reply to this thread or ask your own question?

You'll need to choose a username for the site, which only take a couple of moments. After that, you can post your question and our members will help you out.

Ask a Question

Members online

No members online now.

Forum statistics

Threads
474,431
Messages
2,571,679
Members
48,796
Latest member
Greg L.

Latest Threads

Top