C++链接错误LNK2019

问题描述:

任何人都可以帮助我配置Visual Studio 2005(如果这是问题的解决方案)。我正在使用一些外部库,我得到这个错误:C++链接错误LNK2019

1>Compiling... 
1>main.cpp 
1>c:\documents and settings\mz07\desktop\project\vs8test1\vs8test1\main.cpp(99) : warning C4996: 'getch' was declared deprecated 
1>  c:\program files\microsoft visual studio 8\vc\include\conio.h(145) : see declaration of 'getch' 
1>  Message: 'The POSIX name for this item is deprecated. Instead, use the ISO C++ conformant name: _getch. See online help for details.' 
1>c:\documents and settings\mz07\desktop\project\vs8test1\vs8test1\main.cpp(110) : warning C4996: 'getch' was declared deprecated 
1>  c:\program files\microsoft visual studio 8\vc\include\conio.h(145) : see declaration of 'getch' 
1>  Message: 'The POSIX name for this item is deprecated. Instead, use the ISO C++ conformant name: _getch. See online help for details.' 
1>c:\documents and settings\mz07\desktop\project\vs8test1\vs8test1\main.cpp(128) : warning C4996: 'getch' was declared deprecated 
1>  c:\program files\microsoft visual studio 8\vc\include\conio.h(145) : see declaration of 'getch' 
1>  Message: 'The POSIX name for this item is deprecated. Instead, use the ISO C++ conformant name: _getch. See online help for details.' 
1>Compiling manifest to resources... 
1>Linking... 
1>hdu.lib(hduError.obj) : error LNK2019: unresolved external symbol "__declspec(dllimport) class std::basic_ostream<char,struct std::char_traits<char> > & __cdecl std::operator<<(class std::basic_ostream<char,struct std::char_traits<char> > &,char const *)" ([email protected]@[email protected][email protected]@[email protected]@@[email protected]@[email protected]) referenced in function "class std::basic_ostream<char,struct std::char_traits<char> > & __cdecl operator<<(class std::basic_ostream<char,struct std::char_traits<char> > &,struct HDErrorInfo const &)" ([email protected][email protected][email protected]@[email protected]@@[email protected]@[email protected]@@@Z) 
1>C:\Documents and Settings\mz07\Desktop\project\vs8Test1\Debug\vs8Test1.exe : fatal error LNK1120: 1 unresolved externals 

我一直在使用Google搜索几个小时。请,*是我的最后希望!

对不起,我忘了,包括代码:

#include "atl/stdafx.h" 
#include <cstdio> 
#include <cassert> 

#if defined(WIN32) 
# include <conio.h> 
#else 
# include "conio.h" 
#endif 

#include <HD/hd.h> 
#include <HDU/hduVector.h> 
#include <HDU/hduError.h> 

#pragma comment(lib, "hdu.lib") 
#pragma comment(lib, "hlu.lib") 
#pragma comment(lib, "hd.lib") 
#pragma comment(lib, "hl.lib") 

/******************************************************************************* 
Haptic sphere callback. 
The sphere is oriented at 0,0,0 with radius 40, and provides a repelling force 
if the device attempts to penetrate through it. 
*******************************************************************************/ 

HDCallbackCode HDCALLBACK FrictionlessSphereCallback(void *data) 
{ 
    const double sphereRadius = 40.0; 
    const hduVector3Dd spherePosition(0,0,0); 

// Stiffness, i.e. k value, of the sphere. Higher stiffness results 
// in a harder surface. 
const double sphereStiffness = .25; 

hdBeginFrame(hdGetCurrentDevice()); 

// Get the position of the device. 
hduVector3Dd position; 
hdGetDoublev(HD_CURRENT_POSITION, position); 

// Find the distance between the device and the center of the 
// sphere. 
double distance = (position-spherePosition).magnitude(); 

// If the user is within the sphere -- i.e. if the distance from the user to 
// the center of the sphere is less than the sphere radius -- then the user 
// is penetrating the sphere and a force should be commanded to repel him 
// towards the surface. 
if (distance < sphereRadius) 
{ 
    // Calculate the penetration distance. 
    double penetrationDistance = sphereRadius-distance; 

    // Create a unit vector in the direction of the force, this will always 
    // be outward from the center of the sphere through the user's 
    // position. 
    hduVector3Dd forceDirection = (position-spherePosition)/distance; 

    // Use F=kx to create a force vector that is away from the center of 
    // the sphere and proportional to the penetration distance, and scsaled 
    // by the object stiffness. 
    // Hooke's law explicitly: 
    double k = sphereStiffness; 
    hduVector3Dd x = penetrationDistance*forceDirection; 
    hduVector3Dd f = k*x; 
    hdSetDoublev(HD_CURRENT_FORCE, f); 
} 

hdEndFrame(hdGetCurrentDevice()); 

HDErrorInfo error; 
if (HD_DEVICE_ERROR(error = hdGetError())) 
{ 
    hduPrintError(stderr, &error, "Error during main scheduler callback\n"); 

    if (hduIsSchedulerError(&error)) 
    { 
     return HD_CALLBACK_DONE; 
    }   
} 

return HD_CALLBACK_CONTINUE; 
} 


