Hi,
Perhaps this is slightly offtopic.
Coming into the Windows world from Unix.
Is there a reference on writing C++ libraries in a portable way.
For example, right now I'm sticking "__declspec(dll export)" in front of
each of my classes. I guess I can still make it work on Unix bydefing
__declspec(x) to be an empty macro, but that's embarrassing.
Is there a better solution?
Many thanks in advance!
Aaron 4 2474 aa*******@gmail .com schrieb: For example, right now I'm sticking "__declspec(dll export)" in front of each of my classes. I guess I can still make it work on Unix bydefing __declspec(x) to be an empty macro, but that's embarrassing.
Is there a better solution?
Normally this __declspec() stuff is already in a global #define
because in most cases you use the same header for compiling the
library (this needs __declspec(dlle xport)) and for using the library
(this needs __declspec(dlli mport)). So the class definitions normally
contain something like this:
#ifdef BUILD_LIB
#define LIB_CLASS __declspec(dlle xport)
#else
#define LIB_CLASS __declspec(dlli mport)
#endif
class LIB_CLASS MyClass {
// ...
};
If you now want to have portable libraries you must just extend the
LIB_CLASS macro. For most Unix compilers you would leave it blank.
Note: you need to define this macro just on one single place in the
entire project, so it's not really much effort.
T.M.
Another way of writing portable code is not to export classes. Try to use
pure abstract classes and global functions.
ben
"Torsten Mueller" <de******@share d-files.de> wrote in message
news:u4******** ***@fastmail.fm ... aa*******@gmail .com schrieb:
For example, right now I'm sticking "__declspec(dll export)" in front of each of my classes. I guess I can still make it work on Unix bydefing __declspec(x) to be an empty macro, but that's embarrassing.
Is there a better solution?
Normally this __declspec() stuff is already in a global #define because in most cases you use the same header for compiling the library (this needs __declspec(dlle xport)) and for using the library (this needs __declspec(dlli mport)). So the class definitions normally contain something like this:
#ifdef BUILD_LIB #define LIB_CLASS __declspec(dlle xport) #else #define LIB_CLASS __declspec(dlli mport) #endif
class LIB_CLASS MyClass { // ... };
If you now want to have portable libraries you must just extend the LIB_CLASS macro. For most Unix compilers you would leave it blank. Note: you need to define this macro just on one single place in the entire project, so it's not really much effort.
T.M.
"benben" <be******@hotma il.com> schrieb: Another way of writing portable code is not to export classes. Try to use pure abstract classes and global functions.
Ah, you mean native classes in the module using the library, calling
exported library functions. This is exactly what import libraries do.
Nevertheless also exported functions require __declspec(dlle xport) in
MSVC, otherwise nothing is exported. AFAIR the __declspec(dlli mport)
is redundant on functions.
T.M.
Really, there isn't a way to export stuff with a .def file?
I'm really trying to avoid "__declspec(dll export)" (b/c it is so ugly). This thread has been closed and replies have been disabled. Please start a new discussion. Similar topics |
by: Christian Decker |
last post by:
I was just wondering if there is a site which has a good list of
libraries that can be used to develop portable code on Mac, Linux and
Winblows.
Any ideas?
Sorry if I'm Offtopic, but I didn't know where to post it.
|
by: Xah Lee |
last post by:
Jargons of Info Tech industry
(A Love of Jargons)
Xah Lee, 2002 Feb
People in the computing field like to spur the use of spurious jargons.
The less educated they are, the more they like extraneous jargons, such
as in the Unix & Perl community. Unlike mathematicians, where in
mathematics there are no fewer jargons but each and every one are
|
by: James Harris |
last post by:
Hi,
Can someone recommend a book that will teach me how to
approach C programming so that code is modularised, will compile
for different environments (such as variations of Unix and
Windows), will be robust etc.
As an example, I am developing a BSD Sockets suite which I want
to run under various Unixes, including the Zaurus version of
Linux, and also run parts of it under Windows. My thought is to
|
by: Jason Curl |
last post by:
Dear C group,
I'm very interested in writing portable C, but I only have GNU, Sparc
and Cygwin to compile on.
What I find is the biggest problem to writing portable C is what headers
to include. What sites do people know about that are comprehensive in
their differences?
For example, MacOSX complained about <string.h>. With Solaris I needed
|
by: pemo |
last post by:
Is C really portable? And, apologies, but this is possibly a little OT?
In c.l.c we often see 'not portable' comments, but I wonder just how
portable C apps really are.
I don't write portable C code - *not only* because, in a 'C sense', I
| |
by: Abubakar |
last post by:
Hi,
we are finding out ways in which we could develop libraries that could be
written in c++ in a way that we can use them in windows, linux, and mac os.
We want to write portable code, so that it could be build on mac os, linux,
and windows. The code would involve lots of multi-threading and
network/socket programming. Since I have read that vc++ 2k5 supports a lot
of standard c++ stuff, can it help me to acheive what I want or I will...
|
by: Alexandre Guimond |
last post by:
Hi.
I want to create a portable setup.py file for windows / linux for an
extension package that i need to link with external libraries (gsl and
boost). on windows i do something like this:
imaging = Extension( 'pyag.imaging._imaging',
sources = ( glob.glob(
'Source/pyag/imaging/Src/*.cpp' ) +
glob.glob(
|
by: Ramon F Herrera |
last post by:
My goal is to write a studio-type application which will initially run
on Windows, but I would like it to run on other platforms with minimum
efforts.
I have made the decision to go with C++.
Through advice obtained in this NG (thanks!) I was able to determine
the available alternatives on the most obvious component that must be
portable, i.e. the GUI library. I still have to decide among the 3 big
ones (they are 3, right?).
|
by: =?ISO-8859-1?Q?Tom=E1s_=D3_h=C9ilidhe?= |
last post by:
I need a Big Number library. I've been considering switching my
project to C++ but at the moment I'm exploring the avenue of keeping
it in C.
What's the best Big Number library for C? I need to be able to
represent the number (95 ^ 63), which is approximately (2 ^ 6.6) ^ 63,
which is about 2 ^ 416, so we're talking about maybe a 512-Bit number.
So I need to be able to do division and multiplication on a 512-Bit
number. Has anyone here...
|
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: 6302768590 |
last post by:
Hai team
i want code for transfer the data from one system to another through IP address by using C# our system has to for every 5mins then we have to update the data what the data is updated we have to send another system
| |
by: muto222 |
last post by:
How can i add a mobile payment intergratation into php mysql website.
| |