当前位置:网站首页>Problems needing attention when VC links static libraries
Problems needing attention when VC links static libraries
2022-07-28 10:52:00 【vv1025】
vc Project and linked static library (*.lib) The documents should be consistent :
for example : Is shared mode used MFC dll Still use static mode MFC dll?
Multi thread or single thread ?
Is it debug mode or release Pattern ?
Project attribute configuration involved /MDd And /MTd /MD /MT
If it's not consistent , Errors will be reported in the link phase , Such as :
LIBCMT.lib(invarg.obj) : error LNK2005: __initp_misc_invarg Already in libcmtd.lib(invarg.obj) In the definition of
Or the function cannot be parsed
attach (ZT)
1、VC Compilation options
Multithreading (/MT)
Multithreaded debugging (/MTd)
Multithreading DLL (/MD)
Multithreaded debugging DLL (/MDd)
2、C Runtime library The library files
Single thread(static link) ML libc.lib
Debug single thread(static link) MLd libcd.lib
MultiThread(static link) MT libcmt.lib
Debug multiThread(static link) MTd libcmtd.lib
MultiThread(dynamic link) MD msvcrt.lib
Debug multiThread(dynamic link) MDdmsvcrtd.lib
3. Various C The difference between runtime libraries
(1) Statically linked one-way Library
Statically linked one-way libraries can only be used for single threaded applications , C The object code of the runtime library is finally compiled in the binary file of the application . adopt /ML Compilation options can be set Visual C++ Using statically linked one line Libraries .
(2) Statically linked multithreaded Library
The object code of the statically linked multithreading library is finally compiled in the binary file of the application , But it can be used in multithreaded programs . adopt /MT Compilation options can be set Visual C++ Use statically linked multithreading libraries .
(3) Dynamic link runtime library
Dynamically linked runtime libraries will all C Library functions are stored in a separate DLL MSVCRTxx.DLL in ,MSVCRTxx.DLL Dealing with multithreading . Use /MD Compilation options can be set Visual C++ Run time libraries using dynamic links .
/MDd 、 /MLd or /MTd Option to use Debug runtime library( Debug version of the runtime library ), And /MD 、 /ML or /MT They correspond to each other . Debug Version of Runtime Library Contains debugging information , And some protection mechanisms are used to help find errors , Enhanced error detection , So it can't compare with Release edition .
4、 Here is msdn About Visual C++ Description of compiler options :
These options select single threaded or multi-threaded runtime routines , Indicates whether the multithreaded module is DLL, And select the release version or debug version of the runtime library .
(1) /MD Definition _MT and _DLL So that at the same time from the standard .h File to select a multithreaded specific version of the runtime routine and DLL Specific version . This option also causes the compiler to change the library name MSVCRT.lib Put in .obj In file . Applications compiled with this option are statically linked to MSVCRT.lib. The library provides a layer of code that allows the linker to resolve external references . The actual working code is contained in MSVCR71.DLL in , The library must be run-time for MSVCRT.lib Linked applications are available . When you define _STATIC_CPPLIB (/D_STATIC_CPPLIB) In case of use /MD when , It will cause applications to pass the static multithreading standard C++ library (libcpmt.lib) Not the dynamic version (msvcprt.lib) Link , Still pass at the same time msvcrt.lib Dynamically link to the main CRT.
(2) /MDd Definition _DEBUG、_MT and _DLL, From the standard .h File to select the debug multithread specific version of the runtime routine and DLL Specific version . It also enables the compiler to change the library name MSVCRTD.lib Put in .obj In file .
(3) /ML Make the compiler change the library name LIBC.lib Put in .obj In file , So that the linker can use LIBC.lib Parsing external symbols . This is the default operation of the compiler .LIBC.lib No multithreading support .
(4) /MLd Definition _DEBUG And make the compiler change the library name LIBCD.lib Put in .obj In file , So that the linker can use LIBCD.lib Parsing external symbols .LIBCD.lib No multithreading support .
(5) /MT Definition _MT, So that from the standard head (.h) File to select a multithreaded specific version of the runtime routine . This option also causes the compiler to change the library name LIBCMT.lib Put in .obj In file , So that the linker can use LIBCMT.lib Parsing external symbols . Creating a multithreaded program requires /MT or /MD( Or their debugging equivalent /MTd or /MDd).
(6) /MTd Definition _DEBUG and _MT. Definition _MT Will lead to from the standard .h File to select a multithreaded specific version of the runtime routine . This option also causes the compiler to change the library name LIBCMTD.lib Put in .obj In file , So that the linker can use LIBCMTD.lib Parsing external symbols . Creating a multithreaded program requires /MTd or /MDd( Or their non debugging equivalent /MT or MD).
(7) /LD establish DLL. take /DLL Options are passed to the linker . Linker look up DllMain function , But you don't need this function . If not written DllMain function , The linker will insert back TRUE Of DllMain function . link DLL Startup code . If no export is specified on the command line (.exp) file , Then create the import library (.lib); Link the import library to call your DLL Applications for . take /Fe Explain as naming DLL instead of .exe file ; The default program name becomes the base name .dll Not the base name .exe. If you have not explicitly specified /M One of the options , Change the default runtime library support to /MT.
(8) /LDd Create debugging DLL. Definition _DEBUG. Warning Don't mix static and dynamic versions of runtime libraries . Having multiple copies of the runtime library in a process can cause problems , Because the data in the static replica is not shared with other replicas . The linker is prohibited in .exe Both static version and dynamic version link are used inside the file , But you can still use two of the runtime libraries ( Or more ) copy . for example , When and with dynamic (DLL) Version of the runtime library is linked .exe When files are used together , Using static ( Not DLL) Version of runtime library linked dynamic link library may cause problems .( You should also avoid mixing debug and non debug versions of these libraries in a process ).
No.1 : error :Libcmtd.lib(wincrt0.obj) : error LNK2019: Unresolved external symbols [email protected], The sign is in the function ___tmainCRTStartup Cited in
resolvent :
project --> attribute --> Configuration properties --> The linker --> senior --> entry point : Fill in wWinMainCRTStartup.
No.2 : error :
1>uafxcwd.lib(afxmem.obj) : error LNK2005: "void * __cdecl operator new(unsigned int)" ([email protected]@Z) Already in LIBCMTD.lib(new.obj) In the definition of
1>uafxcwd.lib(afxmem.obj) : error LNK2005: "void __cdecl operator delete(void *)" ([email protected]@Z) Already in LIBCMTD.lib(dbgdel.obj) In the definition of
1>uafxcwd.lib(afxmem.obj) : error LNK2005: "void * __cdecl operator new[](unsigned int)" ([email protected]@Z) Already in libcpmtd.lib(newaop.obj) In the definition of
1>uafxcwd.lib(afxmem.obj) : error LNK2005: "void __cdecl operator delete[](void *)" ([email protected]@Z) Already in LIBCMTD.lib(delete2.obj) In the definition of
resolvent :
project --> attribute --> Configuration properties --> The linker --> Input --> Additional dependency : Join in
uafxcwd.lib
Libcmtd.lib
project --> attribute --> Configuration properties --> The linker --> Input --> Ignore specific default libraries : Join in
uafxcwd.lib
Libcmtd.lib
No.3: Warning :
1>c:\program files (x86)\microsoft visual studio 10.0\vc\include\stdint.h(72): warning C4005: “INT8_MIN”: Macro redefinition
1> c:\program files (x86)\microsoft sdks\windows\v7.0a\include\intsafe.h(144) : See “INT8_MIN” The previous definition of
1>c:\program files (x86)\microsoft visual studio 10.0\vc\include\stdint.h(73): warning C4005: “INT16_MIN”: Macro redefinition
1> c:\program files (x86)\microsoft sdks\windows\v7.0a\include\intsafe.h(146) : See “INT16_MIN” The previous definition of
1>c:\program files (x86)\microsoft visual studio 10.0\vc\include\stdint.h(74): warning C4005: “INT32_MIN”: Macro redefinition
1> c:\program files (x86)\microsoft sdks\windows\v7.0a\include\intsafe.h(148) : See “INT32_MIN” The previous definition of
1>c:\program files (x86)\microsoft visual studio 10.0\vc\include\stdint.h(76): warning C4005: “INT8_MAX”: Macro redefinition
resolvent :
Add... To the header file :
#ifdef _MSC_VER
#pragma warning (push)
#pragma warning (disable : 4005)
#include <intsafe.h>
#include <stdint.h>
#pragma warning (pop)
#endif
No.4: Warning :
Cancel strcpy strcpy_s These warnings .
resolvent :
project --> attribute --> Configuration properties --> C/C++ --> The preprocessor --> Preprocessor definition :_CRT_SECURE_NO_WARNINGS
Then add
#ifndef _CRT_SECURE_NO_WARNINGS
#define _CRT_SECURE_NO_WARNINGS
#endif
Reprinted from :
http://blog.sina.com.cn/s/blog_6db64b4a01010pxr.html
http://blog.csdn.net/mkr127/article/details/8555345
边栏推荐
- 剑指 Offer 09. 用两个栈实现队列
- Solving the optimal solution of particle swarm optimization
- Attention attention mechanism flow chart
- 乱打日志的男孩运气怎么样我不知道,加班肯定很多
- BOM部分属性及理解
- How to play a ball game with RoboCup 2D
- 使用statement对象执行DDL语句创建表
- GKVoronoiNoiseSource
- Development environment configuration of nodemcu
- Pyqt5 rapid development and practice 4.13 menu bar, toolbar and status bar and 4.14 qprinter
猜你喜欢
Advanced C language: pointer (1)

