| | |
Please help me to run my own header file
Please support our C advertiser: Programming Forums - DaniWeb Sister Site
Thread Solved |
I created my own header file in C by creating the ff. files: myfile.h, myfile.c and main.c.Afterwards, I compiled myfile.c so I already have the object file for it, but the problem is when I compiled and run main.c this error message appeared: "Undefined symbol _sum". Please help me to fix this error.See the complete source code of mine below.
// library header file: myfile.h
#ifndef MY_FILE
#define MY_FILE
int sum(int x, int y);
#endif
// library implementation file: myfile.c
#include "myfile.h"
int sum(int x, int y)
{
return x+y;
}
// Program to be run: main.c
#include<stdio.h>
#include "myfile.h"
main()
{
clrscr();
printf("The sum of 3 and 5 is %i",sum(3,5));
getch();
}
// library header file: myfile.h
#ifndef MY_FILE
#define MY_FILE
int sum(int x, int y);
#endif
// library implementation file: myfile.c
#include "myfile.h"
int sum(int x, int y)
{
return x+y;
}
// Program to be run: main.c
#include<stdio.h>
#include "myfile.h"
main()
{
clrscr();
printf("The sum of 3 and 5 is %i",sum(3,5));
getch();
}
c Syntax (Toggle Plain Text)
// call this myfile.h #include <stdio.h> int sum ( int, int ); int sum ( int x, int y ) { return x + y; }
c Syntax (Toggle Plain Text)
// Program to be run: main.c #include <stdio.h> #include "myfile.h" int main ( void ) { //clrscr(); printf ( "The sum of 3 and 5 is %i", sum ( 3, 5 ) ); getchar(); return 0; //getch(); }
Last edited by iamthwee; Jan 23rd, 2009 at 9:33 am.
*Voted best profile in the world*
![]() |
Similar Threads
- Error -> "Unable to run program file" (C++)
- Help needed badly: Problem reading from file (C++)
- Trying to get a header file to compile with source files (C++)
- Including header file in project?? (C++)
- returning a value from a header file (C++)
- graphices header file (C)
- compile header file (C++)
- Secure File Transfer Method with C++??? (C++)
- Link source code and header file together? (C++)
Other Threads in the C Forum
- Previous Thread: Arrays and Pointer Arithmetic Question
- Next Thread: linking of .c and .h files
Views: 815 | Replies: 5
| Thread Tools | Search this Thread |
Tag cloud for C
#include * append array arrays asterisks binarysearch calculate changingto char character cm command copyimagefile cprogramme creafecopyofanytypeoffileinc database directory dynamic execv feet fgets file fork forloop framework function functions givemetehcodez grade graphics gtkwinlinux hacking histogram homework include incrementoperators input intmain() iso kernel keyboard km lazy license linked linkedlist linux list lists locate logical_drives looping loopinsideloop. lowest matrix microsoft mqqueue mysql number oddnumber odf opensource overwrite owf pdf performance pointer pointers posix problem probleminc process program programming radix recursion recv recvblocked research reversing scanf scripting segmentationfault sequential socket spoonfeeding standard string student systemcall testing threads turboc unix user variable wab whythiscodecausesegmentationfault windowsapi






