| |

VerySource

 Forgot password?
 Register
Search
Author: cykppm

EXE relies on several DLLs to run, how to package DLLs in EXE

[Copy link]

0

Threads

57

Posts

27.00

Credits

Newbie

Rank: 1

Credits
27.00

 China

Post time: 2020-8-7 10:00:02
| Show all posts
3. Caused by the use of third-party libraries. This situation is mainly caused by the conflict between the C runtime function library and the MFC library. The specific method is to put the library that prompted the error in front of the other library. In addition, choosing a different C function library may cause this error. Microsoft and C have two C runtime function libraries, one is the ordinary function library: LIBC.LIB, which does not support multithreading. The other one supports multi-threading: msvcrt.lib. If these two function libraries are mixed in a project, this error may be caused. Generally, it requires the MFC library to be linked before the C runtime function library, so it is recommended to use msvcrt.lib which supports multi-threading. Therefore, before using a third-party library, you must first know what library it is linked to, otherwise it may cause LNK2005 errors. If you have to use a third-party library, you can try to modify it as described below, but there is no guarantee that the problem will be solved. The first two methods are provided by Microsoft:
A. Select the VC menu Project->Settings->Link->Catagory, select Input, and then fill in the libraries you need to ignore in the Edit column of Ignore libraries, such as: Nafxcwd.lib;Libcmtd.lib. Then fill in the correct order of the libraries in the Edit column of Object/library Modules, here you need to be able to determine what the correct order is, hehe, God bless you!
B. Select the VC menu Project->Settings->Link page, and then enter /verbose:lib in the Edit column of Project Options, so that you can see the order of the link in the output window during the process of compiling the linker.
C. Select the VC menu Project->Settings->C/C++ page, Catagory selects Code Generation and then selects MultiThread DLL and other libraries in User Runtime libraray, and try them one by one. These are the several situations of LNK2005 errors that I have encountered. There are definitely other situations that may cause this kind of error, so I don’t want you to stay still when you encounter LNK2005 errors after reading this article. Thinking of thinking about correcting the mistakes. The process of programming is a process of thinking, so it is better to start your mind more, that way you will gain more!
=======================================
Support, I have also seen many LINK 2005 errors in the community
One thing to add is that when using a third-party library once, because errno was redefined, it could not be solved by many methods. After looking up MSDN, I found that link has an option /FORCE that can be solved, under IDE
Project->Settings->Link page, select categroy as custom, tick force file output
But there will be a warning
warning LNK4088: image being generated due to /FORCE option; image may not run
But it does solve the problem. This is because VC is more strict about redefinition. Redefinitions like BCB or GCC in the library will not have any warnings or errors.
========================================
The other phenomenon that I found of LINK2005 appears to be caused by the name space. There is no problem with the program I wrote under dos, but this link error appeared in the mfc. Because it was easy to save trouble at first, I wrote using namespace std in a header file, and I used this header file in many places. In addition, I also used the boost library. Later, the method of solving the problem was very strange. When I quoted other header files in a header file, the order of these header files was changed. I used std::map in the header file with the problem. When I put this After the container is replaced with a template, the link will be fine. (For example: template<class coll>), later I felt that template technology still has this effect, I earned it! Haha
========================================
What are the C and C++ libraries my program would link with?
                      Summary Table

Compile Old New IOStream Libraries Option IOStream or STL Linked With
  
/ML No No LIBC.LIB
/MLd No No LIBCD.LIB
/MT No No LIBCMT.LIB
/MTd No No LIBCMTD.LIB
/MD No No MSVCRT.LIB
/MDd No No MSVCRTD.LIB
/ML No Yes LIBC.LIB, LIBCP.LIB
/MLd No Yes LIBCD.LIB, LIBCPD.LIB
/MT No Yes LIBCMT.LIB, LIBCPMT.LIB
/MTd No Yes LIBCMTD.LIB, LIBCPMTD.LIB
/MD No Yes MSVCRT.LIB, MSVCPRT.LIB
/MDd No Yes MSVCRTD.LIB, MSVCPRTD.LIB
/ML Yes No LIBC.LIB, LIBCI.LIB
/MLd Yes No LIBCD.LIB, LIBCID.LIB
/MT Yes No LIBCMT.LIB, LIBCIMT.LIB
/MTd Yes No LIBCMTD.LIB, LIBCIMTD.LIB
/MD Yes No MSVCRT.LIB, MSVCIRT.LIB
/MDd Yes No MSVCRTD.LIB, MSVCIRTD.LIB



