Thread: Undefined Reference to functions, that CAN be found

  1. #1
    Registered User
    Join Date
    Aug 2009
    Location
    Antwerp, Belgium
    Posts
    12

    Undefined Reference to functions, that CAN be found

    Hi!

    I'm using GNU's gsl-library, which I installed and configured in C::B,
    When I try to build, C::B gives me the following error messages:

    Code:

    Code:
    ||=== HH, Debug ===|
    obj\Debug\main.o||In function `_Z21singular_value_decompv':|
    D:\2 - Bouwkunde\070901 - MSc Bouwkunde aan TUe\PROJ FEM-Tool\1 - Programma HH\main.cpp|5194|undefined reference to `_gsl_matrix_alloc'|
    D:\2 - Bouwkunde\070901 - MSc Bouwkunde aan TUe\PROJ FEM-Tool\1 - Programma HH\main.cpp|5197|undefined reference to `_gsl_matrix_set'|
    D:\2 - Bouwkunde\070901 - MSc Bouwkunde aan TUe\PROJ FEM-Tool\1 - Programma HH\main.cpp|5203|undefined reference to `_gsl_matrix_alloc'|
    D:\2 - Bouwkunde\070901 - MSc Bouwkunde aan TUe\PROJ FEM-Tool\1 - Programma HH\main.cpp|5204|undefined reference to `_gsl_vector_alloc'|
    D:\2 - Bouwkunde\070901 - MSc Bouwkunde aan TUe\PROJ FEM-Tool\1 - Programma HH\main.cpp|5205|undefined reference to `_gsl_vector_alloc'|
    D:\2 - Bouwkunde\070901 - MSc Bouwkunde aan TUe\PROJ FEM-Tool\1 - Programma HH\main.cpp|5207|undefined reference to `_gsl_linalg_SV_decomp'|
    D:\2 - Bouwkunde\070901 - MSc Bouwkunde aan TUe\PROJ FEM-Tool\1 - Programma HH\main.cpp|5210|undefined reference to `_gsl_matrix_calloc'|
    D:\2 - Bouwkunde\070901 - MSc Bouwkunde aan TUe\PROJ FEM-Tool\1 - Programma HH\main.cpp|5212|undefined reference to `_gsl_vector_get'|
    D:\2 - Bouwkunde\070901 - MSc Bouwkunde aan TUe\PROJ FEM-Tool\1 - Programma HH\main.cpp|5212|undefined reference to `_gsl_matrix_set'|
    D:\2 - Bouwkunde\070901 - MSc Bouwkunde aan TUe\PROJ FEM-Tool\1 - Programma HH\main.cpp|5219|undefined reference to `_gsl_matrix_get'|
    D:\2 - Bouwkunde\070901 - MSc Bouwkunde aan TUe\PROJ FEM-Tool\1 - Programma HH\main.cpp|5228|undefined reference to `_gsl_matrix_get'|
    D:\2 - Bouwkunde\070901 - MSc Bouwkunde aan TUe\PROJ FEM-Tool\1 - Programma HH\main.cpp|5237|undefined reference to `_gsl_matrix_get'|
    ||=== Build finished: 12 errors, 0 warnings ===|

    When I right-click on the function, and choose:
    Find declaration of: "gsl_matrix_alloc"
    it can. And simply opens the header file in which it is stated.
    Which I interpret as the library being configured correctly (true?).

    So why are they "undifined references"?
    Any suggestions?
    Cheers, Carola

  2. #2
    and the Hat of Guessing tabstop's Avatar
    Join Date
    Nov 2007
    Posts
    14,336
    The header file is not the definition of the function -- it is the declaration of the function. You need to link in a library (which usually has the form lib<whatever>.a, or <whatever>.lib) where the actual code resides -- the GSL manual has the name(s) at the front. I forget the exact menu options, it's something like project -> options -> linker.

  3. #3
    Guest Sebastiani's Avatar
    Join Date
    Aug 2001
    Location
    Waterloo, Texas
    Posts
    5,708
    You're missing an object/library file in the project settings. Gsl should have a lib directory - take a look there and you'll probably find the file that needs to be included.

  4. #4
    Registered User
    Join Date
    Aug 2009
    Location
    Antwerp, Belgium
    Posts
    12
    I understand the header file isn't the function itself,
    but C::B opens the header file in which the function is defined.
    Maybe I didn't explain well:

    When I right-click on the function, and choose:
    Find declaration of: "gsl_matrix_alloc"
    it can. And simply opens the header file in which it is stated.
    I did this to the function in the code itself:

    Code:
    gsl_matrix * sm3_v = gsl_matrix_alloc (sm2nn,sm2nn);
    That's why I figured that I configured the library correctly in C::B
    and why I don't understand why it doesn't get it when it's building.


    Did I miss your point?

  5. #5
    Registered User
    Join Date
    Aug 2009
    Location
    Antwerp, Belgium
    Posts
    12
    Quote Originally Posted by Sebastiani View Post
    You're missing an object/library file in the project settings. Gsl should have a lib directory - take a look there and you'll probably find the file that needs to be included.
    I tried to include it by the following procedure, as adviced by
    Learn C++ - » A.3 — Using libraries with Code::Blocks

    right-click on the project > Build Options > Linker Settings > adding library

    Then it starts to do crazy things
    because I get:

    Code:
    C:\Program Files\CodeBlocks\GNU\lib\libgsl.a(blas_blas.o):blas.c:(.text+0x3a)||undefined reference to `_cblas_sdsdot'|
    C:\Program Files\CodeBlocks\GNU\lib\libgsl.a(blas_blas.o):blas.c:(.text+0xc3)||undefined reference to `_cblas_dsdot'|
    C:\Program Files\CodeBlocks\GNU\lib\libgsl.a(blas_blas.o):blas.c:(.text+0x143)||undefined reference to `_cblas_sdot'|
    C:\Program Files\CodeBlocks\GNU\lib\libgsl.a(blas_blas.o):blas.c:(.text+0x1c3)||undefined reference to `_cblas_ddot'|
    C:\Program Files\CodeBlocks\GNU\lib\libgsl.a(blas_blas.o):blas.c:(.text+0x24a)||undefined reference to `_cblas_cdotu_sub'|
    C:\Program Files\CodeBlocks\GNU\lib\libgsl.a(blas_blas.o):blas.c:(.text+0x2ca)||undefined reference to `_cblas_cdotc_sub'|
    C:\Program Files\CodeBlocks\GNU\lib\libgsl.a(blas_blas.o):blas.c:(.text+0x34a)||undefined reference to `_cblas_zdotu_sub'|
    C:\Program Files\CodeBlocks\GNU\lib\libgsl.a(blas_blas.o):blas.c:(.text+0x3ca)||undefined reference to `_cblas_zdotc_sub'|
    C:\Program Files\CodeBlocks\GNU\lib\libgsl.a(blas_blas.o):blas.c:(.text+0x42d)||undefined reference to `_cblas_snrm2'|
    C:\Program Files\CodeBlocks\GNU\lib\libgsl.a(blas_blas.o):blas.c:(.text+0x45d)||undefined reference to `_cblas_dnrm2'|
    C:\Program Files\CodeBlocks\GNU\lib\libgsl.a(blas_blas.o):blas.c:(.text+0x48d)||undefined reference to `_cblas_scnrm2'|
    C:\Program Files\CodeBlocks\GNU\lib\libgsl.a(blas_blas.o):blas.c:(.text+0x4bd)||undefined reference to `_cblas_dznrm2'|
    C:\Program Files\CodeBlocks\GNU\lib\libgsl.a(blas_blas.o):blas.c:(.text+0x4ed)||undefined reference to `_cblas_sasum'|
    C:\Program Files\CodeBlocks\GNU\lib\libgsl.a(blas_blas.o):blas.c:(.text+0x51d)||undefined reference to `_cblas_dasum'|
    C:\Program Files\CodeBlocks\GNU\lib\libgsl.a(blas_blas.o):blas.c:(.text+0x54d)||undefined reference to `_cblas_scasum'|
    C:\Program Files\CodeBlocks\GNU\lib\libgsl.a(blas_blas.o):blas.c:(.text+0x57d)||undefined reference to `_cblas_dzasum'|
    C:\Program Files\CodeBlocks\GNU\lib\libgsl.a(blas_blas.o):blas.c:(.text+0x5ad)||undefined reference to `_cblas_isamax'|
    C:\Program Files\CodeBlocks\GNU\lib\libgsl.a(blas_blas.o):blas.c:(.text+0x5dd)||undefined reference to `_cblas_idamax'|
    C:\Program Files\CodeBlocks\GNU\lib\libgsl.a(blas_blas.o):blas.c:(.text+0x60d)||undefined reference to `_cblas_icamax'|
    C:\Program Files\CodeBlocks\GNU\lib\libgsl.a(blas_blas.o):blas.c:(.text+0x63d)||undefined reference to `_cblas_izamax'|
    C:\Program Files\CodeBlocks\GNU\lib\libgsl.a(blas_blas.o):blas.c:(.text+0x683)||undefined reference to `_cblas_sswap'|
    C:\Program Files\CodeBlocks\GNU\lib\libgsl.a(blas_blas.o):blas.c:(.text+0x703)||undefined reference to `_cblas_dswap'|
    C:\Program Files\CodeBlocks\GNU\lib\libgsl.a(blas_blas.o):blas.c:(.text+0x783)||undefined reference to `_cblas_cswap'|
    C:\Program Files\CodeBlocks\GNU\lib\libgsl.a(blas_blas.o):blas.c:(.text+0x803)||undefined reference to `_cblas_zswap'|
    C:\Program Files\CodeBlocks\GNU\lib\libgsl.a(blas_blas.o):blas.c:(.text+0x883)||undefined reference to `_cblas_scopy'|
    C:\Program Files\CodeBlocks\GNU\lib\libgsl.a(blas_blas.o):blas.c:(.text+0x903)||undefined reference to `_cblas_dcopy'|
    C:\Program Files\CodeBlocks\GNU\lib\libgsl.a(blas_blas.o):blas.c:(.text+0x983)||undefined reference to `_cblas_ccopy'|
    C:\Program Files\CodeBlocks\GNU\lib\libgsl.a(blas_blas.o):blas.c:(.text+0xa03)||undefined reference to `_cblas_zcopy'|
    C:\Program Files\CodeBlocks\GNU\lib\libgsl.a(blas_blas.o):blas.c:(.text+0xa8a)||undefined reference to `_cblas_saxpy'|
    C:\Program Files\CodeBlocks\GNU\lib\libgsl.a(blas_blas.o):blas.c:(.text+0xb0a)||undefined reference to `_cblas_daxpy'|
    C:\Program Files\CodeBlocks\GNU\lib\libgsl.a(blas_blas.o):blas.c:(.text+0xb8a)||undefined reference to `_cblas_caxpy'|
    C:\Program Files\CodeBlocks\GNU\lib\libgsl.a(blas_blas.o):blas.c:(.text+0xc0a)||undefined reference to `_cblas_zaxpy'|
    C:\Program Files\CodeBlocks\GNU\lib\libgsl.a(blas_blas.o):blas.c:(.text+0xc72)||undefined reference to `_cblas_srotg'|
    C:\Program Files\CodeBlocks\GNU\lib\libgsl.a(blas_blas.o):blas.c:(.text+0xca2)||undefined reference to `_cblas_drotg'|
    C:\Program Files\CodeBlocks\GNU\lib\libgsl.a(blas_blas.o):blas.c:(.text+0xcf1)||undefined reference to `_cblas_srot'|
    C:\Program Files\CodeBlocks\GNU\lib\libgsl.a(blas_blas.o):blas.c:(.text+0xd81)||undefined reference to `_cblas_drot'|
    C:\Program Files\CodeBlocks\GNU\lib\libgsl.a(blas_blas.o):blas.c:(.text+0xdf9)||undefined reference to `_cblas_srotmg'|
    C:\Program Files\CodeBlocks\GNU\lib\libgsl.a(blas_blas.o):blas.c:(.text+0xe39)||undefined reference to `_cblas_drotmg'|
    C:\Program Files\CodeBlocks\GNU\lib\libgsl.a(blas_blas.o):blas.c:(.text+0xe8a)||undefined reference to `_cblas_srotm'|
    C:\Program Files\CodeBlocks\GNU\lib\libgsl.a(blas_blas.o):blas.c:(.text+0xf0a)||undefined reference to `_cblas_drotm'|
    C:\Program Files\CodeBlocks\GNU\lib\libgsl.a(blas_blas.o):blas.c:(.text+0xf74)||undefined reference to `_cblas_sscal'|
    C:\Program Files\CodeBlocks\GNU\lib\libgsl.a(blas_blas.o):blas.c:(.text+0xfa4)||undefined reference to `_cblas_dscal'|
    C:\Program Files\CodeBlocks\GNU\lib\libgsl.a(blas_blas.o):blas.c:(.text+0xfd4)||undefined reference to `_cblas_cscal'|
    C:\Program Files\CodeBlocks\GNU\lib\libgsl.a(blas_blas.o):blas.c:(.text+0x1004)||undefined reference to `_cblas_zscal'|
    C:\Program Files\CodeBlocks\GNU\lib\libgsl.a(blas_blas.o):blas.c:(.text+0x1034)||undefined reference to `_cblas_csscal'|
    C:\Program Files\CodeBlocks\GNU\lib\libgsl.a(blas_blas.o):blas.c:(.text+0x1064)||undefined reference to `_cblas_zdscal'|
    C:\Program Files\CodeBlocks\GNU\lib\libgsl.a(blas_blas.o):blas.c:(.text+0x1133)||undefined reference to `_cblas_sgemv'|
    C:\Program Files\CodeBlocks\GNU\lib\libgsl.a(blas_blas.o):blas.c:(.text+0x1203)||undefined reference to `_cblas_dgemv'|
    C:\Program Files\CodeBlocks\GNU\lib\libgsl.a(blas_blas.o):blas.c:(.text+0x12dd)||undefined reference to `_cblas_cgemv'|
    C:\Program Files\CodeBlocks\GNU\lib\libgsl.a(blas_blas.o):blas.c:(.text+0x13cd)||undefined reference to `_cblas_zgemv'|
    ||More errors follow but not being shown.|
    ||Edit the max errors limit in compiler options...|
    ||=== Build finished: 50 errors, 0 warnings ===|

  6. #6
    Guest Sebastiani's Avatar
    Join Date
    Aug 2001
    Location
    Waterloo, Texas
    Posts
    5,708
    >> That's why I figured that I configured the library correctly in C::B
    and why I don't understand why it doesn't get it when it's building.

    Code Blocks is not the compiler, it's an IDE. So whatever it knows about the code is irrelavent.

    >> I tried to include it by the following procedure, as adviced by

    The way linkers work is that the object/lib files have to be included in a specific order if some of them reference eachother, and that can be tricky. Look at the makefiles included with GSL and it will show what the order of inclusion should be.

  7. #7
    Officially An Architect brewbuck's Avatar
    Join Date
    Mar 2007
    Location
    Portland, OR
    Posts
    7,396
    Quote Originally Posted by Carola View Post
    I understand the header file isn't the function itself,
    but C::B opens the header file in which the function is defined.
    That just proves you have the header file, not the library. And perhaps your misunderstanding is due to the belief that the function is "defined" in the header file. It is not. A function is defined (its code is available) in an object file, i.e. a library. The header file just provides type information.

    If you actually look in the header file you get when you click the function, do you really think that simple line of code implements that entire function? The function implementation has to be somewhere else -- the library file, which you haven't configured properly.
    Code:
    //try
    //{
    	if (a) do { f( b); } while(1);
    	else   do { f(!b); } while(1);
    //}

  8. #8
    Registered User hk_mp5kpdw's Avatar
    Join Date
    Jan 2002
    Location
    Northern Virginia/Washington DC Metropolitan Area
    Posts
    3,817
    The header pretty much is there to just allow the compiler to do its job of type checking the arguments and return values and also to check the number of arguments you're trying to pass into the function. Having and including any necessary headers correctly will simply get you past the compilation stage of building an executable (producing object code). Undefined reference errors are linker errors and not compilation errors. Linking is the next stage of building an executable program after compilation. It is the linkers job to find the actual code that implements all the various functions referenced in your program and put everything together into one nice package. Just because you can right click on a function name and have the function declaration from the header file pop-up does not mean that everything is cool, it simply means that you've included a header. The linker needs to know what library file contains the necessary code (and where it is) so it can put everything together at the end, this is done in your IDE by explicitly specifying those additional libraries that need to be included.
    "Owners of dogs will have noticed that, if you provide them with food and water and shelter and affection, they will think you are god. Whereas owners of cats are compelled to realize that, if you provide them with food and water and shelter and affection, they draw the conclusion that they are gods."
    -Christopher Hitchens

  9. #9
    Registered User
    Join Date
    Aug 2009
    Location
    Antwerp, Belgium
    Posts
    12
    Hi! Thanks for all the answers,
    as I'm trying to get understanding of the core theory,
    I hope you don't mind me asking my bunch of ignorant questions.

    > hk_mp5kpdw

    Thanks, that's pretty clear now.
    I got some idea about it from the info I gathered on the web,
    but it's hard to gain overall insight, and to be certain about what you think,
    there don't seem to be a lot of 'standard procedures' to get certain things done.

    > brewbuck:

    no, I didn't think that complex functions are implemented by a single command line,
    but I did think that through these lines other functions were called,
    in a web-like or waterfall-like structure, running through ... o never mind.
    It's hard, you know, at the start


    my latest clue, problem in compiling&linking [Archive] - FedoraForum.org,
    got me to think that my problem might be that the Linker is looking for Blas....

    ...

    which I found next to my gsl - library


    PHEW!
    It took me 4 (!) days to configure C::B
    to be able to only run a program
    but now I've got it, thanks guys!

Popular pages Recent additions subscribe to a feed

Similar Threads

  1. Library troubles with makefile
    By mslate in forum Linux Programming
    Replies: 17
    Last Post: 07-23-2009, 04:43 PM
  2. Another syntax error
    By caldeira in forum C Programming
    Replies: 31
    Last Post: 09-05-2008, 01:01 AM
  3. Logical errors with seach function
    By Taka in forum C Programming
    Replies: 4
    Last Post: 09-18-2006, 05:20 AM
  4. MinGW Linking GUI Program
    By Tonto in forum Tech Board
    Replies: 19
    Last Post: 08-23-2006, 03:28 PM
  5. C OpenGL Compiler Error?
    By Matt3000 in forum C Programming
    Replies: 12
    Last Post: 07-07-2006, 04:42 PM