我知道LNK2019与未链接的图书馆有关。我知道演习 - >链接器 - >输入 - >额外的依赖关系。我已经使用Basler(HERE)提供的库完成了这项工作。 FYI Basler是一家相机制造商,我需要通过他们的c ++ API与相机交谈。 我想今天开始一个新项目,并认为这将是一个良好的开端,编制他们的“抓住一个框架”#39;样本文件。 在使用g ++的Linux中,一切都像魅力一样,编译只是一分钟,但遗憾的是我出于愚蠢的原因需要Windows这个项目。
我现在正在努力工作4个小时,我开始变得疯狂。 非常感谢帮助。这是主文件和Visual Studio中的所有项目信息:
// Grab.cpp
/*
Note: Before getting started, Basler recommends reading the Programmer's Guide topic
in the pylon C++ API documentation that gets installed with pylon.
If you are upgrading to a higher major version of pylon, Basler also
strongly recommends reading the Migration topic in the pylon C++ API documentation.
This sample illustrates how to grab and process images using the CInstantCamera class.
The images are grabbed and processed asynchronously, i.e.,
while the application is processing a buffer, the acquisition of the next buffer is done
in parallel.
The CInstantCamera class uses a pool of buffers to retrieve image data
from the camera device. Once a buffer is filled and ready,
the buffer can be retrieved from the camera object for processing. The buffer
and additional image data are collected in a grab result. The grab result is
held by a smart pointer after retrieval. The buffer is automatically reused
when explicitly released or when the smart pointer object is destroyed.
*/
// Include files to use the PYLON API.
#include <pylon/PylonIncludes.h>
#ifdef PYLON_WIN_BUILD
# include <pylon/PylonGUI.h>
#endif
// Namespace for using pylon objects.
using namespace Pylon;
// Namespace for using cout.
using namespace std;
// Number of images to be grabbed.
static const uint32_t c_countOfImagesToGrab = 100;
int main(int argc, char* argv[])
{
// The exit code of the sample application.
int exitCode = 0;
// Automagically call PylonInitialize and PylonTerminate to ensure the pylon runtime system
// is initialized during the lifetime of this object.
Pylon::PylonAutoInitTerm autoInitTerm;
try
{
// Create an instant camera object with the camera device found first.
CInstantCamera camera( CTlFactory::GetInstance().CreateFirstDevice());
// Print the model name of the camera.
cout << "Using device " << camera.GetDeviceInfo().GetModelName() << endl;
// The parameter MaxNumBuffer can be used to control the count of buffers
// allocated for grabbing. The default value of this parameter is 10.
camera.MaxNumBuffer = 5;
// Start the grabbing of c_countOfImagesToGrab images.
// The camera device is parameterized with a default configuration which
// sets up free-running continuous acquisition.
camera.StartGrabbing( c_countOfImagesToGrab);
// This smart pointer will receive the grab result data.
CGrabResultPtr ptrGrabResult;
// Camera.StopGrabbing() is called automatically by the RetrieveResult() method
// when c_countOfImagesToGrab images have been retrieved.
while ( camera.IsGrabbing())
{
// Wait for an image and then retrieve it. A timeout of 5000 ms is used.
camera.RetrieveResult( 5000, ptrGrabResult, TimeoutHandling_ThrowException);
// Image grabbed successfully?
if (ptrGrabResult->GrabSucceeded())
{
// Access the image data.
cout << "SizeX: " << ptrGrabResult->GetWidth() << endl;
cout << "SizeY: " << ptrGrabResult->GetHeight() << endl;
const uint8_t *pImageBuffer = (uint8_t *) ptrGrabResult->GetBuffer();
cout << "Gray value of first pixel: " << (uint32_t) pImageBuffer[0] << endl << endl;
#ifdef PYLON_WIN_BUILD
// Display the grabbed image.
Pylon::DisplayImage(1, ptrGrabResult);
#endif
}
else
{
cout << "Error: " << ptrGrabResult->GetErrorCode() << " " << ptrGrabResult->GetErrorDescription() << endl;
}
}
}
catch (GenICam::GenericException &e)
{
// Error handling.
cerr << "An exception occurred." << endl
<< e.GetDescription() << endl;
exitCode = 1;
}
// Comment the following two lines to disable waiting on exit.
cerr << endl << "Press Enter to exit." << endl;
while( cin.get() != '\n');
return exitCode;
}
包含的LibrariesFolder(链接器 - &gt;附加依赖项):
&#34; C:\挂架\挂架\ lib中\的Win32&#34 ;;&#34; C:\挂架\ GenICam标准\库\ CPP \ lib中\ win32_i86&#34;
他们存在。我已经检查过了。
编译器的输出:
1>------ Build started: Project: Grab, Configuration: Debug Win32 ------
1>Grab.obj : error LNK2019: unresolved external symbol "__declspec(dllimport) public: __thiscall Pylon::PylonAutoInitTerm::PylonAutoInitTerm(void)" (__imp_??0PylonAutoInitTerm@Pylon@@QAE@XZ) referenced in function _main
1>Grab.obj : error LNK2019: unresolved external symbol "__declspec(dllimport) public: __thiscall Pylon::PylonAutoInitTerm::~PylonAutoInitTerm(void)" (__imp_??1PylonAutoInitTerm@Pylon@@QAE@XZ) referenced in function __catch$_main$0
1>Grab.obj : error LNK2019: unresolved external symbol "__declspec(dllimport) public: __thiscall Pylon::CDeviceInfo::CDeviceInfo(void)" (__imp_??0CDeviceInfo@Pylon@@QAE@XZ) referenced in function _main
1>Grab.obj : error LNK2019: unresolved external symbol "__declspec(dllimport) public: class GenICam::gcstring __thiscall Pylon::CDeviceInfo::GetModelName(void)const " (__imp_?GetModelName@CDeviceInfo@Pylon@@QBE?AVgcstring@GenICam@@XZ) referenced in function _main
1>Grab.obj : error LNK2019: unresolved external symbol "__declspec(dllimport) public: virtual __thiscall Pylon::CDeviceInfo::~CDeviceInfo(void)" (__imp_??1CDeviceInfo@Pylon@@UAE@XZ) referenced in function _main
1>Grab.obj : error LNK2019: unresolved external symbol "__declspec(dllimport) public: static class Pylon::CTlFactory & __cdecl Pylon::CTlFactory::GetInstance(void)" (__imp_?GetInstance@CTlFactory@Pylon@@SAAAV12@XZ) referenced in function _main
1>Grab.obj : error LNK2019: unresolved external symbol "__declspec(dllimport) public: bool __thiscall Pylon::CGrabResultData::GrabSucceeded(void)const " (__imp_?GrabSucceeded@CGrabResultData@Pylon@@QBE_NXZ) referenced in function _main
1>Grab.obj : error LNK2019: unresolved external symbol "__declspec(dllimport) public: class GenICam::gcstring __thiscall Pylon::CGrabResultData::GetErrorDescription(void)const " (__imp_?GetErrorDescription@CGrabResultData@Pylon@@QBE?AVgcstring@GenICam@@XZ) referenced in function _main
1>Grab.obj : error LNK2019: unresolved external symbol "__declspec(dllimport) public: unsigned int __thiscall Pylon::CGrabResultData::GetErrorCode(void)const " (__imp_?GetErrorCode@CGrabResultData@Pylon@@QBEIXZ) referenced in function _main
1>Grab.obj : error LNK2019: unresolved external symbol "__declspec(dllimport) public: unsigned int __thiscall Pylon::CGrabResultData::GetWidth(void)const " (__imp_?GetWidth@CGrabResultData@Pylon@@QBEIXZ) referenced in function _main
1>Grab.obj : error LNK2019: unresolved external symbol "__declspec(dllimport) public: unsigned int __thiscall Pylon::CGrabResultData::GetHeight(void)const " (__imp_?GetHeight@CGrabResultData@Pylon@@QBEIXZ) referenced in function _main
1>Grab.obj : error LNK2019: unresolved external symbol "__declspec(dllimport) public: void * __thiscall Pylon::CGrabResultData::GetBuffer(void)const " (__imp_?GetBuffer@CGrabResultData@Pylon@@QBEPAXXZ) referenced in function _main
1>Grab.obj : error LNK2019: unresolved external symbol "__declspec(dllimport) public: __thiscall Pylon::CGrabResultPtr::CGrabResultPtr(void)" (__imp_??0CGrabResultPtr@Pylon@@QAE@XZ) referenced in function _main
1>Grab.obj : error LNK2019: unresolved external symbol "__declspec(dllimport) public: __thiscall Pylon::CGrabResultPtr::~CGrabResultPtr(void)" (__imp_??1CGrabResultPtr@Pylon@@QAE@XZ) referenced in function _main
1>Grab.obj : error LNK2019: unresolved external symbol "__declspec(dllimport) public: class Pylon::CGrabResultData * __thiscall Pylon::CGrabResultPtr::operator->(void)const " (__imp_??CCGrabResultPtr@Pylon@@QBEPAVCGrabResultData@1@XZ) referenced in function _main
1>Grab.obj : error LNK2019: unresolved external symbol "__declspec(dllimport) public: __thiscall Pylon::CGrabResultPtr::operator struct Pylon::IImage &(void)const " (__imp_??BCGrabResultPtr@Pylon@@QBEAAUIImage@1@XZ) referenced in function _main
1>Grab.obj : error LNK2019: unresolved external symbol "__declspec(dllimport) public: __thiscall Pylon::CInstantCamera::CInstantCamera(struct Pylon::IPylonDevice *,enum Pylon::ECleanup)" (__imp_??0CInstantCamera@Pylon@@QAE@PAUIPylonDevice@1@W4ECleanup@1@@Z) referenced in function _main
1>Grab.obj : error LNK2019: unresolved external symbol "__declspec(dllimport) public: virtual __thiscall Pylon::CInstantCamera::~CInstantCamera(void)" (__imp_??1CInstantCamera@Pylon@@UAE@XZ) referenced in function _main
1>Grab.obj : error LNK2019: unresolved external symbol "__declspec(dllimport) public: virtual void __thiscall Pylon::CInstantCamera::StartGrabbing(unsigned int,enum Pylon::EGrabStrategy,enum Pylon::EGrabLoop)" (__imp_?StartGrabbing@CInstantCamera@Pylon@@UAEXIW4EGrabStrategy@2@W4EGrabLoop@2@@Z) referenced in function _main
1>Grab.obj : error LNK2019: unresolved external symbol "__declspec(dllimport) public: virtual bool __thiscall Pylon::CInstantCamera::RetrieveResult(unsigned int,class Pylon::CGrabResultPtr &,enum Pylon::ETimeoutHandling)" (__imp_?RetrieveResult@CInstantCamera@Pylon@@UAE_NIAAVCGrabResultPtr@2@W4ETimeoutHandling@2@@Z) referenced in function _main
1>Grab.obj : error LNK2019: unresolved external symbol "__declspec(dllimport) public: virtual bool __thiscall Pylon::CInstantCamera::IsGrabbing(void)const " (__imp_?IsGrabbing@CInstantCamera@Pylon@@UBE_NXZ) referenced in function _main
1>Grab.obj : error LNK2019: unresolved external symbol "__declspec(dllimport) public: virtual class Pylon::CDeviceInfo const & __thiscall Pylon::CInstantCamera::GetDeviceInfo(void)const " (__imp_?GetDeviceInfo@CInstantCamera@Pylon@@UBEABVCDeviceInfo@2@XZ) referenced in function _main
1>Grab.obj : error LNK2019: unresolved external symbol "__declspec(dllimport) void __cdecl Pylon::DisplayImage(unsigned int,struct Pylon::IImage const &)" (__imp_?DisplayImage@Pylon@@YAXIABUIImage@1@@Z) referenced in function _main
1>C:\path-to\Grab.exe : fatal error LNK1120: 23 unresolved externals
========== Build: 0 succeeded, 1 failed, 0 up-to-date, 0 skipped ==========
Pls有人可以告诉我,发生了什么事吗?
答案 0 :(得分:0)
链接器正在尝试编译您的应用程序,但不能,因为它不知道各种Pylon
函数所指的是什么,因为您还没有使用PylonBase_MD_VC100.lib
库。
你可能认为你有,但你没有。让我们解释一下原因:
包含的LibrariesFolder(链接器 - &gt;附加依赖项):
&#34; C:\挂架\挂架\ lib中\的Win32&#34 ;;&#34; C:\挂架\ GenICam标准\库\ CPP \ lib中\ win32_i86&#34;
他们存在。我已经检查过了。
嗯,不。您需要将编译器指向库的文件(在本例中为PylonBase_MD_VC100.lib
),文件夹不足以满足要求。链接到图书馆,它将起作用:
Linker->Additional Dependencies
&gt;添加PylonBase_MD_VC100.lib
库<强> OR 强>
#prama comment(lib, "PylonBase_MD_VC100.lib")
,位于任何#include
s MSDN KB article on this issue中的以下示例将保证LNK2019
错误:
// LNK2019.cpp
// LNK2019 expected
extern char B[100]; // B is not available to the linker
int main() {
B[0] = ' ';
}