/****************************************************************************** 
main function 
Initializes the device, creates a callback to handle sphere forces, terminates 
upon key press. 
******************************************************************************/ 

int main(int argc, char* argv[]) 
{ 
HDErrorInfo error; 
// Initialize the default haptic device. 
HHD hHD = hdInitDevice(HD_DEFAULT_DEVICE); 
if (HD_DEVICE_ERROR(error = hdGetError())) 
{ 
    hduPrintError(stderr, &error, "Failed to initialize haptic device"); 
    fprintf(stderr, "\nPress any key to quit.\n"); 
    getch(); 
    return -1; 
} 

// Start the servo scheduler and enable forces. 
hdEnable(HD_FORCE_OUTPUT); 
hdStartScheduler(); 
if (HD_DEVICE_ERROR(error = hdGetError())) 
{ 
    hduPrintError(stderr, &error, "Failed to start scheduler"); 
    fprintf(stderr, "\nPress any key to quit.\n"); 
    getch(); 
    return -1; 
} 

// Application loop - schedule our call to the main callback. 
HDSchedulerHandle hSphereCallback = hdScheduleAsynchronous(
    FrictionlessSphereCallback, 0, HD_DEFAULT_SCHEDULER_PRIORITY); 

printf("Sphere example.\n"); 
printf("Move the device around to feel a frictionless sphere\n\n"); 
printf("Press any key to quit.\n\n"); 

while (!_kbhit()) 
{ 
    if (!hdWaitForCompletion(hSphereCallback, HD_WAIT_CHECK_STATUS)) 
    { 
     fprintf(stderr, "\nThe main scheduler callback has exited\n"); 
     fprintf(stderr, "\nPress any key to quit.\n"); 
     getch(); 
     break; 
    } 
} 

// For cleanup, unschedule our callbacks and stop the servo loop. 
hdStopScheduler(); 
hdUnschedule(hSphereCallback); 
hdDisableDevice(hHD); 

return 0; 
} 
+0

如果你需要帮助,你应该张贴的代码呢! – 2010-01-21 13:26:49

我想你要导入(hdu.lib)图书馆是建立与不同的运行时库 - 无论你是混合调试和释放在这里库或静态与DLL运行时。

+0

我是C++和visual studio的新手。你的意思是我设置了错误的参数到项目配置?你能否指出我应该在哪里看?非常感谢 – Student 2010-01-21 13:49:35

+0

这是一个很好的观点。分发库的人通常更喜欢静态地与运行时链接,因为它阻止了他们必须分发(并支持)Microsoft DLL。 – 2010-01-21 13:50:29

+0

这适合我这个图书馆。刚刚重新编译了库,它工作 – andrezsanchez 2016-02-22 17:06:31

它看起来像我不喜欢在C++库中链接。如果您在项目的“属性”单击鼠标右键,并检查配置属性 - >链接器 - >输入,你的“附加依赖”行包括“libcpmt.lib”?

+0

不,它没有。我只是试图包括它,但它没有工作 – Student 2010-01-21 13:52:10

+0

相同的链接错误,或不同的? – 2010-01-21 13:55:21

+0

完全相同的错误 – Student 2010-01-21 13:58:50

如果你可以发布链接器正在运行的命令行开关,这将有所帮助,我的意思是完整的命令。

看起来这个hdu libarary对C++ iostream库有依赖性,你可以检查你的链接器设置是否指定了iostream库。

+0

/OUT:“C:\ Documents and Settings \ mz07 \ Desktop \ project \ vs8Test1 \ Debug \ vs8Test1.exe”/ INCREMENTAL/NOLOGO/MANIFEST /MANIFESTFILE:"Debug\vs8Test1.exe.intermediate.manifest “/NODEFAULTLIB:"msvcrt.lib”/ DEBUG/PDB:“c:\ Documents and Settings \ mz07 \ Desktop \ project \ vs8Test1 \ debug \ vs8Test1.pdb”/ SUBSYSTEM:CONSOLE/MACHINE:X86/ERRORREPORT:PROMPT libcpmt。 lib kernel32.lib user32.lib gdi32.lib winspool.lib comdlg32.lib advapi32.lib shell32.lib ole32.lib oleaut32.lib uuid.lib odbc32.lib odbccp32.lib – Student 2010-01-21 13:52:59

+0

此条目:/NODEFAULTLIB:"msvcrt.lib“is对我来说是一个很大的警告标志 - 你在调试版本中排除了C++运行时版本,这意味着你正在混合调试版本和发布版本。这通常不是一个好主意。 – 2010-01-21 15:52:37