Thread: undefined reference to a function

  1. #1
    Registered User
    Join Date
    Jan 2006
    Posts
    5

    undefined reference to a function

    Hi,

    i need to work with images, so I downloaded GDLibrary.
    It is in one directory, in another one I have my .c file.

    In my .c file I import the library with a sentence like
    #include "../thaPath/gd.h"

    In my .c I saw that I have no problems using (declaring) types defined in gd.h,
    but when I try to use functiones defined there...I got the "undefined reference to..." error message.

    I am working under a Red Hat Linux 9 in case the information is worth....

    Thanks in advance for any suggestion...

  2. #2
    old man
    Join Date
    Dec 2005
    Posts
    90
    It sounds like you're not linking in the library. If you're using gcc, look at the -l switch.

  3. #3
    Registered User
    Join Date
    Jan 2006
    Posts
    5
    Thank you very much!
    At this moment I am at work so I cant try what you suggests, but it sounds very probable.

  4. #4
    Registered User
    Join Date
    Jan 2006
    Posts
    5
    Unfortunately I still doesnt work...

    I tell you my situation.

    Installed GDLibrary package, running ./configure, than the make and after that the make install; as the INSTALL file says...

    Now I got my gd.h in /usr/local/include
    and my libgd.a and also my libgd.a, libgd.la, libgd.so in /usr/local/lib

    and I still got the
    undefined reference when I try
    gcc -Wall myFile.c -lgd

    Any suggestions???

  5. #5
    ex-DECcie
    Join Date
    Dec 2005
    Posts
    125
    Quote Originally Posted by rodrigouy
    Unfortunately I still doesnt work...

    I tell you my situation.

    Installed GDLibrary package, running ./configure, than the make and after that the make install; as the INSTALL file says...

    Now I got my gd.h in /usr/local/include
    and my libgd.a and also my libgd.a, libgd.la, libgd.so in /usr/local/lib

    and I still got the
    undefined reference when I try
    gcc -Wall myFile.c -lgd

    Any suggestions???

    This is what I do -- your mileage may vary. I'm assuming that you're on Linux, based on your "/usr/local/lib"

    In /etc there is a file called /etc/ld.so.conf. In there you can specify locations where shareable libraries are located on your machine. If /usr/local/lib is not in there, put it in there and run ldconfig. (You might need to be root to do that).

    Then, I'd compile like:

    gcc -Wall -lgd myFile.c

    Or, to make sure that nothing else is amiss first, before all that, you could try:

    gcc -Wall -L/usr/local/lib -lgd myFile.c


    Try looking at man ldconfig, man ld.so and man ld for more information.

  6. #6
    Registered User
    Join Date
    Jan 2006
    Posts
    5
    Thank you very much!
    As you said /usr/local/bin wasnt in ld.so.conf file...

    after adding that line and running ldconfig most of my
    undefined references dissapeard,
    all but one, that keeps there...

    I really got no clue whats happening...

  7. #7
    old man
    Join Date
    Dec 2005
    Posts
    90

  8. #8
    Registered User
    Join Date
    Jan 2006
    Posts
    5
    Thanks a lot, it seems i was in hurry to program...

    I hope after reading what you linked carefully (and obviusly after dealing with new problems) I can start to use GDLibrary.

    Thanks a lot again!

Popular pages Recent additions subscribe to a feed

Similar Threads

  1. Replies: 4
    Last Post: 05-13-2011, 08:28 AM
  2. In over my head
    By Shelnutt2 in forum C Programming
    Replies: 1
    Last Post: 07-08-2008, 06:54 PM
  3. We Got _DEBUG Errors
    By Tonto in forum Windows Programming
    Replies: 5
    Last Post: 12-22-2006, 05:45 PM
  4. Game Pointer Trouble?
    By Drahcir in forum C Programming
    Replies: 8
    Last Post: 02-04-2006, 02:53 AM
  5. Problem with Visual C++ Object-Oriented Programming Book.
    By GameGenie in forum C++ Programming
    Replies: 9
    Last Post: 08-29-2005, 11:21 PM