libs conflicts

MSDN 上的解释为: You are trying to link with incompatible libraries. Important    The run-time libraries now contain directives to prevent mixing different types. You’ll receive this warning if you try to use different types or debug and non-debug versions of the run-time library in the same program. For example, if you compiled one file to use one kind of run-time library and another file to use another kind (for example, single-threaded versus multithreaded) and tried to link them, you’ll get this warning. You should compile all source files to use the same run-time library. 总之,一句话, lib 之间有冲突。需要删除导入的一些 libs

版 本类 型使用的library 被忽略的library
Release 单线程libc.lib libcmt.lib, msvcrt.lib, libcd.lib, libcmtd.lib, msvcrtd.lib
多线程libcmt.lib libc.lib, msvcrt.lib, libcd.lib, libcmtd.lib, msvcrtd.lib
使用DLL的多线程msvcrt.liblibc.lib, libcmt.lib, libcd.lib, libcmtd.lib, msvcrtd.lib
Debug 单线程libcd.liblibc.lib, libcmt.lib, msvcrt.lib, libcmtd.lib, msvcrtd.lib
多线程libcmtd.liblibc.lib, libcmt.lib, msvcrt.lib, libcmtd.lib, msvcrtd.lib
使用DLL的多线程msvcrtd.liblibc.lib, libcmt.lib, msvcrt.lib, libcd.lib, libcmtd.lib

例如编译 Release 版本的单线程的工程,在 linker 的命令行加入如下的参数: /NODEFAULTLIB:libcmt.lib /NODEFAULTLIB:msvcrt.lib /NODEFAULTLIB:libcd.lib /NODEFAULTLIB:libcmtd.lib /NODEFAULTLIB:msvcrtd.lib
当然,通过 VC6.0 的开发环境也可以配置。选择 Project -> Setting ,出现 Project Setting 对话框,单击 Link 标签,在 Category 下拉菜单中选择 Input ,在下方的 Ignore libraries: 输入框中输入“ 被忽略的 library ”框中对应的 libs 。输入时注意当前 Build 是什么版本, libs 之间用“,”隔开。“ Ingore all default libraries ”不能勾选。

I find the following resource on the internet:

You are trying to link with incompatible libraries.

Important   The run-time libraries now contain directives to prevent mixing different types. You’ll receive this warning if you try to use different types or debug and non-debug versions of the run-time library in the same program. For example, if you compiled one file to use one kind of run-time library and another file to use another kind (for example, single-threaded versus multithreaded) and tried to link them, you’ll get this warning. You should compile all source files to use the same run-time library. See the Use Run-Time Library (MD, /ML, /MT, /LD) compiler options for more information.

You can use the linker’s /VERBOSE:LIB switch to determine which libraries the linker is searching. If you receive LNK4098 and want to create an executable file that uses, for example, the single-threaded, non-debug run-time libraries(/ML或者是你指定的:Single-Threaded ), use the /VERBOSE:LIB option to find out which libraries the linker is searching. The linker should print LIBC.LIB and not LIBCMT.LIB, MSVCRT.LIB, LIBCD.LIB, LIBCMTD.LIB, or MSVCRTD.LIB as the libraries searched. You can tell the linker to ignore the the incorrect run-time libraries by typing the incorrect libraries in the Ignore Libraries text box on the Link tab of the Settings dialog box in Developer’s Studio or by using the /NODEFAULTLIB:library option with LINK for each library you want to ignore. See the Ignore Libraries (/NODEFAULTLIB) linker option for more information.

The table below shows which libraries should be ignored depending on which run-time library you want to use.
//下面的表中列出了:使用什么库的时候,你需要忽略掉什么库,否则就是LNK4098的错误

To use this run-time libraryIgnore these libraries
Single-threaded (libc.lib)libcmt.lib, msvcrt.lib, libcd.lib, libcmtd.lib, msvcrtd.lib
Multithreaded (libcmt.lib)libc.lib, msvcrt.lib, libcd.lib, libcmtd.lib, msvcrtd.lib
Multithreaded using DLL (msvcrt.lib)libc.lib, libcmt.lib, libcd.lib, libcmtd.lib, msvcrtd.lib
Debug Single-threaded (libcd.lib)libc.lib, libcmt.lib, msvcrt.lib, libcmtd.lib, msvcrtd.lib
Debug Multithreaded (libcmtd.lib)libc.lib, libcmt.lib, msvcrt.lib, libcd.lib, msvcrtd.lib
Debug Multithreaded using DLL (msvcrtd.lib)libc.lib, libcmt.lib, msvcrt.lib, libcd.lib, libcmtd.lib

