Win32 Consle Application使用MFC的一些類如CString時編譯時間相信會很經常遇到一些串連錯誤:1. unresolved external symbol __beginthreadex2. unresolved external symbol __endthreadex但是不用MFC類又讓人不甘心,放著好好的類庫不用實在太可惜了。其實是可以用的,只是我們的設定有問題。下面我將具體設定描述一下,和大家共同分享我的經驗。一.建立一個Win32 Consle Application工程:GetCurrentTime。二.開啟“Project”菜單——〉“Setting”功能表項目——〉General選項卡在Microsoft Fountion Classes:中選擇:Use MFC in Static Library.
三.再在C/C++選項卡中的在Category中選擇Code Generation,
再在Use run-time library中選擇Debug Multithreaded或者multithreaded
其中,
Single-Threaded單線程靜態連結庫(release版本)
Multithreaded多線程靜態連結庫(release版本)
multithreaded DLL多線程動態連結程式庫(release版本)
Debug Single-Threaded單線程靜態連結庫(debug版本)
Debug Multithreaded多線程靜態連結庫(debug版本)
Debug Multithreaded DLL多線程動態連結程式庫(debug版本)
選擇Debug Multithreaded(如果你在Win32 Debug環境下)
之後敲入你的代碼:
#include "stdafx.h"
#include <afx.h> // 注意要加上你所用的類的標頭檔
#include <stdio.h>
int main(int argc, char* argv[])
{
CTime time;
time = CTime::GetCurrentTime();
CString str = time.Format("%H:%M:%S");
printf("目前時間為%s/n",(LPCTSTR)str);
return 0;
}
在編譯時間往往提示設定有改動,是否繼續,選擇“是”
四.大功告成。
運行結果: