C++ link static library to dynamic - c++

What I'm Using:
Windows 10
C++ 20
Premake
Visual Studio 2022 (As a compiler maybe clang but for the purpose of this MSVC)
Question:
How would I approach wanting to link one library (static) into my own library (dynamic) and then be able to only ship my dynamiclib (Im on windows so dll)?
Detailed:
Basicly what I'm trying todo is put a bunch of libraries (In my case spdlog and fmt) into one large dynamic lib so i can ship it more easily as it is supposed to be a framework for working with graphical interfaces and i don't want to copy every library i used from my old project when i'm trying to start a new one.
What I Tried
I tried to staticly link libraries into my dll but for some reason there a some linking errors i cannot resolve.

Related

Firebase C++ SDK Multithreaded DLL /MD has no DLL files, Why?

On Firebase CPP SDK website, it states:
For Windows, library versions are provided based on the following:
Build platform: 32-bit (x86) vs 64-bit (x64) mode
Windows runtime environment: Multithreaded / MT vs Multithreaded DLL
/MD
Target: Release vs Debug
But the build they have provided have no DLL files, and only Lib files, when i link the Lib files, the project works fine, how is it possible that it does not ask for firebase DLL?
Donnot need dll at run time when link to a static library.
Here is what I found :
enter link description here
A static library (also known as an archive) consists of routines that are compiled and linked directly into your program. When you compile a program that uses a static library, all the functionality of the static library that your program uses becomes part of your executable. On Windows, static libraries typically have a .lib extension, whereas on linux, static libraries typically have an .a (archive) extension. One advantage of static libraries is that you only have to distribute the executable in order for users to run your program. Because the library becomes part of your program, this ensures that the right version of the library is always used with your program. Also, because static libraries become part of your program, you can use them just like functionality you’ve written for your own program. On the downside, because a copy of the library becomes part of every executable that uses it, this can cause a lot of wasted space. Static libraries also can not be upgraded easy -- to update the library, the entire executable needs to be replaced.

Visual Studio 2013 - How to link/include other libraries in my own library

I want to create library (with my own code) which will use and include other libraries. The problem is that every time i want to use it's not enough to link my library but i also have to link all libraries that are used by my own.
So if my library uses - e.g - GLFW, GLEW and others, each project that wants to use code from my own library has to link to them too.
Is there a way where i can tell compiler/linker to add those 3rd party libraries to my own so i would need only to link one?
I'm working on Visual Studio 2013 (Community) and i'd prefer to build it as static library then dynamic, but as far as i see static library project can't even link other libraries. Do i have to build it as dnamic lib? Or is there some trick to get it done?
I hope i presented the problem well enough to understand it.
In your library source code, you can try and add the following:
#pragma comment (lib, "your_other_library")
Then this will implicitly link in the library without you having to explicitly specify it using the linker settings.
http://support.microsoft.com/kb/153901

Where is the native binary app for windows today?

Well, trying to build a simple exe in visual studio 2012, with c++ win32 console app, just with a
printf("-----");
After build the release version, its running ok.
When transfer to another windows 7 clean installation, at running i get notice that the MSVCP110.DLL is missing...
Its not a native app ??? why extern dll is needed ?
In old win95 I make many executables with visual C 6 and its run standalone withou any dll.
I will always deplay this dll's with the "native" exe ?
When you write a C++ program, you use a few low-level libraries to interface with the machine. The C++ Standard Library is one example. Consider for example, new. When you call new in your program, you're invoking a piece of code that implements that functionality. Where is that actual code?
It's in a library. That library is deployed in a few different ways. One way is through dynamic linking, where the library is in the form of a DLL that needs to be present on the machine where you run your program. That's what MSVCP110.DLL is -- it's one of the library files your program was compiled against. Another way is to use static linking, where the code from that library is compiled directly in to your program. This results in a signifigant increase in the size of your application, but the other side of that coin is you don't need those library files to be on your target machine. You also need to make sure that other libraries your program use are also built against the same static library. If your program shares data with other programs, you further may need to ensure that those programs use the same static libraries.
Microsoft and Windows aren't unique in this. The same thing happens under Linux, albeit the libraries have different names.
There are pros and cons to using either shared libraries (eg dynamic linking) or static libraries. It's simple and catchy to say "gahrrr I hate shared libraries" but unless you understand why either is appropriate in what situation you stand to deploy a poorly-designed program.

How to build boost.log DLL that statically links to everything else boost?

I would like to use boost log library in my C++ project on Windows (VS 2010). Everything uses shared (DLL) runtime. Since my project contains multiple modules, I need to compile boost.log as a DLL. The trouble is, Boost.log depends on five other libraries: system, chrono, datetime, filesystem and thread. I don't want to drag 6 DLLs around, and I would like to link them statically in boost.log.
I tried to #define BOOST_LOG_DYN_LINK in config/user.hpp, but it did not help: when I build the log library it either builds as static (not what I want), or as a DLL referencing 5 other DLLs (not what I want either).
I need a log DLL that has all 5 dependencies linked statically in. Is it possible to achieve?
I think you'll want to create a separate DLL project that statically links the boost libraries you want. Probably this project won't add any other code (other than some DllMain function that does nothing), but it will give you a new DLL (e.g., boostlibs.dll) that you can dynamically link to your application.

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.