Linking...
nafxcwd.lib(thrdcore.obj) : error LNK2001: unresolved external symbol __endthreadex
nafxcwd.lib(thrdcore.obj) : error LNK2001: unresolved external symbol __beginthreadex
Debug/laborary.exe : fatal error LNK1120: 2 unresolved externals
Error executing link.exe.一个很简单的程序 编译通过了是不是我的VC有问题? 下面是程序的代码 很简单的 #include <stdio.h>
#include <string.h>
#include <iostream.h>
#include <Afx.h>class Book {private : char m_name[50] ;
char m_author[50] ;
char m_publisher[50] ;
float m_price ;
 
public :

//Constructors
Book(){
cout << "A new book has been created ." << endl ;
} Book(char name[], char author[], char publisher[], float price){

Book() ;

strcpy(m_name,name) ;
strcpy(m_author,author) ;
strcpy(m_publisher,publisher) ;
m_price = price ;
} //Save the information to the file which is specified by the fileName .
void saveBook(char fileName[]){ cout << m_name << "\t" << m_author << "\t" << m_publisher << "\t" << m_price << endl ; 
FILE *fp ;
if((fp = fopen(fileName,"a")) == NULL){
cout << "Can't open the file : " << fileName << endl ;
return ;
}
fprintf(fp ,"\n%s,\t,%s,\t,%s,\t,%f,\n",m_name,m_author,m_publisher,m_price) ;
fclose(fp) ;
}

//Set functions 
void setName(char* name){
strcpy(m_name,name) ;
} void setAuthor(char* author){
strcpy(m_author,author) ;
}

void setPublisher(char* publisher){
strcpy(m_publisher,publisher) ;
} void setPrice(float price){
m_price = price ;
} //Get functions
char* getName(){
return m_name ;
} char* getAuthor(){
return m_author ; 
}  char* getPublisher(){
return m_publisher ;
} float getPrice(){
return m_price ; 
}
} ;void main(){ Book book("C ++ Primer " , "Stroustru" , "China-pub" , 128.00) ; 
book.saveBook("d:\\hfj.txt") ;
}

解决方案 »

  1.   

    compile with: /MT /D "_X86_" /c
      

  2.   

    MSDN说:
    Libraries:
    Multithreaded versions of the C run-time libraries only.
    To use _beginthread or _beginthreadex, the application must link with one of the multithreaded C run-time libraries.
      

  3.   

    使用多线程库,还不行的话加上:#include <process.h>
      

  4.   

    把#include <Afx.h>这句注释掉,因为你不用MFC。
      

  5.   

    project | settings | c/c++
    最下面的框里+上
    /MT /D "_X86_" /c
      

  6.   

    我用的是VS2003,Project Setting -> C/C++ -> Code Generation -> Runtime Library 中选择Multi thread Dll。别的版本应该差不多,具体记不起来了。
      

  7.   

    好象不行呀就是afx.h这个东西的问题
      

  8.   

    如果你工程建立用的是WIN32 CONSOLE:把#include <Afx.h>这句注释掉
    如果你工程建立用的是WINDOWS APPLICATION:porject->setting中general页中选择“using mfc in a shared dll”
      

  9.   

    更多的错误呀~~我用的是VS2003,Project Setting -> C/C++ -> Code Generation -> Runtime Library 中选择Multi thread Dll。别的版本应该差不多,具体记不起来了。