Markdown to word or PDF

GKCylindersNoiseSource

Characteristics and installation of non relational database mongodb

机器人技术(RoboCup 2D)如何进行一场球赛

How to play a ball game with RoboCup 2D

11_ue4进阶_男性角色换成女性角色,并修改动画

Machine learning -- handwritten English alphabet 3 -- engineering features

ICML 2022 | graph represents the structure aware transformer model of learning

粒子群解决tsp的技术问题
随机推荐
Batch Normlization
剑指 Offer 09. 用两个栈实现队列
Causes and solutions of invalid ROM table
Yan reported an error: could not find any valid local directory for nmprivate/
Advanced C language: pointer (1)
nodejs:检测并安装npm模块,如果已安装则跳过
GKPerlinNoiseSource
20200217 training match L1 - 7 2019 is coming (20 points)
GKVoronoiNoiseSource
Particle swarm optimization to solve the technical problems of TSP
网络文件系统服务(NFS)
判断数码管是共阳极还是共阴极
非关系型数据库MongoDB的特点及安装
2020 second intelligence cup preliminaries
RoboCup (2D) experiment 50 questions and the meaning of main functions
How to play a ball game with RoboCup 2D
c语言进阶篇:指针(一)
Judge whether the nixie tube is a common anode or a common cathode
剑指 Offer 30. 包含min函数的栈
GKPolygonObstacle