Thread: header file including

  1. #1
    Registered User
    Join Date
    May 2008
    Posts
    134

    header file including

    head.c:
    Code:
    int add(int a, int b)
    {
            return(a+b);
    }
    head.h:
    Code:
    #include <stdio.h>
    main.c:

    Code:
    #include "head.h"
    main()
    {
            int a = 10, b = 9;
            printf("addition is : %d", add(a+b));
    }
    =================
    Code:
    cc main.c
    gives error:
    Code:
    /tmp/ccuq5Rod.o: In function `main':
    main.c:(.text+0x28): undefined reference to `add'
    collect2: ld returned 1 exit status
    any line of code needs to be added in any file without changing the file structure/number of files. m unable to make it.

  2. #2
    and the Hat of Guessing tabstop's Avatar
    Join Date
    Nov 2007
    Posts
    14,336
    There's nothing wrong with the files and everything wrong with your command line.
    Code:
    cc main.c head.c

  3. #3
    Registered User
    Join Date
    May 2008
    Posts
    134
    thanx,
    but isn't it possible to change code without changing command line without error?

  4. #4
    and the hat of int overfl Salem's Avatar
    Join Date
    Aug 2001
    Location
    The edge of the known universe
    Posts
    39,656
    That is the way you compile programs with multiple source files.

    Sure, you can compile everything in a single source, but it's one hell of a hack.
    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. Including headers in a header file
    By tjpanda in forum C++ Programming
    Replies: 3
    Last Post: 09-22-2008, 08:48 AM
  2. using definition from header file without including it
    By amitbern in forum C Programming
    Replies: 7
    Last Post: 08-02-2007, 04:48 AM
  3. Unknown Memory Leak in Init() Function
    By CodeHacker in forum Windows Programming
    Replies: 3
    Last Post: 07-09-2004, 09:54 AM
  4. Request for comments
    By Prelude in forum A Brief History of Cprogramming.com
    Replies: 15
    Last Post: 01-02-2004, 10:33 AM
  5. Replies: 6
    Last Post: 04-02-2002, 05:46 AM