How to compile library on C using GCC? -
i made library files pila.h
, pila.c
. compile file pila.c
gcc pila.c -c
, library works fine. have tested it.
then made library. library has files pila_funciones_extra.h
, pila_funciones_extra.c
. in library need include first library. in file pila_funciones_extra.h
set next line include it:
# include "pila.h"
and in file pila_funciones_extra.c
set next line:
# include "pila_funciones_extra.h"
as has be.
but when seek compile file pila_funciones_extra.c
compiler doensn't recognize inclusion of library pila
. says functions, structures, constants , macros defined in library pila
haven't been defined.
i tried compile gcc pila_funciones_extra.c -c
, gcc pila_funciones_extra.c -c pila.o
doesn't work.
i made sure files in same folder.
i'm working on ubuntu.
can tell me right way compile it?
first, take habit compile -wall
(and perhaps also -wextra
more warnings) alternative gcc
; gives warnings, , should improve code till no warnings given.
then want able debug code, pass -g
gcc
. 1 time confident code inquire gcc
produce optimized machine code -o2
. larn utilize gdb
debugger.
so compile first library, assuming source files first1.c
, first2.c
in firstlib/
directory, e.g.
cd firstlib/ gcc -wall -g -c first1.c -o first1.o gcc -wall -g -c first2.c -o first2.o
at point, should utilize makefile
, larn how utilize make
, in particular because want libfirst.a
ar ruv libfirst.a first1.o first2.o ranlib libfirst.a
then can pass -l../firstlib -lfirst
lastly options gcc
command compiling , linking programme using libfirst.a
then compile sec library having makefile
in directory secondlib/
should contain
# in secondlib/makefile cc=gcc cflags= -i../firstlib/ -wall -g ## add together other stuff create
etc etc. want larn how utilize make
, write own makefile
-s take time read gnu create documentation.
you may want pass -h
gcc
have tell included files, , may want utilize remake (in add-on & replacement of make
) debug more complex makefile
-s (notably running remake -x
). here illustration of makefile
; you'll find many others!
read program library howto
c gcc compilation include libraries
No comments:
Post a Comment