Use MFC in a static library option in Visual Studio - visual-studio-2017

I'm trying to link my code (a DLL project) against mbedtls library with "Use MFC in a Static Library" option (Project settings -> General -> Use of MFC) and getting "unresolved external symbol" errors (the functions are from advapi32.lib). If I add advapi32.lib to the linker input, the code links fine, but dependency walker shows me dependence in advapi32.dll... kind of loosing the point of "static linkage". It seems that this option only replaces the /MD flag by /MT and only statically links the runtime lib code... What am I missing here?
When compiling mbedtls lib I choose "Use MFC in a Static Library" and build in Debug mode (static lib).
When compiling my code I choose "Use MFC in a Static Library" and build in Debug mode (DLL).
Thanks!

Related

Why is "Use MFC in a Static Library" setting not followed when building a DLL with VS 2008?

My goal is to create an MFC/C++ DLL that does not have any dependencies other than the basic Win32 DLLs. So I chose "Use MFC in a Static Library" setting in the project properties -> General -> Use of MFC:
but when I build this DLL and check the result with the Dependency Walker I get this:
Showing dependencies on the following MFC Dlls:
MFC90U.DLL
MSVCR90.DLL
MSVCP90.DLL
So what am I doing wrong here?
PS. I'm using Visual Studio 2008
I think I got it. What messed me up was the project setting in C++ -> Code Generation -> Runtime Library. It was changed to Multi-threaded DLL (/MD) and then the following was added to the stdafx.h file:
#define _AFXDLL
So to make it statically link to MFC libraries, I had to change the first setting to Multi-threaded (/MT) and comment out the second one.

Build a C++ binary w/o dll dependency

I wrote some C++ code. I sent it to my friend who isn't a developer. On windows 7 he got the error "the program can't start because msvcr120.dll is missing"
How can I build it so it will run? Do I need to use compile using MSVC 2008? 2005? I'd like this to work on vista+
I think you can statically link the run time library using /MT instread of /MD
see http://msdn.microsoft.com/en-us/library/2kzt1wy3.aspx
Right Click your project -> Properties -> C/C++ -> Code Generation -> Set "Runtime Library" to "/MTd" for debug and "/MT" for release builds

Dll with MFC and static linking [duplicate]

This question already has answers here:
#error Please use the /MD switch for _AFXDLL builds
(2 answers)
Closed 8 years ago.
I have dll using MFC and I need it to work on another computer without additional instalations.
If "C/C++ -> Code Generation -> Runtime Library" is Multi-threaded DLL (/MD) and "General -> Use of MFC" is set to Use MFC in a Shared DLL - my dll needs msvcr80.dll.
If "General -> Use of MFC" is set to Use MFC in a Static Library and "C/C++ -> Code Generation -> Runtime Library" to Multi-threaded (/MT) - I have an error
#error Please use the /MD switch for _AFXDLL builds
Is there any solution? I'd appreciate any help. I'm searching the answer for a long time and in many places it is said that the second variant should work without errors.
You should build your client in the same mode as library your link with.
Librarian warns you about that. So to resolve the error - build your client that uses MFC lib with /MD flag instead of /MT
MFC extension DLLs must be linked with the DLL version of MFC. Only MFC apps can be statically linked to the MFC framwwork.

I can't build a static executable in RAD Studio C++ Builder XE

I need to build my C++ Builder XE project with linked static library so I can get a large executable file in the Project's Debug\Win32 directory but I can't.
Everytime I try to build my project, it doesn't builds the executable with the Runtime Library whereas I have set the Project's Option to disable the "Link with Dynamic RTL" and enable the "Build with runtime packages" like this:
What's going wrong here?
Any idea?
Thank a lot in advance.
You need to turn OFF both the "Link with Dynamic RTL" and the "Build with runtime packages" options. Dynamic RTL and Runtime packages are all external DLLs.

MSVC is linking to release libraries in debug build instead of debug versions

I am using Microsoft Visual Studio 2008 (C++). I am having a solution which I want to build in debug mode. I am referencing some third party libraries (e.g. MyGUI). By the end of the debug build the linker gives a fatal error (LNK1104) that "MyGUIEngine.lib" cannot be found. So actually in debug mode the linker should link to "MyGUIEngine_d.lib". Why does it look for the release version of this library?
I am building Multithreaded-Debug-DLL (/MDd).
The "C/C++" -> "Code Generation" -> "Runtime Library" setting (which you have set to "Multi-Threaded Debug DLL") controls what version of the C and C++ runtime you compile and link against, and has nothing to do with 3rd party libraries (such as "MyGUIEngine").
To change the version of "MyGUIEngine" you link to, change the value in "Linker" -> "Input" -> "Additional Dependancies" to "MyGUIEngine_d.lib" for the Debug configuration, and "MyGUIEngine.lib" for the Release configuration.