msvcprt and crt - c++

I have editbin msvcprt and look for scanf for instance but i can't find it.
Does it mean crt is not encapsulate in msvcprt ?
Does it mean cin function doesn't use scanf ?

There are two libraries: the C Run-Time library (called the "CRT") and the Standard C++ Library. The scanf function is a part of the CRT, not the Standard C++ Library.
Both the CRT and the Standard C++ Library are linked in automatically when you compile a C++ program. You can read the details about which libraries get linked in when on the C Run-Time Libraries documentation on MSDN.
In this specific case, the corresponding CRT library for the msvcprt.lib version of the Standard C++ Library (/MD / Multithreaded DLL) is msvcrt.lib.

You are using the wrong tool and the wrong file. Use dumpbin.exe and msvcrt.lib

Related

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

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

Distributed dll and c++ objects - how some libraries handle this?

Recently I found that passing/exposing objects to/from dll is dangerous if executable and dll was compiled with different compilers or even with different version of the same compiler or even with different settings of the same compiler! To say I was surprised is to say nothing - all this time I thought I can create a dynamic library and safely distribute it.
Now having this knowledge I wonder how certain libraries work? Let's take a dll in system32 folder. With dependency Walker I can see that in, say, d3d11.dll functions exposed with C parameter - I guess this is C convention which gives us a guarantee it will work. Also I know that d3d11 works with COM objects, so there's no risk of creating an object in dll and destroying it in exe.
But now let's take any Qt dll - the functions exported as c++ and have all their names mangled. I remember when I installed the framework I specified my compiler - MSVC2013, but I didn't specified a version! I can use a dll compiled with update1 compiler in update5 compiler and I can't remember any strange behavior. How it works then? How they handled mangled function name resolve, parameters passing?
The usual reason that a library under windows has to be compiled with the same compiler is that the C++ standard library is not ABI compatible between different version of MSVC++. If a library uses the C++ Standard library across the dll boundary this is ok as long as the C++ standard library is identical in the library and the compiler that uses the library.
Qt expose there own strings (QString) and vectors(QVector) etc, instead of std::string and std::vector, therefore Qt doesn't expose the C++ standard library through the dll boundary, hence the Qt dll works with all versions of Visual Studio.

Is there Something in the Standard Library or Boost to Compile a dll at Runtime?

In C# I can use CSharpCodeProvider to take in a file and compile it on the fly.
I want the same thing for C++. Essentially I'm trying to compile a .dll from a file specified at runtime and dynamically link it to the executing program.
I'm sure there's some crazy library out there that does this, but what I was hoping is that there is a library in either the Standard Library or Boost which does this. Does anyone know of one?
No, there is nothing like this in the standard library or boost.
There is however clang which is a full C++ compiler built on LLVM which is organized as a library that you can (with "some" work) use in your program.
#Perreal also pointed out correctly that if you are using C++/CLI (which is usually not included when talking about C++ in general), you can access a .NET component that will allow you to compile C++/CLI code - but not native C++ code.

How to reuse static library code which is already linked into a DLL with another C++ application in visual studio 2010?

I'm working on a C++ solution in Visual Studio 2010. I've a DLL file which is using some standard C++ library functions (such as string or file functions). For some portability reasons I have to compile this DLL with /MT option, so all required runtime library functions will be linked to the released DLL file.
I've another C++ project which is a windows application, this project also compiles with /MT option and generates an standalone exe file. The second project also uses the same standard C++ library functions that are already linked in my DLL (The executable also uses some DLL exported methods).
Now here is my question: Is there any way to tell linker that don't link common runtime functions which already linked to DLL file & don't link these shared parts again in the exe file (e.g. reuse same code for string functions which already linked to my DLL)?
No, you can't do that. Although executable depends on DLL, they can still be considered as separate and stand-alone binary artifacts, each of which should contain required symbols for proper execution.
This is one of the reasons why dynamic linking is preferred. Furthermore, I don't see any problem to link dynamically and redistribute the runtime with your application.
Although Microsoft Visual C Runtime is included on most platforms, there are many different versions of it, some of which are buggy or/and break backward compatibility. Thus, it is always a good idea to distribute the version of msvcr*.dll that you know works for sure with your application.

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