Skip to contentSkip to conversation

how to call Functions implemented in other file?

DISCUSSION houanito 2 participants 2 messages May 27, 2008

lore
Share & tools
lore

houanito

author
#0 lore raw

hello!

i have a problem using gcc c Complier in Unix.
I want to use a function which is implemented in a file in another path.This function is written by the distirbuters of the system and so the system uses this function.But i want to use that in order to do one part of my homework.
Because the file that contains this function is *.c and not *.h, adding #include *.c to my code,generates problem..

any help??thanks!

Signature · 2 lines
View this message in context: http://www.nabble.com/how-to-call-Functions-implemented-in-other-file--tp17490027p17490027.html
Sent from the linux-c-programming mailing list archive at Nabble.com.
#1 lore raw

You need to compile this other file and add it to your compile line and include the .h file for it. For instance.

/path/to/file/foo.c
/path/to/file/foo.h
/path/to/file/foo.o

/home/user/yourProgram.c

/* yourProgram.c */
#include "/path/to/file/foo.h"

...

$ gcc /path/to/file/foo.o yourProgram.c

This is a very simplified version of what you could do. Though this doesn't account for possible library requirements of this object file.
If this .c file is provided by your distibution or some other
program. There is most likely a library or something to use the functionality it has. In theory this can all work, but things are rarely designed to work this way. I would reconsider your desire to use this .c file.

Cheers,
Eric

Quoted 21 lines · houanito

hello!

i have a problem using gcc c Complier in Unix.
I want to use a function which is implemented in a file in another path.This function is written by the distirbuters of the system and so the system uses this function.But i want to use that in order to do one part of my homework.
Because the file that contains this function is *.c and not *.h, adding #include *.c to my code,generates problem..

any help??thanks!
--
View this message in context: http://www.nabble.com/how-to-call-Functions-implemented-in-other-file--tp17490027p17490027.html
Sent from the linux-c-programming mailing list archive at Nabble.com.

--
To unsubscribe from this list: send the line "unsubscribe linux-c-programming" in the body of a message to [email protected]
More majordomo info at http://vger.kernel.org/majordomo-info.html

Signature · 6 lines
"None are more hopelessly enslaved than those who falsely believe they
are free."
 --Goethe

"Freedom is living without government coercion."
 --Ron Paul (www.ronpaul2008.com)