Create DLL (run-time link library) for Standard C/C++ Library - c++

Is it possible to create DLL (run-time link library) for Standard C/C++ Library like GNU Scientific Library, LibModbus, GNU Multiple Precision Arithmetic Library, LibQrEncode using Mingw that can be linked at run-time? If yes, how?
Using the make method creates files that can only be statically linked.
Why this is being done :
Separating user files/code from standard library
Multiple user program/process working independent/minimal synchronization from each other access similar set of functions but are developed by 3 separate developers
Modifying and updating files will be simpler

Related

How to use libstdc++ namespace when using libc++ as standard library? [duplicate]

I am having a difficult time configuring an iOS project which uses a static library linked against the old libstdc++ that gcc used. That library is 32 and 64-bit.
There are 6 libraries (libssl.a for example) that are 32-bit and must be updated. If I compile those libraries from source, they will be automatically linked with libc++, which will result in my linker complaining.
Therefore, here are my questions:
1) Is there any way to have a single static library inside the project use libstdc++, and have the others use libc++?
2) How can I compile libraries from source (like libcrypto and libssh) and force them use the old libstdc++ standard library?
3) Is there any other way out of this mess?
1) Yes, you can certainly mix and match which C++ runtimes your C++ code uses so long as those separate modules don't actually pass objects between each-other. For example, if you have two modules in your app which just expose C APIs but internally use C++, then each can use whichever C++ runtime they want. Problems occur when trying to share objects between the runtimes.
2) You can use the '--stdlib=libstdc++' or '--stdlib=libc++' command line argument when compiling and linking to specify which C++ library to use. If your final executable needs to link against both, you'll need to manually specify the other one (eg: --stdlib=libc++ -lstdc++).
3) Yep, but note that libstdc++ was deprecated years ago and isn't even available on watchOS nor tvOS, so your best bet is to just get everything over to libc++.
As long as you don't mix objects (like passing a string from one library into a function that expects a different kind of string), you can do it by including both libraries when you build the top-level app.
In my case, it worked by setting the standard C++ lib to the GNU version and then adding libc++ as I would any other system library.

Confused about .so version and linking strategy when distributing a api library

We have been porting our Java API to C++, and creating a library file (.a file) for Linux. Our API has dependency on the boost framework and also on log4cxx. (We discussed with the first user for this, and they are okay with those dependencies).
When I compile a sample application which uses our library file, it is linking against .so files for the dependencies (libboost_system.so, libboost_thread.so, and liblog4cxx.so). When the application runs, it needs to find the specific versioned file names for each of those .so files, e.g. liblog4cxx.so.10.
If the user is using a newer version of boost (for example), would s/he be able to link against their local version and run with that newer version (assuming bacwards compatibility)? Is there some other way to deal with versions/dependencies like these (i.e. do you try to link in the external referenced libraries to your own library)?
Yes, the program can link to newer libraries with a compatible interface. The numbers in the filename encode the library Application Binary Interface (ABI).
FreeBSD's handbook has more information about library versioning. The basic rules are:
Start from 1.0
If there is a change that is backwards compatible, bump minor number (note that ELF systems ignore the minor number)
If there is an incompatible change, bump major number
The linker will sort out the details to use the newest library version with a compatible interface. There is also more information available here on stackoverflow.

How do I create a C++ library that can be used independently of its dependencies?

Basically, I wrote a C++ library which has a number of dependencies. They are:
GNU Scientific Library for Windows
GLEW
STD (std::vector, is this even a dependency?)
I would like to be able to generate, using Visual Studio 2010, a library from this code. I would like to be able to create a new Win32 Console Application, reference the library and work with it. I don't want it to be necessary to have this new console application reference the library's dependencies as well.
I'm unsure if what I'm after is even possible. Should I create a dynamic or a static library? How should I link to it? These are sub-questions that come to mind, but I think I'm missing the big picture here.
Therefore my question is: How do I create a C++ library that can be used indepentently of its dependencies?
create wrapper functions and classes that reference these libraries? Also these other libraries have to be statically linked or if they are linked dynamically, you will have to deploy the DLLs with your application!
If all else fail, use UPX? :-) to create a single binary.

Static Linking in Fortran

I've developed a module written in C++ that manages the licenses for my company's product. To prevent DLL replacement, it is our goal to statically link the DLL in the solution. This is very easy to do in C++ but proving to be a bit problematic for part of our codebase that is written in Fortran.
I realize that this could possibly vary from compiler to compiler (We use Intel Fortran 9.1), but is there any universal way to implement static linking of a C++ DLL within Fortran?
To get static linking, the usual way is not to use DLL but simple libraries instead (*.lib). This has nothing to do with programming languages : it just depends on the operating system.
Building a library is also simpler than building a DLL. On Unix, a library has the suffix .a whereas a DLL has a suffix .so (for shared object).
Nevertheless, it is often possible to link a DLL statically but this is obtained by a specific option passed to the linker. For instance on Unix, with many compiler suites, the option is either -static or -Bstatic. Look at the keyword "static" in your programming manual of your compilers.
If you have access to the source, just compile it to object files and link them into your Fortran project. ISO_C_BINDING should work on many compilers.

Difference between C/C++ Runtime Library and C/C++ Standard Library

