From: mapson AT mapson DOT com (Mapson) Newsgroups: comp.os.msdos.djgpp Subject: Issues making and using libs Date: Thu, 05 Nov 1998 05:12:11 GMT Organization: Yale University Lines: 37 Message-ID: <364132d1.31058536@news.cis.yale.edu> NNTP-Posting-Host: psych-09.eng.yale.edu X-Newsreader: Forte Free Agent 1.1/32.230 To: djgpp AT delorie DOT com DJ-Gateway: from newsgroup comp.os.msdos.djgpp Reply-To: djgpp AT delorie DOT com I have posted a similar question to a C/C++ newsgroup, but it has occured to me that one of my questions (executable bloating) may relate directly to the fact that I am using DJGPP and the "ar" utility to make libs (".a") files from .o files. I need to make two libraries for the project I am doing now- one main one and one created out of user hardware information. The system works, but here are some questions I have about it. First of all, one of the reasons I decided to make libs instead of just putting the code directly in my source files is that I thought libs were a way of accessing only what is needed in a given program. IOW, if I have 25 functions in a lib, and my program only needs 2 of them, only the object code for two functions is extracted from the lib. Problem with my theory: the final executables made with the libs are *considerably* (20%) larger than the same programs with the raw source code (all 25 functions) built in! Even if my theory was wrong, I'd have expected them to be close in size... why are my programs so much larger by linking with the libs?! Secondly, include files have taken on a new significance with these libs. I used to keep my global variables in my header files- but in the case of these libs, they only cause "multiple declaration" errors later on- even when I uses the standard "#IFDEFINED _THIS_LIB_ ... way of only including things once. Solution was to pull all variables out of the include files, put them in the source files for the libs. Problem: I don't understand why this is true with variables and not functions- that is, the declared functions certainly don't cause any problem. There is something I am missing here in my understanding, and none of my books address this sort of stuff directly. Presently my theory is that the variables, being global, all are given a default compiler value ( globals are set to zero by default, right?), and that is why the multiple declaration errors occur- it is as if each occurance, rather than a declaration, is also a value assignment. Wrong? As usual, lease post here- no e-mail. Thanks.