控制台程序使用MFC类的方法

(unresolved external symbol __endthreadex解决办法)

 

1、新建控制台程序:

1

 

2

 

3

 

2、添加源代码如下:

 

[cpp] view plain copy
 
 print?
  1. #include <afx.h>  
  2. #include <stdio.h>  
  3.   
  4. int main()  
  5. {  
  6.     int         lo, hi;  
  7.     CString     str;  
  8.     CStdioFile  pFile;  
  9.       
  10.     pFile.Open("FIBO.DAT", CFile::modeWrite |  
  11.                            CFile::modeCreate|  
  12.                            CFile::typeText);  
  13.       
  14.     str.Format("%s/n", "Fibonacci sequencee, less than 100 :");  
  15.     printf("%s", (LPCTSTR) str);  
  16.     pFile.WriteString(str);  
  17.       
  18.     lo = hi = 1;  
  19.       
  20.     str.Format("%d/n", lo);  
  21.     printf("%s", (LPCTSTR) str);  
  22.     pFile.WriteString(str);  
  23.       
  24.     while (hi < 100)  
  25.     {  
  26.         str.Format("%d/n", hi);  
  27.         printf("%s", (LPCTSTR) str);  
  28.         pFile.WriteString(str);  
  29.         hi = lo + hi;  
  30.         lo = hi - lo;  
  31.     }  
  32.       
  33.     pFile.Close();  
  34.     return 0;  
  35. }  

 

 

3、编译是链接出错:

Compiling...
Console.cpp

Linking...
nafxcwd.lib(thrdcore.obj) : error LNK2001: unresolved external symbol __endthreadex
nafxcwd.lib(thrdcore.obj) : error LNK2001: unresolved external symbol __beginthreadex
Debug/MFCConsole.exe : fatal error LNK1120: 2 unresolved externals
Error executing link.exe.

Console.exe - 3 error(s), 0 warning(s)

 

4、分析原因:

    上述连接错误表示找不到__endthreadex与__beginthreadex,我们的程序有调用它们吗?没有,但是MFC有(afx.h)

 

5、解决办法

     unresolved external symbol __endthreadex错误解决

    A、设置静态链接库

        选择Project-Settings--General--Microsoft foundation Classes
        下拉列表中有三个选项,选择2/3即可:
        1、Not using MFC
        2、Use MFC in a Static Libray
        3、Use MFC in a Shared DLL

    B、设置C Runtime函数库

        Project / settings / c/c++ / Catagory / Code Generation

        use run-time library”选择“debug multithreaded”

 

6、关于C Runtime

4

5

 

http://blog.csdn.net/wangningyu/article/details/4642421

posted @ 2016-10-03 06:34  findumars  Views(2763)  Comments(0Edit  收藏  举报