Subj : Re: How to obtain library name at compile/preprocessor time? To : comp.programming From : Randy Date : Fri Sep 30 2005 04:35 pm babuyama wrote: > Hi, > Is there a way to obtain library name at compile/preprocessor time? Yes, from the command line: "gcc myfile.c -L... -l..." Otherwise, no. > > Assuming that the compilation unit, myfile.c is part of mylib.a, from > myfile.c code at compile/preprocessor time, I would like to know that > the library name is "mylib". I could not find an equivalent of > __FUNCTION__, __FILE__ defines for getting the library name. Is there > another way? > Thanks, > Babu The tradition for 99% of modern compilers is to place only object files in libraries, not source files (myfile.o but not myfile.c). After compilation, the libraries' objects are accessed by the linker to build the final executable. The compiler (and its preprocessor) is never aware of the contents of libraries, but the linker must be. Some exceptions to this are: 1) Macro repositories like C++'s STL, which are composed of source code, not object files, or 2) Inter-procedural scope optimized code (-O3 or -IPO), where the compiler needs to know something about the procedures that are being called by the procedure being compiled (or that call it), or 3) Languages like Ada that do global program verification and validation, or like Fortran 90, which needs to refer to type or module info that's not present in the current source file. In C/C++, the latter is accomplished using include files. Randy .