On Sun, 11 Apr 1999, Darius Blaszijk wrote:
# Recently I came across a package witch I want to use in my programs. The
# package consists of a header file (interface) and a *.c source code file
# (implementation). How can I use these files in my application? If I try
# to compile my application the compiler gives me this message: undefined
# reference.
By your use of 'interface' and 'implementation' i'd say you've used modula-2
or pascal...
and like those languages you must tell your C compiler to include the header
file.
Assuming the header is called foo.h and the source is called foo.c. Put them
in the same directory as your c program (called bar.c in this example).
in the top of bar.c put a line like this:
(it goes along with the #include <stdio.h> and similar lines)
#include "foo.h"
this tells gcc to look in the current directory (which is what "" means. <>
means 'look in standard include locations')
then when you come to compile, type a command line like:
gcc -Wall -o bar bar.c foo.c
the -Wall just makes gcc really really picky about your code (a good thing).
-o tells it what to call the executable (the first thing after the -o) and
bar.c and foo.c are the sources to compile. You need to compile foo.c as well.
If it was given as an object file (foo.o) then you'd do something slightly
different
(
gcc -Wall -c bar.c
/* creates bar.o */
gcc -Wall -c foo.c
/* creates foo.o */
gcc bar.o foo.o -o bar
/* links them together into an executable called 'bar' */
)
--
+++ If at first you don't succeed, you must be a programmer +++
[EMAIL PROTECTED] http://www.penguinpowered.com/~a_out