Subj : Re: Questions on compiling and using a library To : borland.public.cpp.borlandcpp From : Ed Mulroy [TeamB] Date : Mon Dec 27 2004 03:47 pm You want to use a header file which supplies function prototypes. To insure that only the functions you use are included in the build, put each in a separate source file. You also want to put header guards in the header file to defend against when it might be included multiple times - not a danger here but it is in a real world situation. So that boils down to these files: --------UTILS.H------ #ifndef UTILS_H #define UTILS_H int f1 (int x); int f2 (int x); #endif ----------F1.C----------- #include "utils.h" int f1 (int x) { return 2*x; } ----------F2.C----------- #include "utils.h" int f2 (int x) { return x**2; } ----------------------------- You would then create a library containing those files and add the library name to the project. BC++ 5.02 is from 1997 and it has been a long time since I created a library with it. If I had to do so now I'd do it from the command line. Assuming that you had the object files then you could create a library with a command like this: tlib /C libname.lib -+f1-+f2 where the '-' says to delete the old copy from the library and the '+' tells to now add the new copy. Obviously if you are only creating and not updating the library it will tell you that the old copy was not found. The '.obj' part of the name is assumed although you could put it in if you liked. When you get to a library which contains many object files you will run out of room on the command line. The way around that is to use a response file. When tlib sees a '@' character followed by a file name it takes the file name as that of a response file and uses its contents as if they came from the command line. (Note that the complers, bcc32.exe and bcc.exe as well as the linkers, ilink32.exe, tlink32.exe and tlink.exe also will accept response files.) An example using a response file would be: tlib /C libname.lib @resp.txt where the response file is RESP.TXT and contains the lines below (between the dashed lines): ----------------- -+f1 & -+ f2 ----------------- Note that the '&' is a continuation character and MUST have a space to its left. Another way to do this is with a source pool instead of with a library. You might look that up in the help. .. Ed > tazzi wrote in message > news:41d053ef$1@newsgroups.borland.com... > > I am using BC5.02 and would like some help in compiling > a group of functions into a library. My method now is not > efficient, and I would like to improve it. > > Consider a Utility library "Utils.c" which > includes functions f1 and f2. Function f > would like to make use of f1, but does not > need f2. > > Code for Utils.c: > ------------------------------------------------- > > int f1 (int x) > { > return 2*x; > } > > int f2 (int x) > { > return x**2; > } > ------------------------------------------------- > Right now, I am using the following method to > include Utils.c: > > Code for f.c: > ------------------------------------------------- > #include "Utils.c" > > int f(int x) > { > return f1(x); > } > ------------------------------------------------- > > This method produces an executable which includes > the unnecessary function f2. > > Can some one explain how to: > > 1. Compile Utils.c into a library of functions > using the IDE. > 2. Add the appropriate nodes to the Project > tree so that when function f.c is compiled > and linked, it only contains the required > function f1? .