From: "John M. Aldrich" Newsgroups: comp.os.msdos.djgpp Subject: Re: Library Problem ! Help ! Date: Sun, 14 Dec 1997 21:14:17 +0000 Organization: Two pounds of chaos and a pinch of salt Lines: 49 Message-ID: <34944C29.5D7A@cs.com> References: <66v8v3$8s2$1 AT duke DOT telepac DOT pt> Reply-To: fighteer AT cs DOT com NNTP-Posting-Host: ppp243.cs.com Mime-Version: 1.0 Content-Type: text/plain; charset=us-ascii Content-Transfer-Encoding: 7bit To: djgpp AT delorie DOT com DJ-Gateway: from newsgroup comp.os.msdos.djgpp Precedence: bulk Hugo Jose Ferreira wrote: > > My question is: HOW CAN I FIX THIS !!!! Maybe putting all the functions in > the header file ISN'T the proper way of doing a library... But... my > question is: how can I tell the linker to not include the functions I'm not > using ?!?!? Putting functions into header files is NEVER the proper way of doing a library. Gcc's linker always includes all code in each object file that is passed to it into the final executable. There is no way around this; it's the way it's designed. However, if you put the functions that you may or may not want linked into a library in the proper way, then the linker will only link those object files in the library that contain symbols that are used by your code. This means that in order to achieve maximum efficiency, you must break your code down into individual source files, each of which contains a single function and any local or static variables needed by that function. So, if you have functions "waitvretrace()" and "copyscr()" that you may not want used in all your programs, you would split them up into source files, like so: waitvret.c (contains code for waitvretrace()) copyscr.c (contains code for copyscr()) Then you would compile them to object code: gcc -Wall -g -O2 -c waitvret.c gcc -Wall -g -O2 -c copyscr.c Then you would put them into a library: ar rvs libmygfx.a waitvret.c copyscr.c To link with the resulting library, use the following command line: gcc -Wall -g -O2 -o myprog.exe myprog.c -L. -lmygfx Hope this helps! -- --------------------------------------------------------------------- | John M. Aldrich | "Courage is the complement of fear. | | aka Fighteer I | A man who is fearless cannot be | | mailto:fighteer AT cs DOT com | courageous. (He is also a fool.)" | | http://www.cs.com/fighteer | - Lazarus Long | ---------------------------------------------------------------------