For example, if you received this warning and you want to create an executable file that uses the non-debug, single-threaded version of the run-time libraries, you could use the following options with the linker:

/NODEFAULTLIB:libcmt.lib 
/NODEFAULTLIB:msvcrt.lib
/NODEFAULTLIB:libcd.lib
/NODEFAULTLIB:libcmtd.lib
/NODEFAULTLIB:msvcrtd.lib


==========================================================================================

/MD, /ML, /MT, /LD   (Use Run-Time Library)




说明:上面各种指定给LINKER看的“符号”中的“M”表示“Module(模块)”之意


With these options, you can select either single-threaded or multithreaded run-time routines, indicate
that a multithreaded module is a dynamic-link library (DLL), and select the retail or debug version of
the library.

Note   Having more than one copy of the run-time libraries in a process can cause problems, because
static data in one copy is not shared with the other copy. To ensure that your process contains only
one copy, avoid mixing static and dynamic versions of the run-time libraries. The linker will prevent
you from linking with both static and dynamic versions within one .EXE file, but you can still end up
with two (or more) copies of the run-time libraries. For example, a dynamic-link library linked with
the static (non-DLL) versions of the run-time libraries can cause problems when used with an .EXE file
that was linked with the dynamic (DLL) version of the run-time libraries. (You should also avoid mixing
the debug and non-debug versions of the libraries in one process.)

Command LineProject SettingsDescription
/MDMultithreaded DLLDefines _MT and _DLL so that both multithread- and DLL-specific versions of the run-time routines are selected from the standard .H files. This option also causes the compiler to place the library name MSVCRT.LIB into the .OBJ file.
Applications compiled with this option are statically linked to MSVCRT.LIB. This library provides a layer of code that allows the linker to resolve external references. The actual working code is contained in MSVCRT.DLL, which must be available at run time to applications linked with MSVCRT.LIB.
/MDdDebug Multithreaded DLL Defines _DEBUG, _MT, and _DLL so that debug multithread- and DLL-specific versions of the run-time routines are selected from the standard .H files. It also causes the compiler to place the library name MSVCRTD.LIB into the .OBJ file.
/MLSingle-Threaded Causes the compiler to place the library name LIBC.LIB into the .OBJ file so that the linker will use LIBC.LIB to resolve external symbols. This is the compiler’s default action. LIBC.LIB does not provide multithread support.
/MLdDebug Single-Threaded Defines _DEBUG and causes the compiler to place the library name LIBCD.LIB into the .OBJ file so that the linker will use LIBCD.LIB to resolve external symbols. LIBCD.LIB does not provide multithread support.
/MTMultithreaded Defines _MT so that multithread-specific versions of the run-time routines are selected from the standard header (.H) files. This option also causes the compiler to place the library name LIBCMT.LIB into the .OBJ file so that the linker will use LIBCMT.LIB to resolve external symbols. Either /MT or /MD (or their debug equivalents /MTd or /MDd) is required to create multithreaded programs.
/MTdDebug Multithreaded Defines _DEBUG and _MT. Defining _MT causes multithread-specific versions of the run-time routines to be selected from the standard .H files. This option also causes the compiler to place the library name LIBCMTD.LIB into the .OBJ file so that the linker will use LIBCMTD.LIB to resolve external symbols. Either /MTd or /MDd (or their non-debug equivalents /MT or MD) is required to create multithreaded programs.
/LDNot applicableCreates a DLL.
Passes the /DLL option to the linker. The linker looks for, but does not require, a DllMain function. If you do not write a DllMain function, the linker inserts a DllMain function that returns TRUE.
Links the DLL startup code.
Creates an import library (.LIB), if an export (.EXP) file is not specified on the command line; you link the import library to applications that call your DLL.
Interprets /Fe as naming a DLL rather than an .EXE file; the default program name becomes basename.DLL instead of basename.EXE.
Changes default run-time library support to /MT if you have not explicitly specified one of the /M options
/LDdNot applicableCreates a debug DLL. Defines _DEBUG.

To find these options in the development environment, click Settings on the Project menu.
Then click the C/C++ tab, and click Code Generation in the Category box. See the
Use Run-Time Library drop-down box.

The debug options select the debug versions of the library or DLL and define _DEBUG.
For more information on using the debug versions, see C Run-Time Debug Libraries.

For further discussion of DLLs, see DLL Topics.


=====================================================================================
总结下:
(1)Single-Threaded----------------(/ML)
(2)Multithreaded------------------(/MT)
(3)Multithreaded------------------(/MD)
(4)Debug Single-Threaded----------(/MLd)
(5)Debug Multithreaded------------(/MTd)
(6)Debug Multithreaded DLL--------(/MDd)

