473,406 Members | 2,619 Online
Bytes | Software Development & Data Engineering Community
Post Job

Home Posts Topics Members FAQ

Join Bytes to post your question to a community of 473,406 software developers and data experts.

How to obtain library name at compile/preprocessor time?

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
5 2040
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
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
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

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
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 thread has been closed and replies have been disabled. Please start a new discussion.

Similar topics

43
by: Steven T. Hatton | last post by:
Now that I have a better grasp of the scope and capabilities of the C++ Standard Library, I understand that products such as Qt actually provide much of the same functionality through their own...
15
by: Benjamin Rutt | last post by:
Are there any C tools that can find redundant #includes in a project, so as to shorten compile time? Of course, eliminating single #includes by hand and determining if the recompile fails is one...
20
by: Jim Ford | last post by:
I understand that some compilers define a symbol that can be used anywhere in the code in order to find out, at run time, the name of the file where the code corresponding to the current execution...
1
by: Dmitri Vorobiev | last post by:
Hello group, Is it possible to check the presence of a structure member at compile time using only the C preprocessor? What I have in mind could look like the following. Suppose the...
11
by: babuyama | last post by:
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...
3
by: Michael | last post by:
Hi! Is it possible to check the active solution configuration (debug, release or some user defined) at compile time using for example preprocessor directives? Best regards, Michael
14
by: Gernot Frisch | last post by:
Hi, can I use the preprocessor, using sizeof(a)/sizeof(a) to yield an error for too long strings? Like: #define CRYPT(a) \ #if sizeof(a)/sizeof(a) 31 \ xCRYPT(a) \
12
by: Ark | last post by:
Hello NG, I arrange data in structs like { members... uint16_t crc; more members, maybe... } Then I need to save them, up to and including crc, in non-volatile memory or a file, as the case...
5
by: David T. Ashley | last post by:
I've occasionally had trouble compiling and linking programs that use shared libraries. That never made a lot of sense to me, because I thought the operating system went hunting for the symbols...
11
by: Francois Grieu | last post by:
Hi, I'm using an assert()-like macro to test a constant expression at compile time #define ASSERT(condition) struct{char assert_failure;} The idea is that this macro cause a compilation...
0
by: Charles Arthur | last post by:
How do i turn on java script on a villaon, callus and itel keypad mobile phone
0
by: emmanuelkatto | last post by:
Hi All, I am Emmanuel katto from Uganda. I want to ask what challenges you've faced while migrating a website to cloud. Please let me know. Thanks! Emmanuel
0
BarryA
by: BarryA | last post by:
What are the essential steps and strategies outlined in the Data Structures and Algorithms (DSA) roadmap for aspiring data scientists? How can individuals effectively utilize this roadmap to progress...
1
by: Sonnysonu | last post by:
This is the data of csv file 1 2 3 1 2 3 1 2 3 1 2 3 2 3 2 3 3 the lengths should be different i have to store the data by column-wise with in the specific length. suppose the i have to...
0
marktang
by: marktang | last post by:
ONU (Optical Network Unit) is one of the key components for providing high-speed Internet services. Its primary function is to act as an endpoint device located at the user's premises. However,...
0
by: Hystou | last post by:
Overview: Windows 11 and 10 have less user interface control over operating system update behaviour than previous versions of Windows. In Windows 11 and 10, there is no way to turn off the Windows...
0
tracyyun
by: tracyyun | last post by:
Dear forum friends, With the development of smart home technology, a variety of wireless communication protocols have appeared on the market, such as Zigbee, Z-Wave, Wi-Fi, Bluetooth, etc. Each...
0
agi2029
by: agi2029 | last post by:
Let's talk about the concept of autonomous AI software engineers and no-code agents. These AIs are designed to manage the entire lifecycle of a software development project—planning, coding, testing,...
0
isladogs
by: isladogs | last post by:
The next Access Europe User Group meeting will be on Wednesday 1 May 2024 starting at 18:00 UK time (6PM UTC+1) and finishing by 19:30 (7.30PM). In this session, we are pleased to welcome a new...

By using Bytes.com and it's services, you agree to our Privacy Policy and Terms of Use.

To disable or enable advertisements and analytics tracking please visit the manage ads & tracking page.