[转]默认库“library”与其他库的使用冲突;使用 /NODEFAULTLIB:library

您试图与不兼容的库链接。

重要事项 运行时库现在包含防止混合不同类型的指令。如果试图在同一个程序中使用不同类型的运行时库
或使用调试和非调试版本的运行时库,则将收到此警告。例如,如果编译一个文件以使用一种运行时库,
而编译另一个文件以使用另一种运行时库(例如单线程运行时库对多线程运行时库),并试图链接它们,
则将得到此警告。应将所有源文件编译为使用同一个运行时库。有关更多信息,请参阅使用运行时库(/MD
、/ML、/MT、/LD)编译器选项。可以使用链接器的 /VERBOSE:LIB 开关来确定链接器搜索的库。如果收到
LNK4098,并想创建使用如单线程、非调试运行时库的可执行文件,请使用 /VERBOSE:LIB 选项确定链接
器搜索的库。链接器作为搜索的库输出的应是 LIBC.lib,而非 LIBCMT.lib、MSVCRT.lib、LIBCD.lib、
LIBCMTD.lib 和 MSVCRTD.lib。对每个要忽略的库可以使用 /NODEFAULTLIB,以通知链接器忽略错误的运
行时库。

下表显示根据要使用的运行时库应忽略的库。

若要使用此运行时库 请忽略这些库 
单线程 (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.lib) libc.lib、libcmt.lib、libcd.lib、libcmtd.lib、msvcrtd.lib 
调试单线程 (libcd.lib) libc.lib、libcmt.lib、msvcrt.lib、libcmtd.lib、msvcrtd.lib 
调试多线程 (libcmtd.lib) libc.lib、libcmt.lib、msvcrt.lib、libcd.lib、msvcrtd.lib 
使用 DLL 的调试多线程 (msvcrtd.lib) libc.lib、libcmt.lib、msvcrt.lib、libcd.lib、libcmtd.lib 

例如,如果收到此警告,并希望创建使用非调试、单线程版本的运行时库的可执行文件,可以将下列选项
与链接器一起使用:

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

 

 

vc2010使用libcurl静态库 遇到连接失败的解决方案
2010-11-10 15:35

下载libcurl的源码,打开lib文件夹下项目,编译为静态链接库。

在编译的时候出现问题如下:

注:以前在vc2005下用mfc工程并且libcurl用的dll方式没问题,这次vc2008用的sdk并且libcurl用的静态编译,也不知道什么问题引起的

HttpWebRequest.obj : error LNK2001: 无法解析的外部符号 __imp__curl_slist_free_all
1>HttpWebRequest.obj : error LNK2001: 无法解析的外部符号 __imp__curl_easy_cleanup
1>HttpWebRequest.obj : error LNK2001: 无法解析的外部符号 __imp__curl_easy_getinfo
1>HttpWebRequest.obj : error LNK2001: 无法解析的外部符号 __imp__curl_easy_setopt
1>HttpWebRequest.obj : error LNK2001: 无法解析的外部符号 __imp__curl_slist_append
1>HttpWebRequest.obj : error LNK2001: 无法解析的外部符号 __imp__curl_easy_init
1>HttpWebRequest.obj : error LNK2001: 无法解析的外部符号 __imp__curl_global_init
1>HttpWebRequest.obj : error LNK2001: 无法解析的外部符号 __imp__curl_easy_perform

上网查了好久找到了这个链接:

http://bobobobo.wordpress.com/2008/11/08/working-with-curl-getting-started-the-easy-way-on-win32/终于解决了问题

具体步骤就是:

1、给工程添加依赖的库:项目->属性->链接器->输入->附加依赖项,把libcurl.lib ws2_32.lib winmm.lib wldap32.lib添加进去

注意,debug配置用libcurld.lib

2、加入预编译选项:项目->属性->c/c++ ->预处理器->预处理器,把  ;BUILDING_LIBCURL;HTTP_ONLY复制进去(注意不要丢了";")

 

 

C Run-Time Library Functions for Thread Control
2010-11-10 15:45

All Win32 programs have at least one thread. Any thread can create additional threads. A thread can complete its work quickly and then terminate, or it can stay active for the life of the program.

The LIBCMT and MSVCRT C run-time libraries provide two functions for thread creation and termination: _beginthread and _endthread.

The _beginthread function creates a new thread and returns a thread identifier if the operation is successful. The thread terminates automatically if it completes execution, or it can terminate itself with a call to _endthread.

Warning   If you are going to call C run-time routines from a program built with LIBCMT.LIB, you must start your threads with the_beginthread function. Do not use the Win32 functions ExitThread and CreateThread. Using SuspendThread can lead to a deadlock when more than one thread is blocked waiting for the suspended thread to complete its access to a C run-time data structure.

The _beginthread Function

The _beginthread function creates a new thread. A thread shares the code and data segments of a process with other threads in the process, but has its own unique register values, stack space, and current instruction address. The system gives CPU time to each thread, so that all threads in a process can execute concurrently.

The _beginthread function is similar to the CreateThread function in the Win32 API but has these differences:

  • The _beginthread function lets you pass multiple arguments to the thread.
  • The _beginthread function initializes certain C run-time library variables. This is important only if you use the C run-time library in your threads.
  • CreateThread provides control over security attributes. You can use this function to start a thread in a suspended state.

The _beginthread function returns a handle to the new thread if successful or –1 if there was an error.

The _endthread Function

The _endthread function terminates a thread created by _beginthread. Threads terminate automatically when they finish. The _endthread function is useful for conditional termination from within a thread. A thread dedicated to communications processing, for example, can quit if it is unable to get control of the communications port.

See Also

Multithreading with C and Win32

 

 

其他参考资料:

How to link with the correct C Run-Time (CRT) library


How To Use the C Run-Time


http://www.cnblogs.com/zdxster/archive/2011/01/27/1945877.html

posted on 2012-10-12 08:47  龙猫先生  阅读(234)  评论(0编辑  收藏  举报

导航