======================================================================================

C Run-Time Debug Libraries

The following table lists the debug versions of the C run-time library files, along with their
associated compiler options and environment variables. For a list of the release versions of
these libraries, see C Run-Time Libraries.

Prior to Visual C++ 4.2, the C run-time libraries contained the iostream library functions.
In Visual C++ 4.2, the old iostream library functions were removed from LIBCD.LIB,
LIBCMTD.LIB, and MSVCRTD.LIB. This change was made because the Standard C++ library was added
to Visual C++, and it contains a new set of iostream libraries.

Two sets of iostream functions are now included in Visual C++. The old iostream functions now
exist in their own libraries: LIBCID.LIB, LIBCIMTD.LIB, and MSVCIRTD.LIB. The new iostream
functions, as well as many other new functions, exist in the Standard C++ libraries:
LIBCPD.LIB, LIBCPMTD.LIB, and MSVCPRTD.LIB.

The Standard C++ library and the old iostream library are incompatible and only one of them
can be linked with your project. See theStandard C++ Library Overview and
Make the Old iostream Library the Default for details.

When you build a debug version of your project, one of the basic C run-time debug libraries
(LIBCD.LIB, LIBCMTD.LIB, and MSVCRTD.LIB) is linked by default, depending on the compiler
option you choose (single-threaded, multithreaded, or DLL). Depending on the headers you use
in your code, a debug library from the Standard C++ libraries or one from the old iostream
libraries may also be linked.

  • If you include aStandard C++ library header in your code, a Standard C++ library will be
  • linked in automatically by Visual C++ at compile time. For example:
   #include <ios> 
  • If you include an old iostream library header, an old iostream library will be linked in
  • automatically by Visual C++ at compile time. For example:
   #include <ios.h>

Note that headers from the Standard C++ library and the old iostream library cannot be mixed.

Headers determine whether a Standard C++ library, an old iostream library, or neither will be
linked. Compiler options determine which of the libraries to be linked is the default
(single-threaded, multithreaded, or DLL). When a specific library compiler option is defined,
that library is considered to be the default and its environment variables are automatically
defined.

C Run-Time Debug Library (without iostream)CharacteristicsOptionDefined
LIBCD.LIBSingle-threaded, static link/MLd_DEBUG
LIBCMTD.LIBMultithreaded, static link/MTd_DEBUG, _MT
MSVCRTD.LIBMultithreaded, dynamic link
(import library for MSVCRTD.DLL)1
/MDd_DEBUG, _MT, _DLL
1   In place of the “x” in the DLL name, substitute the major version numeral of Visual C++ that you are using. For example, if you are using Visual C++ version 4, then the library name would be MSVCR40D.DLL.

Standard C++ Debug LibraryCharacteristicsOptionDefined
LIBCPD.LIBSingle-threaded, static link/MLd_DEBUG
LIBCPMTD.LIBMultithreaded, static link/MTd_DEBUG, _MT
MSVCPRTD.LIBMultithreaded, dynamic link (import library for MSVCRTD.DLL)/MDd_DEBUG, _MT, _DLL

iostream Debug LibraryCharacteristicsOptionDefined
LIBCID.LIBSingle threaded, static link/MLd_DEBUG
LIBCIMTD.LIBMultithreaded, static link/MTd_DEBUG, _MT
MSVCIRTD.LIBMultithreaded, dynamic link (import library for MSVCIRTD.DLL)/MDd_DEBUG, _MT, _DLL

The debug versions of the library functions differ from the release versions mainly in that
debug information was included when they were compiled (using the /Z7 or /Zi compiler option),
optimization was turned off, and source code is available. A few of the debug library functions
also contain asserts that verify parameter validity.

Using one of these debug libraries is as simple as linking it to your application with the
/DEBUG:FULL linker option set. You can then step directly into almost any run-time function
call.

 
  • 0
    点赞
  • 2
    收藏
    觉得还不错? 一键收藏
  • 0
    评论
评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

当前余额3.43前往充值 >
需支付:10.00
成就一亿技术人!
领取后你会自动成为博主和红包主的粉丝 规则
hope_wisdom
发出的红包
实付
使用余额支付
点击重新获取
扫码支付
钱包余额 0

抵扣说明:

1.余额是钱包充值的虚拟货币,按照1:1的比例进行支付金额的抵扣。
2.余额无法直接购买下载,可以购买VIP、付费专栏及课程。

余额充值