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 5 2084
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
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.
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?
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
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 This thread has been closed and replies have been disabled. Please start a new discussion. Similar topics |
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 libraries. I'm not sure
if that's a good thing or not. AFAIK, most of Qt is compatable with the
Standard Library. That is, QLT can interoperate with STL, and you can
convert back and forth between std::string and Qt::QString, etc.
Are there any...
|
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
option, though that is an extremely manual and time-intensive
approach. Thanks,
--
Benjamin
|
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 instant is
implemented. This prompts two questions:
1) Is this an ANSI C feature, or just a compiler-dependent goody?
2) If it is an ANSI C feature, is there anything equivalent for
function names, rather than file names?
|
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 structures s1 and s2 look like
struct s1 {
|
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 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
| |
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
|
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) \
|
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 may be.
The data size I need for type T is offsetof(struct T, crc) +
|
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 and libraries at runtime (and
not before).
Questions:
a)How do the development tools know that a given symbol (a function entry
point, for example) is located in a shared library and won't be linked in
statically?
|
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 error if a constant
condition
is not true (or if the condition is not constant), with some
|
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, people are often confused as to whether an ONU can Work As a Router. In this blog post, we’ll explore What is ONU, What Is Router, ONU & Router’s main usage, and What is the difference between ONU and Router. Let’s take a closer look !
Part I. Meaning of...
| |
by: Oralloy |
last post by:
Hello folks,
I am unable to find appropriate documentation on the type promotion of bit-fields when using the generalised comparison operator "<=>".
The problem is that using the GNU compilers, it seems that the internal comparison operator "<=>" tries to promote arguments from unsigned to signed.
This is as boiled down as I can make it.
Here is my compilation command:
g++-12 -std=c++20 -Wnarrowing bit_field.cpp
Here is the code in...
|
by: jinu1996 |
last post by:
In today's digital age, having a compelling online presence is paramount for businesses aiming to thrive in a competitive landscape. At the heart of this digital strategy lies an intricately woven tapestry of website design and digital marketing. It's not merely about having a website; it's about crafting an immersive digital experience that captivates audiences and drives business growth.
The Art of Business Website Design
Your website is...
|
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 protocol has its own unique characteristics and advantages, but as a user who is planning to build a smart home system, I am a bit confused by the choice of these technologies. I'm particularly interested in Zigbee because I've heard it does some...
|
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, and deployment—without human intervention. Imagine an AI that can take a project description, break it down, write the code, debug it, and then launch it, all on its own....
Now, this would greatly impact the work of software developers. The idea...
|
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 presenter, Adolph Dupré who will be discussing some powerful techniques for using class modules.
He will explain when you may want to use classes instead of User Defined Types (UDT). For example, to manage the data in unbound forms.
Adolph will...
|
by: conductexam |
last post by:
I have .net C# application in which I am extracting data from word file and save it in database particularly. To store word all data as it is I am converting the whole word file firstly in HTML and then checking html paragraph one by one.
At the time of converting from word file to html my equations which are in the word document file was convert into image.
Globals.ThisAddIn.Application.ActiveDocument.Select();...
| |
by: TSSRALBI |
last post by:
Hello
I'm a network technician in training and I need your help.
I am currently learning how to create and manage the different types of VPNs and I have a question about LAN-to-LAN VPNs.
The last exercise I practiced was to create a LAN-to-LAN VPN between two Pfsense firewalls, by using IPSEC protocols.
I succeeded, with both firewalls in the same network. But I'm wondering if it's possible to do the same thing, with 2 Pfsense firewalls...
|
by: adsilva |
last post by:
A Windows Forms form does not have the event Unload, like VB6. What one acts like?
| |