Extern Function in C/C++ - Programmers Heaven

Howdy, Stranger!

It looks like you're new here. If you want to get involved, click one of these buttons!

Categories

Extern Function in C/C++

tatyakadamtatyakadam Posts: 2Member
Simple1.c
------------------------------------
#include
int f1(int x, int y)
{
printf("%d %d", x, y);
return x+y;
}
-----------------------------------


Simple2.c
------------------------------------
#include
extern int f1(int x,int y);
void main()
{
printf(" %d
", f1(5,6));
}
-----------------------------------

I was trying complie Simple1.c file then Simple2.c on Turbo C/C++ Compiler (Windows Xp). It showing following error :
Compiling Sample2.c :
Linking Sample2.exe:
Linker Error : Undefined Symbol _f1 in module Sample2.c

Can any body help me regards this.
my mail id is : [email protected]

Comments

  • AsmGuru62AsmGuru62 Posts: 6,519Member
    [color=Blue]Try to remove "extern" from function prototype. It is needed only for variables.[/color]
  • LundinLundin Posts: 3,711Member
    Actually, plain function prototypes like

    void func (void);

    are declared extern implicitly. So the above is just the same as

    extern void func (void);

    though the latter is more "stylish".

    ---

    The problem in this case is the lack of header files. Make a h-file for each c-file and put the prototypes in the h-files.
Sign In or Register to comment.