| | |
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
| Thread Tools | Search this Thread |
#include * ansi append array arrays asterisks bash binarysearch centimeter changingto char character convert copyimagefile cprogramme creafecopyofanytypeoffileinc createprocess() database dynamic execv fgets file floatingpointvalidation fork framework function getlogicaldrivestrin givemetehcodez grade gtkwinlinux hacking histogram ide inches include infiniteloop initialization input interest intmain() iso kernel keyboard kilometer km license linked linkedlist linux list lists looping lowest matrix meter microsoft number oddnumber open opendocumentformat openwebfoundation overwrite owf pdf pointer pointers posix power probleminc process program programming radix recursion recv recvblocked research reversing segmentationfault sequential single socket socketprogramming standard strchr string suggestions systemcall test testing threads turboc unix urboc user variable wab whythiscodecausesegmentationfault windowsapi






