Modular programming: undefined reference. Help pls!

This is a discussion on Modular programming: undefined reference. Help pls! within the C Programming forums, part of the General Programming Boards category; Hello, I'm writing a modular program. However, the compiler complains that it can't find the function create_list, but this function ...

  1. #1
    Registered User
    Join Date
    Jan 2012
    Posts
    69

    Modular programming: undefined reference. Help pls!

    Hello,

    I'm writing a modular program. However, the compiler complains that it can't find the function create_list, but this function is declared in Bibliography.h

    The precise error is:
    kevin@kevin-N55SF:~/Desktop/Project$ gcc -Wall -ansi -pedantic -O0 -g -o Application Main.c/tmp/ccpYEJYU.o: In function `main':
    /home/kevin/Desktop/Project/Main.c:21: undefined reference to `create_list'
    collect2: ld returned 1 exit status

    My Main.c:
    Code:
    /* AUTH: Kevin Strijbos
       DATE: 26/02/2012
       
       THIS IS THE MAIN FILE OF THE PROGRAM. */
       
       #include "Bibliography.h"
    
    
    int main (int argc, char *argv[])
    {
    	FILE *fpntr;
    	REFERENCE *list; /* Head pointer for the linked list. */
    	
    	list = NULL;
    	
    	if ((fpntr = fopen(*(argv+1), "r")) == NULL) /* Open file. */
    	{
    		printf("Can't open file.\n");
    		return 1;
    	}
    	
    	create_list(&list, fpntr); /* Create the linked list. */
    	
    	return 0;
    }
    My bibliography.h:
    Code:
    /* AUTH: Kevin Strijbos
    	DATE: 26/02/2012 
    	
    	Contains the global declaration of BUFSIZE and function headers which work with the bibliography. 
    	
    	VER 1.0 */
    
    
    	#ifndef _BIBLIOGRAPHY_H_
    	#define _BIBLIOGRAPHY_H_
    
    
    	#include "Files.h"
    	#include "List.h"
    	
    	#define BUFSIZE 512 /* Global declaration of bufsize, it has to be big since we don't know how long a reference is. */
    	
    	void create_list (REFERENCE* *list, FILE *fpntr); /* Creates a linkd list of all references in the reference list. */
    	
    	#endif
    Anyone got an idea?

    Thanks in advance!

  2. #2
    Registered User
    Join Date
    May 2010
    Posts
    2,564
    Where is the function implemented?

    Jim

  3. #3
    Registered User
    Join Date
    Jan 2012
    Posts
    69
    In bibliography.c

    Code:
    Code:
    /* AUTH: Kevin Strijbos
    	DATE: 26/02/2012
    	DESC: contains functions to work with the reference list. */
    	
    	#include "Bibliography.h"
    	
    	/* Creates a linked list of the references.
    	 * @param list The list to be modified.
    	 * @param fpntr Pointer to the file from which the references have to be added. */
    	void create_list (REFERENCE* *list, FILE *fpntr)
    	{
    		char buf[BUFSIZE];
    		int eof;
    		ARTICLE article; /* Storage struct. */
    		BOOK book; /* Storage struct. */
    		REFERENCE element; /* Element which is added to the list. */
    		
    		while ((eof = read_reference(buf, fpntr)) != 1) /* Read_reference returns 1 if EOF is reached. */
    		{
    			if (decide_ref(buf) == 1) /* Decide_ref returns 1 if the reference is from an article type. */
    			{
    				article = fill_article(buf); /* Fill the article structure. */
    				fill_refART(&element, &article, buf); /* Fill the REFERENCE structure. */
    				add_element(list, &element); /* Add the element to the list. */
    			}
    			else /* Decide_ref returns 0 if the reference is from an article type. */
    			{
    				book = fill_book(buf); /* Fill the book structure. */
    				fill_refBOOK(&element, &book, buf); /* Fill the REFERENCE structure. */
    				add_element(list, &element); /* Add the element to the list. */
    			}
    		}
    	}

  4. #4
    Registered User
    Join Date
    May 2010
    Posts
    2,564
    And where is bibliography.c contained in your compile line? You may want to study this link on how to compile multiple files: An introduction to GCC.

    Jim

  5. #5
    Registered User ledow's Avatar
    Join Date
    Dec 2011
    Posts
    435
    Also, watch the capitalisation of your include filenames. You refer to it as both Bibliography.h and bibliography.h in your post and while it may not affect things on some platforms, it certainly does on others. Even Cygwin / MinGW's gcc can be case-sensitive.

    - Compiler warnings are like "Bridge Out Ahead" warnings. DON'T just ignore them.
    - A compiler error is something SO stupid that the compiler genuinely can't carry on with its job. A compiler warning is the compiler saying "Well, that's bloody stupid but if you WANT to ignore me..." and carrying on.
    - The best debugging tool in the world is a bunch of printf()'s for everything important around the bits you think might be wrong.

  6. #6
    Registered User
    Join Date
    Jan 2012
    Posts
    69
    Just before my main.

    References.h->References.c->List.h->List.c->Files.h->Files.c->Bibliography.h->Bibliography.c->Main

    And yes, I watch the capitalisation of my filenames, don't worry

  7. #7
    Registered User
    Join Date
    Jan 2012
    Posts
    69
    BTW, I compiled, linked and runned it with Visual Studio 2010, so I don't have to worry about linking. The code works fine, no problem with the files.
    So my guess is that I didn't link the files correctly in gcc?

  8. #8
    Registered User
    Join Date
    May 2010
    Posts
    2,564
    Please show your complete compile line, and the exact error messages.


    Jim

Popular pages Recent additions subscribe to a feed

Similar Threads

  1. Modular Programming Help
    By DJ_Steve in forum C Programming
    Replies: 21
    Last Post: 09-11-2009, 12:01 AM
  2. modular c programming
    By akrlot in forum C Programming
    Replies: 5
    Last Post: 10-25-2007, 07:00 AM
  3. Modular Programming
    By St0rM-MaN in forum C Programming
    Replies: 7
    Last Post: 05-10-2007, 02:56 AM
  4. modular programming
    By breaka in forum C Programming
    Replies: 4
    Last Post: 08-18-2006, 07:27 AM
  5. Modular programming
    By Longie in forum Linux Programming
    Replies: 1
    Last Post: 07-08-2003, 11:03 PM

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