man gcc
-L = Path to libraries I find it a bit odd that you have to point the compiler to the includes, in the first place, though, and believe there's some- thing wrong with your installation. Cheers, Tink |
I found an option that works.
gcc file.cpp -lstdc++ What does that mean? |
That means that you're using the C compiler
instead of the C++ one and tell it to link against the stdc++ library :} Cheers, Tink |
?? Sorry but I am a little confused here. Do you mean you use the gcc to compile the code containing "cout<<....<<...."?
This error is also weird to me, since the code compiles well on my computer. I think probably you accidentally modified some settings of the system library or include file. like /etc/ld.so.conf Qu Chen |
I just installed Linux a week ago. I have not modified anything really. I just looked at that file, they are not where ALL of my libraries are. Should I add them?
|
THAT WAS IT! After I added where the includes lived (/usr/..../g++) the file compiled with out the -lstdc++ option (that is really lazy of me! I spend two days looking for a way not to type in eight characters every time I compile :) )
Thanks for all of your help guys |
Quote:
|
I'm having a similar problem but not having any luck. I'm trying to compile the "helloworld.cpp" program and getting the following error:
helloworld.cpp: In function `int main()': helloworld.cpp:5: `cout' undeclared (first use this function) helloworld.cpp:5: (Each undeclared identifier is reported only once for each function it appears in.) helloworld.cpp:5: `endl' undeclared (first use this function) The code is: #include <iostream> int main() { cout<<"Hello World!"<<endl; return 0; } I tried the solutions that you guys tried (including 'gcc file.cpp -lstdc++) but they didn't work. I think my C++ libraries are in /usr/include/c++/3.2. The iostream lib is there. Any thoughts? Thanks. |
either prefix cout and endl with std:: or add the line
using namespace std; before main |
Thanks Kev! The 'using namespace std;' worked. But tell me, why do you have to use that? Why is it not enough to use g++ and c++ libraries? Thanks again.
|
Because namespaces make sense,
and the new standard requires either adding the namespace to the function, or the "using namespace std" at the beginning. The latter (even though more convenient) is considered worse style. Cheers, Tink |
EDIT Will someone who can plz delete this, silly me didn't see the part about prefixing std:: before cout, etc. That fixed it. But still, why is the std:: part necessary, i have used gcc before and it didn't require this. /EDIT
i have had the same problem, i use g++ 3.2.3. the headers are Code:
#include <iostream> |
Quote:
Lyle |
All times are GMT -5. The time now is 06:23 PM. |