Thread: Implicit Declaration Of Function

  1. #1
    Trying to Learn C nathanpc's Avatar
    Join Date
    Jul 2009
    Location
    Brazil
    Posts
    72

    Exclamation Implicit Declaration Of Function

    Hello,
    I've just organized my code by using headers, but just as I've done this, I got a warning that turned into an error when linking.

    I have a code(use of a function that is inside a header) in test.c that is like this:
    Code:
    #include "test1.h"
    
    /* Some code */
    main()
    {
       Testing();
    }
    And my test1.h header is like this:
    Code:
    void Testing();
    void print(int, int, int, const char*);
    And at test1.c
    Code:
    void Testing()
    {
       print(0xF9, 27, 5, "\xC9\\xBB");
    }
    
    void print(int colour, int x, int y, const char *string)
    {
       volatile char *video=(volatile char*)0xB8000 + y*160 + x*2;
       while(*string != 0)
       {
          *video=*string;
          string++;
          video++;
          *video=colour;
          video++;
       }
    }
    When I try to compile the code, I got this:
    Code:
    ubuntu@eeepc:~/Development/Test$ gcc -o test.o -c test.c -Wall -Wextra -nostdlib -nostartfiles -nodefaultlibs
    test.c: In function ‘main’:
    test.c:11: warning: implicit declaration of function ‘Testing’
    ubuntu@eeepc:~/Development/Test$
    At the time it's just a simple warning, but when I try to link it...
    Code:
    ubuntu@eeepc:~/Development/Test$ ld -T linker.ld -o kernel.bin loader.o test.o
    test.o: In function main':
    test.c:(.text+0xfc): undefined reference toTesting'
    What I need to do?

    Best Regards,
    Nathan Paulino Campos
    Follow Me At Twitter
    Eee PC 904HD White | Windows XP Home Edition and Linux Ubuntu Hardy Herron

    Google Talk: [email protected]
    ICQ: 424738586
    AIM: nathanjava

  2. #2
    spurious conceit MK27's Avatar
    Join Date
    Jul 2008
    Location
    segmentation fault
    Posts
    8,300
    Quote Originally Posted by nathanpc View Post
    What I need to do?
    What do you want to do?

    Just combine test.h into test1.c and compile like this:

    gcc -o myprog test.c test1.c
    C programming resources:
    GNU C Function and Macro Index -- glibc reference manual
    The C Book -- nice online learner guide
    Current ISO draft standard
    CCAN -- new CPAN like open source library repository
    3 (different) GNU debugger tutorials: #1 -- #2 -- #3
    cpwiki -- our wiki on sourceforge

Popular pages Recent additions subscribe to a feed

Similar Threads

  1. In over my head
    By Shelnutt2 in forum C Programming
    Replies: 1
    Last Post: 07-08-2008, 06:54 PM
  2. Replies: 15
    Last Post: 11-11-2007, 10:40 AM
  3. Implicit declaration of function : wait()
    By husust in forum C Programming
    Replies: 2
    Last Post: 02-06-2006, 09:35 AM
  4. cannot start a parameter declaration
    By Dark Nemesis in forum C++ Programming
    Replies: 6
    Last Post: 09-23-2005, 02:09 PM
  5. Contest Results - May 27, 2002
    By ygfperson in forum A Brief History of Cprogramming.com
    Replies: 18
    Last Post: 06-18-2002, 01:27 PM