Working with multiple source files

This is a discussion on Working with multiple source files within the C Programming forums, part of the General Programming Boards category; I have a similar question so I thought I would necro this thread. I'm a math student trying to write ...

  1. #16
    Registered User
    Join Date
    Jun 2008
    Posts
    3

    Similar situation

    I have a similar question so I thought I would necro this thread.

    I'm a math student trying to write a program so I don't know too much. I'm working on fedora code 5.
    I am trying to make a call to a C program called nauty (it calculates automorphism groups of graphs).
    As a first step I'm just trying to run one of it's example programs, which executes a simple call to nauty.
    However it says "It needs to be linked with nauty.c nautil.c and naugraph.c.".
    I've got a vague idea of what that means from reading around here a little bit.
    When I try to compile my example program I get a whole host of errors. It seems that the example cannot find nauty. This isn't too suprising since nauty is in a different folder.

    So my question is: how do I link my example program to other c files that are located elsewhere?

    Here is the example program in full.
    The nauty files are in /usr/local/nauty22
    Code:
    /* This program prints generators for the automorphism group of an
       n-vertex polygon, where n is a number supplied by the user.
       It needs to be linked with nauty.c, nautil.c and naugraph.c.
       This version uses a fixed limit for MAXN.
    */
    #define MAXN 100
    #include "nauty.h"   /* which includes <stdio.h> */
    main()
    {
        graph g[MAXN*MAXM];
        int lab[MAXN],ptn[MAXN],orbits[MAXN];
        static DEFAULTOPTIONS(options);
        statsblk(stats);
        setword workspace[50*MAXM];
        int n,m,v;
        set *gv;
        options.writeautoms = TRUE;
        while (1)
        {
            printf("\nenter n : ");
            if (scanf("%d",&n) == 1 && n > 0)
            {
                if (n > MAXN)
                {
                    printf("n must be in the range 1..%d\n",MAXN);
                    exit(1);
                }
                m = (n + WORDSIZE - 1) / WORDSIZE;
                nauty_check(WORDSIZE,m,n,NAUTYVERSIONID);
                for (v = 0; v < n; ++v)
                {
                    gv = GRAPHROW(g,v,m);
                    EMPTYSET(gv,m);
                    ADDELEMENT(gv,(v+n-1)%n);
                    ADDELEMENT(gv,(v+1)%n);
                }
                printf("Generators for Aut(C[%d]):\n",n);
                nauty(g,lab,ptn,NULL,orbits,&options,&stats,
                                                workspace,50*MAXM,m,n,NULL);
            }
            else
                break;
        }
    }
    Hopefully I havn't broken any protocal here.
    Thanks very much for any and all advice.

  2. #17
    and the Hat of Guessing tabstop's Avatar
    Join Date
    Nov 2007
    Posts
    14,185
    You would type "gcc" followed by all the .c files needed to make a complete program. If they are in different directories, you can specify a path to those files, or move all the .c files so they are together.

  3. #18
    Registered User
    Join Date
    Jun 2008
    Posts
    3
    Thanks very much, I appreaciate it ^^

Page 2 of 2 FirstFirst 12
Popular pages Recent additions subscribe to a feed

Similar Threads

  1. Splitting source into multiple files(Linux & make)
    By IceDane in forum C Programming
    Replies: 6
    Last Post: 05-18-2009, 07:31 AM
  2. added start menu crashes game
    By avgprogamerjoe in forum Game Programming
    Replies: 6
    Last Post: 08-29-2007, 01:30 PM
  3. WM_COPYDATA and mutex selecting multiple files
    By gh0st in forum Windows Programming
    Replies: 2
    Last Post: 10-27-2006, 02:22 PM
  4. multiple source files
    By AmazingRando in forum C Programming
    Replies: 6
    Last Post: 03-13-2005, 02:39 PM
  5. Multiple Source Files!?!?
    By Padawan in forum C Programming
    Replies: 14
    Last Post: 04-03-2004, 11:19 PM

Tags for this Thread


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