Thread: linkedlist error: undefined reference

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

    linkedlist error: undefined reference

    Code:
    #include <stdio.h>
    #include <string.h>
    #include <stdlib.h>
    #include "list_funcs.h"
    
    int main()
    {
    	struct data_node *first = NULL, *new_node, *ptr = NULL;
    	insert(&first, 9);
    	char command;
    	char name [25];
    	int key;
    	int exit = 0;
    	while(!exit)
    	{
    		printf("\nEnter list command (+-flx):");
    		scanf("%c", &command);
    		switch(command)
    		{
    			case '+':
    				printf("+ detected\nEnter key data: ");
    				scanf("%d", &key);
    				printf("What string to store? ");
    				scanf("%s", name);
    				//ptr = insert(&first, key);
    				//strcpy(ptr->name, name);
    				//printf("%s", name);
    				break;
    			default:
                        break;
    		}
    	}
    	getchar();
    }
    [Linker error] undefined reference to `insert'

    If i put the insert function within this file it doesnt throw that error.

  2. #2
    ATH0 quzah's Avatar
    Join Date
    Oct 2001
    Posts
    14,826
    Are you actually linking your files?

    gcc -o myfile myfile.c myotherfile.c myyetanotherfile.c -Wall -pedantic

    Does your header file actually contain that function's prototype?

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

  3. #3
    Registered User slingerland3g's Avatar
    Join Date
    Jan 2008
    Location
    Seattle
    Posts
    603
    Can you give us what 'list_funcs.h' contains please? I agree with quzah. The compiler needs to know all there is to know about your insert function and its parameters.

Popular pages Recent additions subscribe to a feed

Similar Threads

  1. Getting an error with OpenGL: collect2: ld returned 1 exit status
    By Lorgon Jortle in forum C++ Programming
    Replies: 6
    Last Post: 05-08-2009, 08:18 PM
  2. Undefined Reference Compiling Error
    By AlakaAlaki in forum C++ Programming
    Replies: 1
    Last Post: 06-27-2008, 11:45 AM
  3. Screwy Linker Error - VC2005
    By Tonto in forum C++ Programming
    Replies: 5
    Last Post: 06-19-2007, 02:39 PM
  4. C OpenGL Compiler Error?
    By Matt3000 in forum C Programming
    Replies: 12
    Last Post: 07-07-2006, 04:42 PM
  5. c++ linking problem for x11
    By kron in forum Linux Programming
    Replies: 1
    Last Post: 11-19-2004, 10:18 AM