Undefined reference to...

This is a discussion on Undefined reference to... within the C Programming forums, part of the General Programming Boards category; Hello! I'm trying to compile and try some libraies to decodify a datamtatrix code. I'm using codeblocks over Windows XP. ...

  1. #1
    Registered User
    Join Date
    Oct 2009
    Posts
    10

    Undefined reference to...

    Hello!

    I'm trying to compile and try some libraies to decodify a datamtatrix code. I'm using codeblocks over Windows XP.

    I have tried with two libraries and I always get the same error: undefined reference to... I have seen that is a linker problem, but I don't know how to fix it.

    In the first library. I compile it perfectly and it works. But the problems come when I want to add one file that it's need to open a file from the HDD. So, when I add it, it needs some libraries like magick wand and magick (about images). I add them and I finish of compile it perfectly. But then, it says "undefined reference to..." each function called by dtmxread to the magick wand library.

    In the second one, it happens the same. This one need to be linked by Fec.h. When I finish of compile it, the linker erros comes to me againg. Each function called in the library to the file fec.h are undefined references...

    What I'm doing wrong? Thank you so much.

    Should I use anothe programming enviroment?.

  2. #2
    ATH0 quzah's Avatar
    Join Date
    Oct 2001
    Posts
    14,826
    You have to know about a function before you can actually use it. Therefore, the function itself must exist in the file you want to use, before you use it, or it must be prototyped before you use it. The latter is usually done by including a header file which has said prototype.


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

  3. #3
    C++まいる!Cをこわせ!
    Join Date
    Oct 2007
    Posts
    23,013
    When calling functions in a library, the linker must know where these functions are. To tell the linker the necessary information, you must supply it with .lib files from the specified library. If you have those .lib files (you should have them if you have compiled the library), then you just have to configure the linker to find them.
    How to do that in C::B, I do not know, however.
    Quote Originally Posted by Adak View Post
    io.h certainly IS included in some modern compilers. It is no longer part of the standard for C, but it is nevertheless, included in the very latest Pelles C versions.
    Quote Originally Posted by Salem View Post
    You mean it's included as a crutch to help ancient programmers limp along without them having to relearn too much.

    Outside of your DOS world, your header file is meaningless.

  4. #4
    Registered User
    Join Date
    Oct 2009
    Posts
    10
    Hello, thanks for your answers. I have tried to do that but I don't find the *.lib. Really, I call them libraries, because when I downloaded them, it says that they are that . I only see a file set of *.c *.h. and some .sh but nothing that C::B can add like a library in the linker options. If I must generate it...how can I do it?. Compiling only the "library"? I don't think so, because it is going to ask for me a main function.... :S

    Thank you again!!

  5. #5
    and the Hat of Guessing tabstop's Avatar
    Join Date
    Nov 2007
    Posts
    14,185
    It only asks you for a main function if you try to link an executable. If you compile only, no main is needed. How you do that depends on what you're using for a compiler. You say C::B, so you should do File->New->Project, and choose either static or shared library depending on what you want. Then you can add the files into your project and off you go.

  6. #6
    Registered User
    Join Date
    Oct 2009
    Posts
    10
    Hello, I have done that. Create the library like you say in the static library options. I have to quit a lot of things that references to pthread and that things. But well, it doesn't mind I work with winthreads. Now, I have build it, but I don't see any file.lib in the folder project. I have to do anything more?. I online have the files *.o.

    Thank you for all, I know C, but about libraries....not so much

  7. #7
    and the Hat of Guessing tabstop's Avatar
    Join Date
    Nov 2007
    Posts
    14,185
    *.o works just as well as *.lib.

  8. #8
    Registered User
    Join Date
    Oct 2009
    Posts
    10
    Hello!

    I'm going to say step by step what I have done.

    Firstly, I have been working with the second one library, because it's shorter.

    1- It needs fec.h, so I take all the files that come with FEC and create another project (static library).

    2- Add all of them to the project -> it gives to me a lot of errors. So I decided to only add to the project Fec.c y Fec.h. It generates to me the file.a

    3- I add to the project libdatamatrix the file.a in the linker options and nothing, the same errors. Then I think that.. in the project libdatamatrix I have one file called cli.c that contents the main. So I though maybe I must do a datamatrix library.

    4- Create a new project (static library) with the files of the datamatrix decoder. I only add datamatrix.h and datamatrix.c (the rest no, seeing the experience before in step 2). And I got the .a file.

    5- Add to initial project datamatrix where cli.c is. And nothing.... the same errors. undefined reference to...


    I'm missing something?

    Thank you all!

  9. #9
    and the Hat of Guessing tabstop's Avatar
    Join Date
    Nov 2007
    Posts
    14,185
    Okay. So in the linux world, libraries end in .a. You need take that .a file and put in the library part (not as an include, not as an added file, but in compiler settings).

  10. #10
    Registered User
    Join Date
    Oct 2009
    Posts
    10
    I had it in the linker settings at build options in the C::B, now I try like you said in compiler settings in the part of other options, and nothing.... :S

    About the linux.., I though they were *.so. But well I'm working on XP, and well...it can be because it's the output of the C::B.

    Thanks!

  11. #11
    and the Hat of Guessing tabstop's Avatar
    Join Date
    Nov 2007
    Posts
    14,185
    *.so is the linux equivalent of *.dll, while *.a is the linux equivalent of *.lib.

    You need to make sure the path is right -- if you don't put the path to your .a files in the include path, then you won't find them.

    If you have a project you want to use this with, then you should go to project->build options, choose linker settings, click on add on the left, and then click on the ... to find your .a file. This will include the full path so that your .a file will be found.

  12. #12
    Registered User
    Join Date
    Oct 2009
    Posts
    10
    Yes, that was how I was doing that, after searching the file.a it asked to you if you want the incluthe path or the full one (including c:\...) and I choose for security c:\...becasue it always work. But nothing... :S it's really odd...all of it.

  13. #13
    and the Hat of Guessing tabstop's Avatar
    Join Date
    Nov 2007
    Posts
    14,185
    Define "nothing".

  14. #14
    Registered User
    Join Date
    Oct 2009
    Posts
    10
    lol... I'm sorry , Nothing...I want to say that it doesn't work...the problem go on existing.

  15. #15
    and the Hat of Guessing tabstop's Avatar
    Join Date
    Nov 2007
    Posts
    14,185
    I am trying to avoid downloading the thing. The installation commands are in the .sh file, so that may give you some idea of what needs to be compiled together. If you made more than one .a file for whatever reason, then both of those would need to be added.

Page 1 of 2 12 LastLast
Popular pages Recent additions subscribe to a feed

Similar Threads

  1. Getting an error with OpenGL: collect2: ld returned 1 exit status
    By Lorgon Jortle in forum C++ Programming
    Replies: 6
    Last Post: 05-08-2009, 09:18 PM
  2. Undefined Reference Compiling Error
    By AlakaAlaki in forum C++ Programming
    Replies: 1
    Last Post: 06-27-2008, 12:45 PM
  3. Screwy Linker Error - VC2005
    By Tonto in forum C++ Programming
    Replies: 5
    Last Post: 06-19-2007, 03:39 PM
  4. C OpenGL Compiler Error?
    By Matt3000 in forum C Programming
    Replies: 12
    Last Post: 07-07-2006, 05:42 PM
  5. c++ linking problem for x11
    By kron in forum Linux Programming
    Replies: 1
    Last Post: 11-19-2004, 10:18 AM

Tags for this Thread


1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 21