Linking problem - undefined reference to load_parameters

This is a discussion on Linking problem - undefined reference to load_parameters within the C++ Programming forums, part of the General Programming Boards category; I am having a real bad hair day today! Nothing works! Anyway, enough ranting: main.cc Code: #include <iostream> #include <global.h> ...

  1. #1
    Registered User
    Join Date
    May 2006
    Location
    Berkshire, UK
    Posts
    29

    Linking problem - undefined reference to load_parameters

    I am having a real bad hair day today! Nothing works!

    Anyway, enough ranting:

    main.cc
    Code:
    #include <iostream>
    #include <global.h>
    ...
    int main(int argc,char *argv[])
    {
    ...
    	if(load_params(argv[1]))
    		return RET_ERR; 
    ...
    return RET_OK;
    }
    global.h
    Code:
    #ifndef _GLOBAL_H
    #define _GLOBAL_H
    
    #ifdef __cplusplus
    extern "C"
    {
    #endif
    ...
    	int load_params(char *fname);	
    ...
    #ifdef __cplusplus
    }
    #endif
    
    #endif /* _GLOBAL_H */
    param.cc
    Code:
    #include <global.h>
    ...
    inline int load_params(char *fname)
    {	return param_scenario.init(fname); 
    }
    ...
    All files compile but I get an "undefined reference to load_parameters" error. I note that load_parameters does not have () after it in the error message.

    All help appreciated. Thank you.

  2. #2
    Registered User
    Join Date
    Aug 2005
    Posts
    1,267
    The problem is more likely in the makefile. Is it linking all necessary *.o files, such as param.o and main.o along with other libraries.

    Also, since you declared the function inline, you might have to move it from param.cc to param.h

  3. #3
    C++ Witch laserlight's Avatar
    Join Date
    Oct 2003
    Location
    Singapore
    Posts
    23,820
    Could you provide the smallest and simplest code that demonstrates the error?
    Quote Originally Posted by Bjarne Stroustrup (2000-10-14)
    I get maybe two dozen requests for help with some sort of programming or design problem every day. Most have more sense than to send me hundreds of lines of code. If they do, I ask them to find the smallest example that exhibits the problem and send me that. Mostly, they then find the error themselves. "Finding the smallest program that demonstrates the error" is a powerful debugging tool.
    Look up a C++ Reference and learn How To Ask Questions The Smart Way

  4. #4
    Registered User
    Join Date
    May 2006
    Location
    Berkshire, UK
    Posts
    29
    Quote Originally Posted by Ancient Dragon
    The problem is more likely in the makefile. Is it linking all necessary *.o files, such as param.o and main.o along with other libraries.

    Also, since you declared the function inline, you might have to move it from param.cc to param.h
    I told you it was a bad hair day - remove the inline and everything works :-)

    Thanks for the help everyone.

    Michael.

Popular pages Recent additions subscribe to a feed

Similar Threads

  1. Replies: 4
    Last Post: 05-13-2011, 08:28 AM
  2. undefined Reference when linking a library
    By steve1_rm in forum C Programming
    Replies: 7
    Last Post: 03-12-2008, 05:34 PM
  3. Gnarly Linking Error HELP!!!!
    By brooksbp in forum C++ Programming
    Replies: 8
    Last Post: 05-04-2007, 01:00 AM
  4. Problem with OpenGL tutorial
    By 2Biaz in forum Windows Programming
    Replies: 18
    Last Post: 09-16-2004, 11:02 AM
  5. Undefined Reference Problem
    By esilja in forum C++ Programming
    Replies: 1
    Last Post: 11-08-2001, 08:05 AM

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