Thread: linking error

  1. #1
    Registered User
    Join Date
    Apr 2010
    Posts
    17

    linking error

    When I run my program I get a compiler error saying undefined reference to 'Get_host'
    please help
    Code:
    //im_sender.c
    
    
    #include "cursor.h"
    
    
    main (int argc, char *argv [])
    
    {
    
    printf("%s\n",Get_host());
    return 0;
    }
    Code:
    //cursor.h
    
    #ifndef CURSOR_H
    #define CURSOR_H
    
    char *Get_host(void);
    //char *Get_room;
    //char *Get_name;
    
    #endif
    Code:
    //cursor.c
    
    #include "cursor.h"
    
    char Host_port[56];
    
    char* Get_host() {
    return Host_port;
    }

  2. #2
    spurious conceit MK27's Avatar
    Join Date
    Jul 2008
    Location
    segmentation fault
    Posts
    8,300
    Quote Originally Posted by gar35 View Post
    When I run my program I get a compiler error saying undefined reference to 'Get_host'
    You mean, "when I compile my code I get an error".

    But the error you're getting is not in the code. How are you compiling it?
    C programming resources:
    GNU C Function and Macro Index -- glibc reference manual
    The C Book -- nice online learner guide
    Current ISO draft standard
    CCAN -- new CPAN like open source library repository
    3 (different) GNU debugger tutorials: #1 -- #2 -- #3
    cpwiki -- our wiki on sourceforge

  3. #3
    Registered User
    Join Date
    Apr 2010
    Posts
    17
    Yea thats right. I have a makefile, should I include this header file in its makefile

  4. #4
    and the hat of int overfl Salem's Avatar
    Join Date
    Aug 2001
    Location
    The edge of the known universe
    Posts
    39,661
    The makefile should have a list of all the .c files which need to be built.

    The dependencies include the .h files, but they in themselves are NOT compiled.
    If you dance barefoot on the broken glass of undefined behaviour, you've got to expect the occasional cut.
    If at first you don't succeed, try writing your phone number on the exam paper.

Popular pages Recent additions subscribe to a feed

Similar Threads

  1. Beginner Needs help in Dev-C++
    By Korrupt Lawz in forum C++ Programming
    Replies: 20
    Last Post: 09-28-2010, 01:17 AM
  2. Post...
    By maxorator in forum C++ Programming
    Replies: 12
    Last Post: 10-11-2005, 08:39 AM
  3. pointer to array of objects of struct
    By undisputed007 in forum C++ Programming
    Replies: 12
    Last Post: 03-02-2004, 04:49 AM
  4. Stupid compiler errors
    By ChrisEacrett in forum C++ Programming
    Replies: 9
    Last Post: 11-30-2003, 05:44 PM
  5. Couple C questions :)
    By Divx in forum C Programming
    Replies: 5
    Last Post: 01-28-2003, 01:10 AM