Menu

Compiler not noticing libraries

jassin
2003-06-23
2012-09-26
  • jassin

    jassin - 2003-06-23

    I have been working on a small tutorial and I am having problems trying to compile the code, he is the code short and sweet.

    #include <iostream>
    #include <stdlib.h>

    int main(int argc, char *argv[])
    {
      cout << "Hello, I am your computer talking." << endl;
      system("PAUSE");
      return 0;
    }

    When I compile this code it gives the error:

    'cout' undeclared (first use this function)
    'endl' undeclared (first use this function)

    Why us the compiler not noticing the libraries?

     
    • Wayne Keen

      Wayne Keen - 2003-06-23

      Actually the problem has nothing whatsoever to do with libraries.  Your program is half pre-standard code and half post standard (which is half better than some)

      When the standard header notation came in (iostream rather than iostream,h), so did the use of namespaces. Sooo, you have a couple of options to fix your code.  The easiest is to add

      using namespace std;

      below your last include. One other option is to qualify your function names, i.e.

      std::cout

      Now, let me make one other observation..no, make that two.

      (1) When you are having an issue of this sort always report the exact version number of Dev you are using.  And always post your *complete* compile log, not just the errors.  This last is important as it enables the folks helping you to see where you have Dev installed, how the compiler was called, what all is in the path etc, a lot of infomration that we do not have to ask for later...

      (2) When you say "Why us the compiler not noticing the libraries?", the statement contains a bias saying that the compiler is somehow screwing up.  In this case, it is not, you are, there is an error in your code.  There is nothing wrong with making mistakes, I make more than most myself.  But it is almost never a healthy attitude to look at an error and say "whats wrong with this compiler?", because 99% of the time (at least for me) its your error and it can adversely affect the attitude of those who you are asking for help.

      (3) OK, I lied, 3 things...this is really not the best forum for posting questions of this type, this forum is for the developers (I am not smart enough to be one)....you will get more and better help for C++ language questions on the Bloodshed forum

      Wayne

      p.s. Note you can get an error of this kins if you name your code something.c, this leads the compiler to compile it as a C program...another reason to include your full log

       
    • Wayne Keen

      Wayne Keen - 2003-06-23

      Here is the corrected code:

      #include <iostream>
      #include <stdlib.h>
      using namespace std;

      int main(int argc, char *argv[])
      {
      cout << "Hello, I am your computer talking." << endl;
      system("PAUSE");
      return 0;
      }

      (Big change right?)

      Here is my full compile log:

      Compiler: Default compiler
      Executing  g++.exe...
      g++.exe "C:\Documents and Settings\Administrator\My Documents\testit3.cpp" -o "C:\Documents and Settings\Administrator\My Documents\testit3.exe"   -O0  -I"C:\Dev-Cpp\include\c++"  -I"C:\Dev-Cpp\include\c++\mingw32"  -I"C:\Dev-Cpp\include\c++\backward"  -I"C:\Dev-Cpp\include"   -L"C:\Dev-Cpp\lib"
      Execution terminated
      Compilation successful

      I am running Dev 4.9.8.0 on Win2000

      Wayne

       

Log in to post a comment.

Want the latest updates on software, tech news, and AI?
Get latest updates about software, tech news, and AI from SourceForge directly in your inbox once a month.