默認庫“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

發表評論
所有評論
還沒有人評論,想成為第一個評論的人麼? 請在上方評論欄輸入並且點擊發布.
相關文章