Your program uses the /ML compilation option, and the .lib that the program depends on may be compiled with the /MDd option, causing a link conflict. The unified compilation option can avoid this error
Project Settings->C/C++ Tab->Category:CodeGeneration
Select Multithread Dll (or Debug Multithread Dll) in the Use run-time library combo box

Summary Table for CRT DLLs Used
Import Library Linked With DLLs Used (Visual C++ 5.0|6.0) DLLs Used (Visual C++ 4.2) DLLs Used (Visual C++ .NET 2002| Visual C++ .NET 2003)
MSVCRT.LIB MSVCRT.DLL MSVCRT.DLL MSVCRT.DLL
MSVCRTD.LIB MSVCRTD.DLL MSVCRTD.DLL MSVCRTD.DLL
MSVCPRT.LIB MSVCP(5|6)0.DLL MSVCP7(0|1).DLL
MSVCPRTD.LIB MSVCP(5|6)0D.DLL MSVCP7(0|1)D.DLL
MSVCIRT.LIB MSVCIRT.DLL MSVCIRT.DLL
MSVCIRTD.LIB MSVCIRTD.DLL MSVCIRTD.DLL


Note: All related projects should select the same compilation options
========================================
Information found in Microsoft's MSDN

Possible cause Inadvertently link with single-threaded library and multi-threaded library at the same time. Ensure that the application project file only includes the appropriate libraries, and any third-party libraries have been appropriately created for single-threaded or multi-threaded versions.
This symbol is a wrapper function (created by compiling with /Gy), which is included in multiple files, but has changed between compilations. Recompile all files containing symbol.
The symbol is defined in different forms in two member objects in different libraries, and these two member objects are used.
An absolute symbol is defined twice, and the value defined each time is different.
The header file declares and defines variables. Possible solutions are:
Declare the variable in .h: extern BOOL MyBool;, and then assign it in the .c or .cpp file: BOOL MyBool = FALSE;.
Declare the variable as Static.
Declare the variable as selectany.
When using uuid.lib with other .lib files that define GUIDs (such as oledb.lib and adsiid.lib). E.g:
oledb.lib(oledb_i.obj): error LNK2005: _IID_ITransactionObject
already defined in uuid.lib(go7.obj)
To fix it, add /FORCE:MULTIPLE to the linker command line options and make sure uuid.lib is the first library referenced. For more information, please refer to the Knowledge Base article: Q148652, PRB: LNK2005 Errors When Link C Run-Time Libraries Are Linked Before MFC Libraries.
Q140440, FIX: Global Overloaded Delete Operator Causes LNK2005.
Q184235, PRB: LNK2005 Errors on New and Delete When Defining _ATL_MIN_CRT.
This error is followed by the fatal error LNK1169.
=======================================
Sometimes because the project uses pre-compiled header files and incremental compilation, there may be an LNK2005 error after you make changes, prompting the message "XXXX has been defined in the XXXX.obj file". At this time, as long as Rebuild All is generally Can solve the problem. This is caused by operations such as changes in the order of the header files.
The last thing to explain: things are constantly changing, C++ standards are changing, and compilers are also changing, so not all LNK2005 errors can be answered here, but at least it can give you hints. Learning and thinking is the right thing!
Reply

Use magic Report

1

Threads

11

Posts

9.00

Credits

Newbie

Rank: 1

Credits
9.00

 Invalid IP Address

 Author| Post time: 2020-8-7 11:30:01
| Show all posts
Thank you!
Reply

Use magic Report

0

Threads

1

Posts

2.00

Credits

Newbie

Rank: 1

Credits
2.00

 China

Post time: 2020-9-4 11:45:01
| Show all posts
To use dynamic links. For static linking, copy all the dynamic libraries your program depends on.
In addition, Windows has its own runtime library. In systeme32, the program can be automatically searched.
It may be a problem with the link attribute settings of your compilation. It is recommended to check.
Reply

Use magic Report

You have to log in before you can reply Login | Register

Points Rules

Contact us|Archive|Mobile|CopyRight © 2008-2023|verysource.com ( 京ICP备17048824号-1 )

Quick Reply To Top Return to the list