Thread: Undefined reference

  1. #1
    Registered User
    Join Date
    May 2005
    Posts
    48

    Undefined reference

    Hey guys, first I'd like to thank you for all your help in the past. Anyway, when I compile I get a whole bunch of "undefined reference to" and then a function call. I have these functions defined, and the appropriate files included. For example
    error:
    "main.o(.text+0x235):/home/bbare/converting/c/main.cpp:68: undefined reference to `Convert_and_Score(int, double, int, double, double&)'"

    in main I have #include "In_out.h"
    In_out.h:
    Code:
    void Convert_and_Score(int chrom_num1, double cM_percent1, int chrom_num2, double cM_percent2, double &outscore);

  2. #2
    Registered User
    Join Date
    May 2005
    Posts
    48
    oh ya
    the call in main that the error is referencing:
    Code:
        double score;
        double fChromNumOne = PGAGetRealAllele(ctx, p, pop, 1);
        double fChromNumTwo = PGAGetRealAllele(ctx, p, pop, 3);
        int iChromNumOne = (int)(fChromNumOne * NUM_CHROM);
        int iChromNumTwo = (int)(fChromNumTwo * NUM_CHROM);
    
        double loc1 = PGAGetRealAllele(ctx, p, pop, 2);
        double loc2 = PGAGetRealAllele(ctx, p, pop, 4);
    
        score = 0;
        Convert_and_Score(iChromNumOne, loc1, iChromNumTwo, loc2, score);
    and those PGA functions are also undefined references yet I have the file that they are defined in included...

  3. #3
    Code Goddess Prelude's Avatar
    Join Date
    Sep 2001
    Posts
    9,897
    Okay, you have the header...but are those functions defined anywhere? A header should only give you the declarations, not the definitions, so you need to link with a library or an implementation source file.
    My best code is written with the delete key.

  4. #4
    Registered User
    Join Date
    May 2005
    Posts
    48
    Sorry, yes, the declarations are in the header. The defintions are in the file of the same name just .cpp extension.
    Makefile:
    Code:
    In_out.o: In_out.h In_out.cpp
            g++ $(FLAGS) -c In_out.cpp
    
    ...
    
    ga_ee: math_utils.o calc_subs.o EM.o EE_utils.o In_out.o main.o
            g++ math_utils.o calc_subs.o EM.o EE_utils.o main.o -o ga_ee

  5. #5
    Registered User
    Join Date
    Oct 2001
    Posts
    2,934
    > g++ math_utils.o calc_subs.o EM.o EE_utils.o main.o -o ga_ee
    I notice you don't have In_out.o included on this line. It is included on the line above this one however.

  6. #6
    Registered User
    Join Date
    May 2005
    Posts
    48
    yay! stupid mistakes are so much better. easier to fix!

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, 08:18 PM
  2. Undefined Reference Compiling Error
    By AlakaAlaki in forum C++ Programming
    Replies: 1
    Last Post: 06-27-2008, 11:45 AM
  3. Screwy Linker Error - VC2005
    By Tonto in forum C++ Programming
    Replies: 5
    Last Post: 06-19-2007, 02:39 PM
  4. C OpenGL Compiler Error?
    By Matt3000 in forum C Programming
    Replies: 12
    Last Post: 07-07-2006, 04:42 PM
  5. c++ linking problem for x11
    By kron in forum Linux Programming
    Replies: 1
    Last Post: 11-19-2004, 10:18 AM