Thread: "undefined reference" to functions I have certainly included

  1. #1
    Registered User
    Join Date
    Apr 2003
    Posts
    3

    "undefined reference" to functions I have certainly included

    I am writing a program in C that needs to use colored text (DOS-type, 16 colors). I decided to use the color functions in conio.h because it seemed easiest and had everything I needed, but the compiler reports undefined references to the functions at the lines they are used, but I did include conio.h at the beginning of the file and with proper notation. I am also sure that I spelled the function correctly and used the correct parameters.
    What is the problem here?
    Thanks

  2. #2
    ---
    Join Date
    May 2004
    Posts
    1,379
    conio.h is not a standard header file so the functions you may think are there probably aren't. An example being the Borland version of conio.h is different to the gcc version.

  3. #3
    Registered User
    Join Date
    Apr 2003
    Posts
    3
    I did not know that, but coincidentally, the way I determined which header file to use and what parameters and specifics to use was by searching through the header files. If the header file does have the function in it, is there another possible problem I could fix?

  4. #4
    Registered User
    Join Date
    Aug 2001
    Posts
    244
    in header files you usually only find the DECLARATIONS of functions.
    you must specify the LIBRARY that contains the DEFINITIONS of the funtions.

    (declaration = function name and type, definition = actual code)
    like:

    Code:
    void my_func(); // declaration
    
    void my_func()
    { // definition
    
    }
    so there is probably some conio.lib or something.


    edit:
    also: unresolved references are detected in the LINKING phase (if you get to that phase it means that your code compiled just fine)
    - that is when all DECLARED symbols are being resolved.
    whenever there is a "unresolved reference" it means that something was declared but never defined.
    Last edited by Raven Arkadon; 12-11-2005 at 07:43 PM.
    signature under construction

  5. #5
    ATH0 quzah's Avatar
    Join Date
    Oct 2001
    Posts
    14,826
    Well it would actually help a bit if you said what compiler and OS you're using. Not all compilers and operating systems are created equal. Furthermore, there is no "standard C method" of displaying color, because not all devices have color. Or displays for that matter...


    Quzah.
    Hope is the first step on the road to disappointment.

  6. #6
    Registered User
    Join Date
    Apr 2003
    Posts
    3
    there is a conio.c with the definitions of the functions, and it is in the same folder as the header file.

    sorry I forgot to mention the compiler and OS. I am using DevC++ 4 with MingW, and my OS is Win XP.

    Since conio does not sound to be standard, is there a better way I should make colored text? Note: I am a "noob" so the reason i chose conio is because it looked very simple. After coming from BASIC and VB I have lots of small problems in C that I often cant resolve and I end up giving up on projects because of them, so I try to keep everything siple so I can focus on the inherent difficulties of the project. The program i am doing now is hopeful of becoming a chess AI engine, so I should have enough problems with that...

  7. #7
    Registered Luser cwr's Avatar
    Join Date
    Jul 2005
    Location
    Sydney, Australia
    Posts
    869
    If you just want colored text in a terminal, then ANSI escape codes are likely the most portable. Whether these work on Windows, I've no idea.

    http://en.wikipedia.org/wiki/ANSI_escape_code

  8. #8
    Frequently Quite Prolix dwks's Avatar
    Join Date
    Apr 2005
    Location
    Canada
    Posts
    8,057
    See the FAQ.
    dwk

    Seek and ye shall find. quaere et invenies.

    "Simplicity does not precede complexity, but follows it." -- Alan Perlis
    "Testing can only prove the presence of bugs, not their absence." -- Edsger Dijkstra
    "The only real mistake is the one from which we learn nothing." -- John Powell


    Other boards: DaniWeb, TPS
    Unofficial Wiki FAQ: cpwiki.sf.net

    My website: http://dwks.theprogrammingsite.com/
    Projects: codeform, xuni, atlantis, nort, etc.

  9. #9
    Frequently Quite Prolix dwks's Avatar
    Join Date
    Apr 2005
    Location
    Canada
    Posts
    8,057
    If you just want colored text in a terminal, then ANSI escape codes are likely the most portable. Whether these work on Windows, I've no idea.
    They only work if you have ANSI.SYS in your CONFIG.SYS or where ever it should be.
    dwk

    Seek and ye shall find. quaere et invenies.

    "Simplicity does not precede complexity, but follows it." -- Alan Perlis
    "Testing can only prove the presence of bugs, not their absence." -- Edsger Dijkstra
    "The only real mistake is the one from which we learn nothing." -- John Powell


    Other boards: DaniWeb, TPS
    Unofficial Wiki FAQ: cpwiki.sf.net

    My website: http://dwks.theprogrammingsite.com/
    Projects: codeform, xuni, atlantis, nort, etc.

  10. #10
    It's full of stars adrianxw's Avatar
    Join Date
    Aug 2001
    Posts
    4,829
    My Console Programming Tutorial starting there covers the Windows way of adding colour to a console window, and a whole load of other stuff.

    It is written in C++ but if you replace the cout with printf, they should work, they did before I converted them to C++.

    The API routines will be the same of course.
    Wave upon wave of demented avengers march cheerfully out of obscurity unto the dream.

  11. #11
    Registered User
    Join Date
    Dec 2005
    Posts
    23
    hi
    I also have problem with undefined reference. Program worked fine before, I added few lines and it worked ok, but then my colegue updated the Monta Vista Linux and now when I want to compile it writes me undefined reference, path and the names of the functions
    What should I do?
    Have a nice Day

    Matt

  12. #12
    Registered User
    Join Date
    Dec 2005
    Posts
    23
    I sorted out, what an idiot thing from me.
    Have a nice Day

    Matt

Popular pages Recent additions subscribe to a feed

Similar Threads

  1. "undefined reference" in my Class
    By bumcheekcity in forum C++ Programming
    Replies: 8
    Last Post: 04-08-2007, 01:40 PM
  2. Post...
    By maxorator in forum C++ Programming
    Replies: 12
    Last Post: 10-11-2005, 08:39 AM
  3. Dikumud
    By maxorator in forum C++ Programming
    Replies: 1
    Last Post: 10-01-2005, 06:39 AM
  4. "Undefined Reference"
    By crepincdotcom in forum C Programming
    Replies: 24
    Last Post: 05-31-2004, 05:12 PM
  5. Passing data/pointers between functions #2
    By TankCDR in forum C Programming
    Replies: 1
    Last Post: 11-02-2001, 09:49 PM