在 project-->settings-->Link-->Object/Library modules 中加入库WSOCK32.LIB即可。
在VC中进行WINSOCK的API编程开发的时候,需要在项目中使用下面三个文件,否则会出现编译错误。
1.WINSOCK.H: 这是WINSOCK API的头文件,需要包含在项目中。
2.WSOCK32.LIB: WINSOCK API连接库文件。在使用中,一定要把它作为项目的非缺省的连接库包含到项目文件中去。
3.WINSOCK.DLL: WINSOCK的动态连接库,位于WINDOWS的安装目录下。
--------------------Configuration: Example1 - Win32 Debug--------------------
Linking...
error LNK2001: unresolved external symbol _connect@12
error LNK2001: unresolved external symbol _htons@4
error LNK2001: unresolved external symbol _inet_addr@4
error LNK2001: unresolved external symbol _socket@12
error LNK2001: unresolved external symbol _closesocket@4
error LNK2001: unresolved external symbol _send@16
error LNK2001: unresolved external symbol _recv@16
error LNK2001: unresolved external symbol _WSAAsyncSelect@16
error LNK2001: unresolved external symbol _accept@12
error LNK2001: unresolved external symbol _listen@8
error LNK2001: unresolved external symbol _bind@12
在 project-->settings-->Link-->Object/Library modules 中加入库odbc32.lib 即可。
mfc程序调用了odbc api,连接时出错:
error LNK2001: unresolved external symbol _SQLConnect@28
error LNK2001: unresolved external symbol _SQLFetch@4
error LNK2001: unresolved external symbol _SQLBindCol@24
error LNK2001: unresolved external symbol _SQLFreeHandle@8
error LNK2001: unresolved external symbol _SQLExecDirect@12
error LNK2001: unresolved external symbol _SQLAllocHandle@12
error LNK2001: unresolved external symbol _SQLSetEnvAttr@16
error LNK2001: unresolved external symbol _SQLDisconnect@4
在 project-->settings-->Link-->Object/Library modules 中加入库cv.lib cvaux.lib cxcore.lib highgui.lib 即可。
error LNK2001: unresolved external symbol _cvReleaseImage
error LNK2001: unresolved external symbol _cvWaitKey
error LNK2001: unresolved external symbol _cvDrawContours
error LNK2001: unresolved external symbol _cvReleaseMemStorage
error LNK2001: unresolved external symbol _cvDestroyWindow
error LNK2001: unresolved external symbol _cvFindContours
error LNK2001: unresolved external symbol _cvCvtColor
error LNK2001: unresolved external symbol _cvCreateImage
error LNK2001: unresolved external symbol _cvGetSize
error LNK2001: unresolved external symbol _cvShowImage
error LNK2001: unresolved external symbol _cvLoadImage
error LNK2001: unresolved external symbol _cvNamedWindow
error LNK2001: unresolved external symbol _cvCreateMemStorage
在 project-->settings-->Link-->Object/Library modules 中加入库OpenGL32.lib GLu32.lib GLaux.lib 即可。
error LNK2001: unresolved external symbol _gluPerspective@32
error LNK2001: unresolved external symbol _gluLookAt@72
error LNK2001: unresolved external symbol __imp__glLoadIdentity@0
error LNK2001: unresolved external symbol __imp__glMatrixMode@4
error LNK2001: unresolved external symbol __imp__glViewport@16
error LNK2001: unresolved external symbol __imp__glHint@8
error LNK2001: unresolved external symbol __imp__glDepthFunc@4
error LNK2001: unresolved external symbol __imp__glEnable@4
error LNK2001: unresolved external symbol __imp__glClearDepth@8
error LNK2001: unresolved external symbol __imp__glClearColor@16
error LNK2001: unresolved external symbol __imp__glShadeModel@4
error LNK2001: unresolved external symbol __imp__glEnd@0
error LNK2001: unresolved external symbol __imp__glVertex3f@12
error LNK2001: unresolved external symbol __imp__glBegin@4
error LNK2001: unresolved external symbol __imp__glTranslatef@12
error LNK2001: unresolved external symbol __imp__glClear@4
error LNK2001: unresolved external symbol __imp__wglDeleteContext@4
error LNK2001: unresolved external symbol __imp__wglMakeCurrent@8
error LNK2001: unresolved external symbol __imp__wglCreateContext@4
在 project-->settings-->Link-->Object/Library modules 中加入库VFW32.Lib 即可。
error LNK2001: unresolved external symbol _capCreateCaptureWindowA@32
在创建项目时, 不使用MFC AppWizard向导, 如果没有设置好项目参数, 就会在编译时产生很多连接错误, 如error LNK2001错误, 典型的错误提示有:
libcmtd.lib(crt0.obj) : error LNK2001: unresolved external symbol _main
LIBCD.lib(wincrt0.obj) : error LNK2001: unresolved external symbol _WinMain@16
msvcrtd.lib(crtexew.obj) : error LNK2001: unresolved external symbol _WinMain@16
nafxcwd.lib(thrdcore.obj) : error LNK2001: unresolved external symbol __beginthreadex
nafxcwd.lib(thrdcore.obj) : error LNK2001: unresolved external symbol __endthreadex
错误可能引起的原因:
当copy网上的源程序,在本机编译的时候,由于新建的工程没有把连接用的库,在连接的时候添加进去,所以一些函数、变量找不到定义的库文件,从而出错。
texture.obj : error LNK2001: unresolved external symbol __imp__glEnable@4
texture.obj : error LNK2001: unresolved external symbol __imp__glTexEnvf@12
texture.obj : error LNK2001: unresolved external symbol __imp__glTexParameterf@12
texture.obj : error LNK2001: unresolved external symbol __imp__glTexImage2D@36
texture.obj : error LNK2001: unresolved external symbol __imp__glPixelStorei@8
texture.obj : error LNK2001: unresolved external symbol _auxDIBImageLoadA@4
解决方法:
先弄清楚到底缺了哪些库,再在project=》setting=》link里面的moldul/lib 添加这些库的文件。
可以用以下形式在源程序里面添加下面代码:
#pragma comment(lib, "openGL32.lib");
#pragma comment(lib, "glu32.lib");
*#pragma comment(lib, "glaux.lib");
vc编译报错 unresolved external symbol __imp__PlaySoundA@12 解决办法:
添加Winmm.lib和 头文件中包含 Mmsystem.h
选择"project"->"setting"->"link"->"Object/library modules"然后添加"Winmm.lib"就可以了。