Can you guys tell me the difference between them?
By the way, is there something called C++ library or C library?
The C++ Standard Library and C Standard Library are the libraries that the C++ and C Standard define that is provided to C++ and C programs to use. That's a common meaning of those words, i haven't ever seen another definition of it, and C++ itself defines it as this:
The C++ Standard Library provides an extensible framework, and contains components for: language support, diagnostics, general utilities, strings, locales, containers, iterators, algorithms, numerics, and input/output. The language support components are required by certain parts of the C++ language, such as memory allocation (5.3.4, 5.3.5) and exception processing (clause 15).
C++ Runtime Library and C Runtime Library aren't so equally used. Some say a runtime library is the part that a program uses at runtime (like, the code that implements std::type_info or the code supporting signal handlers) as opposed to stuff that they only use at compile time (like macro definitions). Other people say that a runtime library is one that is linked to a program at load time dynamically, as opposed to statically at compile time, though this use is very seldom. shared library or dynamically linked library are better terms for that.
C++ Library and C Library are very broad terms. They just mean that a library is written in C++ and/or C.
The above is not only limited to C++ and/or C. There are python libraries and there is a python Standard Library too.
According to https://en.wikibooks.org/wiki/C_Programming/Standard_libraries#Common_support_libraries, there is a very important difference between Standard Library and Runtime Library. While the Standard Library defines functions that are (always) available to the programmer (but not part of the (initial) specification of the programming language, at least in C), the Runtime Library contains functions that are necessary to actually run a program on a given platform (and are platform-specific / vendor-specific).
For example, printf() is part of the C Standard Library, while program startup (which is in many cases invisible to the programmer) is implemented in the Runtime Library. So for example, you could write a C-program which does not use the Standard Library but you always need the Runtime Library because otherwise, your program could not be executed. But to be honest, this would be of little use because a C-program without the Standard Library could not do input/output so it could not tell you something about its impressive results.
What leads to confusion concerning the difference between those two is:
In every case, the Runtime Library is needed/used and in (nearly) all cases, the Standard Library is used. Furthermore, the Standard Library could be dependent on the Runtime Library and is most probably developed by the same vendor. Therefore, the distinction is not clear and in most cases not necessary.
Microsoft has put the C Standard Library and C Runtime Library together and just calls it C Run-Time Library.
C++ standard library is a term to define the standard library that a minimum conforming compiler/toolset should have. C++ runtime library is the library shipped with the toolset to provide standard library functionality, and probably some internal stuff the compiler might need. In fact, those terms are often interchangeable.
Introduction
C/C++ Standard Library is any implementation of all the required set of functionalities needed to accomplish what ISO C/C++ standard requires. (Wikipedia definition of a C++ Standard Library)
A Runtime Library is any implementation of a set of functionalities that are usually offered in form of SDK that are required to be installed or statically linked to let a program using that SDK to be run having all that it could need to use that SDK. For these reasons Runtime Library is usually strictly related to the SDK used and the compiler version used. (Wikipedia definition of a generic Runtime Library)
C/C++ Runtime Library
A C/C++ Runtime Library has thus to contain all the functionalities required to execute what is required by the Standard Library (header only functionalities of the specific Standard Library implementation can be excluded because they are resolved within the program itself) plus a set of functionalities offered by the SDK of the specific implementation (again functionalities offered as header only can be excluded).
The Microsoft Case
Before MSVC140: recent Microsoft VC++ Runtime used to have an installable version of the C/C++ Runtime (VCRedist), that version was the same for all the OSes.
Starting from MSVC140: starting from the next MSVC140 compiler, the Runtime library has been split into two parts:
UCRT (Universal C Runtime): shipped with the OS and related to it, distributed through updates or OS images
VCRedist: the part that is expected to change with the compiler being used and that is common among the different OSes versions (managed like before MSVC140).
Here is a link to MS C Runtime reference documentation.
Here is a link to MS C Runtime download page and install instructions.
C++ Standard Library consists of two main parts, namely the Standard Template Library (STL) and the runtime library. STL is implemented in header files only, while an implementation of the runtime library contains both header files and binaries (i.e., .lib and .dll files on Windows platforms).
Another aspect, maybe not exactly the case of C/C++, but according to the wikipedia: Runtime library
In computer programming, a runtime library (RTL) is a set of low-level routines used by a compiler to invoke some of the behaviors of a runtime environment, by inserting calls to the runtime library into compiled executable binary.
To be concise:
Runtime library is meant to be used by the compiler and standard library is meant to be used by the programmer.
C++ runtime library contains functions and objects supplied in C++, such as cout, fstream and so on.
C runtime library contains C functions such as printf, scanf, fopen, and so on.
The standard library is a particular set of defined names and headers as
defined in the C++ standard document, a runtime library is a blob of
binary stuff that is used as a part of the compiled program but is not
included in your program executables because it is so commonly needed.
Instead, those pieces of functionality are included on the host machine
(although you might need to ask your customers to install an updated
runtime if they have an older service pack) so they get included into
your program only at "runtime".
Ref. links:
http://msdn2.microsoft.com/en-us/library/cscc687y(VS.80).aspx
http://msdn2.microsoft.com/en-us/library/59ey50w6(VS.80).aspx