Thread: separating functions into diff files

  1. #1
    Registered User
    Join Date
    Apr 2009
    Posts
    16

    separating functions into diff files

    Hello, I have a pretty big file and I wanted to move the functions into other files. So far I've been compiling with
    cc -o out main.c a.c
    But I would like to just compile one c file. Is that possible? I was reading something about using #include, so in my main.c I have:
    #include "a.h"
    and in my a.h file I define my constants and functions
    Code:
    #define PI 3.14
    void a(int N, int *M);
    and in a separate a.c file I only have the function. However when I try compiling I have the error " undefined reference to 'a' " What am I doing wrong?

  2. #2
    ATH0 quzah's Avatar
    Join Date
    Oct 2001
    Posts
    14,826
    If you haven't compiled any of the files, you must compile them all. If you have only recently edited one file, you just need to recompile that file. You always need to link all of them however.


    Quzah.
    Hope is the first step on the road to disappointment.

Popular pages Recent additions subscribe to a feed

Similar Threads

  1. Replies: 3
    Last Post: 09-30-2008, 12:10 AM
  2. How to Create .H files and use Assembler functions?
    By luisvalencia in forum C Programming
    Replies: 7
    Last Post: 04-10-2005, 11:47 PM
  3. Using c++ standards
    By subdene in forum C++ Programming
    Replies: 4
    Last Post: 06-06-2002, 09:15 AM
  4. Functions and Creating Files
    By AngelEyes in forum C++ Programming
    Replies: 2
    Last Post: 05-14-2002, 06:12 PM
  5. reinserting htm files into chm help files
    By verb in forum Windows Programming
    Replies: 0
    Last Post: 02-15-2002, 09:35 AM