Thread: #includes don't seem to be working

  1. #1

    #includes don't seem to be working

    I have managed to get my compiler not to complain, but now when i compile it, the LINKER complains at me. IT doesn't seem to recognize perfectly normal function calls, and things like cout<< and cin>>

    here are the most recent linker errors:
    Code:
    c:\c++\rpg\engine.o(.text+0x45):engine.cpp: undefined reference to `cout'
    c:\c++\rpg\engine.o(.text+0x4a):engine.cpp: undefined reference to `ostream::operator<<(char const *)'
    c:\c++\rpg\engine.o(.text+0x53):engine.cpp: undefined reference to `ostream::operator<<(char const *)'
    c:\c++\rpg\engine.o(.text+0x5c):engine.cpp: undefined reference to `ostream::operator<<(int)'
    c:\c++\rpg\engine.o(.text+0x65):engine.cpp: undefined reference to `ostream::operator<<(char const *)'
    c:\c++\rpg\engine.o(.text+0x6e):engine.cpp: undefined reference to `ostream::operator<<(int)'
    c:\c++\rpg\engine.o(.text+0x7a):engine.cpp: undefined reference to `endl(ostream &)'
    c:\c++\rpg\engine.o(.text+0x9e):engine.cpp: undefined reference to `cout'
    c:\c++\rpg\engine.o(.text+0xa3):engine.cpp: undefined reference to `ostream::operator<<(char const *)'
    c:\c++\rpg\engine.o(.text+0xac):engine.cpp: undefined reference to `ostream::operator<<(int)'
    c:\c++\rpg\engine.o(.text+0xb5):engine.cpp: undefined reference to `ostream::operator<<(char const *)'
    ..... ...... ......

  2. #2
    Used Registerer jdinger's Avatar
    Join Date
    Feb 2002
    Posts
    1,065
    Below your #includes do you have:
    Code:
    using namespace std;
    And are you using the new headers (ie: no ".h")
    Code:
    #include <string>
    not
    #include <string.h>

  3. #3
    It is hard to type now because i am woozy from hittimg my head on the wall... No, i don't have namespace there, but i should because i got into that habit long ago.....

    But i do forget, what does namespace do?
    Compilers:
    GCC on Red Hat 8.1 (Primary)
    GCC on Mac OS X 10.2.4 (Secondary)

    Others:
    MinGW on XP

  4. #4
    shoot
    still doesn't work.

    Here is the #includes part of the code:

    Code:
    #include <iostream>
    #include <cstdio>
    #include <cstdlib>
    #include <conio.h>
    #include <stdlib.h>
    #include <time.h>
    
    #include "mainHeader.h"
    #include "creatures.h"
    #include "storyline.h"
    #include "scenario.h"
    #include "players.h"
    using namespace std;
    Compilers:
    GCC on Red Hat 8.1 (Primary)
    GCC on Mac OS X 10.2.4 (Secondary)

    Others:
    MinGW on XP

  5. #5
    Used Registerer jdinger's Avatar
    Join Date
    Feb 2002
    Posts
    1,065
    I've never used
    Code:
    #include <cstdio>
    #include <cstdlib>
    #include <stdlib.h>
    those header files (at least not together), but if I had to guess cstdio may have identically named but differently implemented objects shared in iostream (same with cstdlib/stdlib.h).

    Here is what I use (basic cout example):
    Code:
    #include <iostream>
    using namespace std;
    
    int main()
    {
       cout<<"hello world!\n";
       return(0);
    }
    What functions/data types are you using that require all four of those individual headers? If I had to guess I'd say you could probably get away with on iostream and stdlib.h.

  6. #6

    what is printf and getche in?

    <see title>
    Compilers:
    GCC on Red Hat 8.1 (Primary)
    GCC on Mac OS X 10.2.4 (Secondary)

    Others:
    MinGW on XP

  7. #7
    Used Registerer jdinger's Avatar
    Join Date
    Feb 2002
    Posts
    1,065
    printf() is in stdio.h
    getch() is in conio.h (non-standard, but if you're using Bloodshed then you should be ok).

  8. #8
    Registered User
    Join Date
    Apr 2002
    Posts
    362
    In addition to the assistance you've already gotten, you may want to comment out either #include <cstdlib> or #include <stdlib.h> and see if that doesn't make a difference.

    The reason is that the new C Standard changed <stdlib.h> to <cstdlib> as it did with <stdio.h> (<cstdio>).

    Rather like incuding <iostream.h> and <iostream>. Is there a difference? I understand that, in some cases, there are differences between some of the old header files and their new standard counterparts. Nothing major, of course, but why chance it?

    -Skipper
    "When the only tool you own is a hammer, every problem begins to resemble a nail." Abraham Maslow

  9. #9
    still not working

    i get exactly the same errors
    Compilers:
    GCC on Red Hat 8.1 (Primary)
    GCC on Mac OS X 10.2.4 (Secondary)

    Others:
    MinGW on XP

  10. #10
    Registered User toaster's Avatar
    Join Date
    Apr 2002
    Posts
    161
    I don't use Dev-C++ so I'm just taking random shots at it.

    things to check on:

    is there a customize option?
    maybe you can configure your linker or compiler there or by manual such as in Borland compilers.
    go check the Dev-C++ documentation(s), if it should include any or check the site or send those guys a question.
    if there is a linker configuration, maybe you can turn down the " linker sensitivity " a little bit.

    are all the header directories existant?

    is your iostream.h file corrupt or modified in any way?

    that's all I can think of right now.
    think only with code.
    write only with source.

  11. #11
    Registered User
    Join Date
    Apr 2002
    Posts
    362
    Going along with toaster's random shots, now.

    For kicks, try changing this:
    Code:
    #include <iostream>
    #include <cstdio>
    #include <cstdlib>
    #include <conio.h>
    #include <stdlib.h>
    #include <time.h>
    
    #include "mainHeader.h"
    #include "creatures.h"
    #include "storyline.h"
    #include "scenario.h"
    #include "players.h"
    using namespace std;
    to this:
    Code:
    #include <iostream>
    #include <cstdio>
    #include <cstdlib>
    #include <conio.h>
    #include <stdlib.h>
    #include <time.h>
    using namespace std;
    
    #include "mainHeader.h"
    #include "creatures.h"
    #include "storyline.h"
    #include "scenario.h"
    #include "players.h"
    My logic in this suggestion, weak though it may be, is that your compiler may be throwing errors based on the inclusion of your own header files prior to namespace std being "invoked".

    Much the same as what occurs in this code:
    Code:
    #include <iostream>
    #include <conio.h>
    
    int main()
    {
    x += 2;
    int x = 0;
    
    std::cout << x;
    
    getch();
    return 0;
    }
    While x is declared/defined in the code, it's not until after we attempt to operate on it. An error is given saying that we have an "Undefined symbol 'x' ". The beauty of a one-pass compiler.

    Personally, I try to exhaust potential flaws in my own logic before blaming the compiler though I'm not using Dev-C++, and I'm not familiar with it.

    -Skipper
    "When the only tool you own is a hammer, every problem begins to resemble a nail." Abraham Maslow

  12. #12
    still no
    Compilers:
    GCC on Red Hat 8.1 (Primary)
    GCC on Mac OS X 10.2.4 (Secondary)

    Others:
    MinGW on XP

  13. #13
    Registered User toaster's Avatar
    Join Date
    Apr 2002
    Posts
    161
    um, what version is your Dev-C++ ?
    think only with code.
    write only with source.

Popular pages Recent additions subscribe to a feed

Similar Threads

  1. Makefile and includes
    By Lang in forum C Programming
    Replies: 4
    Last Post: 03-18-2008, 03:29 AM
  2. Working on simple Engine
    By bladerunner627 in forum Game Programming
    Replies: 16
    Last Post: 05-25-2005, 11:27 AM
  3. Trying to eject D drive using code, but not working... :(
    By snowfrog in forum C++ Programming
    Replies: 3
    Last Post: 05-07-2005, 07:47 PM
  4. Circular includes
    By ventolin in forum C++ Programming
    Replies: 2
    Last Post: 05-23-2004, 05:43 PM
  5. cygwin -> unix , my code not working properly ;(
    By CyC|OpS in forum C Programming
    Replies: 4
    Last Post: 05-18-2002, 04:08 AM