Struct Pullthrough

Aug 25, 2011 at 2:53pm
Hi there,
So I am trying to create a structure in a library that I have. The library is compiled into a 'lib.a' file. I would like a structure to be defined in a file called say: 'bla.h' within the library and ALSO be able to access this struct from a file outside the library, say 'bla2.h'

Now I already have #include "bla.h" called from within 'bla2.h' and I have functions within 'bla2.h' that require this said structure. I tried to copy/pasta the structure defn into both but gcc doesn't seem to like that and calls a structure re-definition error.

Your advice is greatly appreciated.
Aug 25, 2011 at 3:11pm
Hi,
just for the record: when you included bla.h in bla2.h, but before copying the strucutre defn into bla2.h, did it work?
can the problem be that the include directory for your second library is not set?
Aug 25, 2011 at 3:11pm
What you missing is to link your library 'lib.a' during compile time.

"gcc src-file.c -lm -lpthread
The libraries referenced in this example for inclusion during linking are the math library and the thread library. They are found in /usr/lib/libm.a and /usr/lib/libpthread.a. "


So you would do something like this
gcc -o executable-name prog.c -L/path/to/library-directory -llib

you have to put l (l for library) plus library name without extension "llib"


Aug 25, 2011 at 4:00pm
Hi guys,
ljs: I tried to include bla.h in bla2.h, but that didn't quite work.
What I ended up doing was:
-moving all relevant functions to bla2.h/bla2.c
-#include 'bla2.h' within 'bla.h'

& the problem was that the lib was not included in bla.c's Makefile defn.
Thanks for the help!
Topic archived. No new replies allowed.