Solved

Static Linking instead of using dll

Posted on 2006-07-13
5
1,178 Views
Last Modified: 2013-11-20
My MFC application  currently links dynamically to a "dll file", which I have to provide when i ship the software. The dll is a MFC dll project.

I am trying to convert the MFC Application to do a STATIC linking process instead of Dynamic Linking (with the dll or a lib file)  

Is the "Implicit Linkng" option similar to the static link option ? I am getting confused between the implicit and explicit linking methods used in Visual Studio for linking MFC projects...
http://msdn2.microsoft.com/en-us/library/253b8k2c.aspx

What is the best way to proceed in order to perform a static link when i have MFC dll and a MFC executable.

Thanks
0
Comment
Question by:hari4130
[X]
Welcome to Experts Exchange

Add your voice to the tech community where 5M+ people just like you are talking about what matters.

  • Help others & share knowledge
  • Earn cash & points
  • Learn & ask questions
  • 2
5 Comments
 
LVL 22

Accepted Solution

by:
mahesh1402 earned 350 total points
ID: 17106040
>>I am getting confused between the implicit and explicit linking methods used in Visual Studio for linking MFC projects...

In Implicit linking you link in a very small lib file that contains little more than a jump table, and at run the time OS loads the DLL and fills in the jump addresses. but if the DLL is not found your program doesn't run.

Explicit linking is awkward but gives you flexible control.  You have to load the DLL yourself (LoadLibrary) and get and use function pointers to the functions you wish to call (GetProcAddress).  But your program can run without the DLL, you can select which DLL to load at run time and you can select when and if the DLL is loaded.  It is a primitive form of a "plug-in" option.

In static linking, the linker gets all the referenced functions from the static link library and places it with your code into your executable. Using DLLs instead of static link libraries makes the size of the executable file smaller. Dynamic linking is faster than static linking. but in static mfc linking you don't have to redistribute mfc*.dll etc with program.

If you statically link to the MFC code library, your .DLL will incorporate within itself all the MFC code it needs. Thus, it will be a larger .DLL, but it won't be dependent on the client computer having the proper MFC code library .DLL. If you can't rely on the host computer having the right version of MFC available, this is the way to go. If your application users are all within your own company, and you have control over what versions of the MFC .DLLs are lurking on their computers, or if your installation program also loads the right MFC .DLL, this might not be an issue.

http://www.codeguru.com/cpp/cpp/cpp_mfc/tutorials/article.php/c4017/
http://www.codeguru.com/cpp/cpp/cpp_mfc/tutorials/article.php/c4019/

-MAHESH
0
 
LVL 22

Expert Comment

by:mahesh1402
ID: 17106058
>>What is the best way to proceed in order to perform a static link when i have MFC dll and a MFC executable.

Creating Static-linked Executables using VC++ :http://www.codeproject.com/dll/staticlink.asp <====

-MAHESH
0
 
LVL 5

Expert Comment

by:bastibartel
ID: 17172326
Hi there,

If I understand your question right, you would like to link statically to some library (DLL) that you currently have to ship along.
That is not possible, unless you can rebuild that library, i.e. have te source code at hand.
If you do, you must turn the DLL project into a static library project - ask along if that is an option for you.

The 'link statically/dynamically' option in DevStudio refers to the actual MFC libraries only, that is to the parts that represent MFC functionality.
It has nothing to do with other libraries, may they be your own or third party, and may they be using MFC or not.

The only concern of yours will be, that programs that are linked to MFC dynamically will usually not work with DLL's linked statically to MFC (and vice versa)
But that is currently not your problem I suppose.

Cheers,
Sebastian


0

Featured Post

Database Solutions Engineer FAQs

In this series, we will discuss common questions received as a database Solutions Engineer at Percona. In this role, we speak with a wide array of MySQL and MongoDB users responsible for both extremely large and complex environments to smaller single-server environments.

Question has a verified solution.

If you are experiencing a similar issue, please ask a related question

If you use Adobe Reader X it is possible you can't open OLE PDF documents in the standard. The reason is the 'save box mode' in adobe reader X. Many people think the protected Mode of adobe reader x is only to stop the write access. But this fe…
Have you tried to learn about Unicode, UTF-8, and multibyte text encoding and all the articles are just too "academic" or too technical? This article aims to make the whole topic easy for just about anyone to understand.
This video will show you how to get GIT to work in Eclipse.   It will walk you through how to install the EGit plugin in eclipse and how to checkout an existing repository.
In this video, viewers are given an introduction to using the Windows 10 Snipping Tool, how to quickly locate it when it's needed and also how make it always available with a single click of a mouse button, by pinning it to the Desktop Task Bar. Int…
Suggested Courses

623 members asked questions and received personalized solutions in the past 7 days.

Join the community of 500,000 technology professionals and ask your questions.

Join & Ask a Question