By using this site, you agree to our updated Privacy Policy and our Terms of Use. Manage your Cookies Settings.
449,364 Members | 1,764 Online
Bytes IT Community
+ Ask a Question
Need help? Post your question and get tips & solutions from a community of 449,364 IT Pros & Developers. It's quick & easy.

How to obtain library name at compile/preprocessor time?

P: n/a
Hi,
Is there a way to obtain library name at compile/preprocessor time?

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

Sep 30 '05 #1
Share this Question
Share on Google+
5 Replies


P: n/a
babuyama wrote:
Hi,
Is there a way to obtain library name at compile/preprocessor time?

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?


There is no way. Think about it, your code is compiled *before* it goes
into a library. The compiler is not psychic, it does not know what
library you are going to put the object file into.

john
Sep 30 '05 #2

P: n/a
Not portably. If you know your compiler toolchain you can do that.

Example 1: if you have sourcecode of your compiler and linker, go ahead
and knock yourself out.

Example 2: you can write own preprocessor, which your makefile,
solution, workspace what not calls before compiling and linking to
create a header file which contains the definition, which is then
included whereever you need this definition.. sounds ankward? You bet
right on the money.

Sep 30 '05 #3

P: n/a
Thanks for the replies. In general, I agree that if the compilation
step does not have the a-priori knowledge of the library it is going to
be part of - then it cann't know the library name.

But, in my case, during the build process, I know what source files
belong to what library. So, I was wondering if there is any compiler
flag that can be used to pass the library name on the compile line,
which will be available in the source file?

Sep 30 '05 #4

P: n/a

babuyama wrote:
Thanks for the replies. In general, I agree that if the compilation
step does not have the a-priori knowledge of the library it is going to
be part of - then it cann't know the library name.

But, in my case, during the build process, I know what source files
belong to what library. So, I was wondering if there is any compiler
flag that can be used to pass the library name on the compile line,
which will be available in the source file?


Well, that's compiler-specific and mostly off topic in this NG.
However, one solution would be to simply supply a string as a #define
on the command line (-D with g++ for instance).

Cheers! --M

Sep 30 '05 #5

P: n/a
Do a separate compilation unit, which contains the library definitions (you
have to write your own or it can be automated by a build tool).

Then provide a header with extern declarations to those definitions.

Include the header in every other compilation units in the build process.

Ben
Oct 1 '05 #6

This discussion thread is closed

Replies have been disabled for this discussion.