LNK2019 Basler Pylon API 在 Visual Studio 2015

LNK2019 Basler Pylon API in Visual Studio 2015

我知道 LNK2019 与未链接的图书馆有关。我知道演练 -> 链接器 -> 输入 -> 附加依赖项。我已经使用 Basler (HERE) 提供的库完成了这项工作。仅供参考 Basler 是一家相机制造商,我需要通过他们的 C++ API 与相机对话。 我今天想从一个新项目开始,并认为编译他们的 'grab a single frame' 示例文件是一个好的开始。 好吧,在 Linux 中,使用 g++ 一切都像一个魅力,编译是一分钟的事情,但遗憾的是,出于愚蠢的原因,我需要 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;
    }

包含的库文件夹(链接器->附加依赖项):

"C:\pylon\pylon\lib\Win32";" C:\pylon\genicam\library\cpp\lib\win32_i86"

它们存在。我已经检查过了。

编译器的输出:

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[=13=]
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 ==========

有人可以告诉我,这是怎么回事吗?

链接器正在尝试编译您的应用程序,但无法编译,因为它不知道各种 Pylon 函数指的是什么,因为您还没有使用 PylonBase_MD_VC100.lib 库。 你可能认为你有,但你没有。让我们解释一下原因:

Included LibrariesFolder (Linker->Additional Dependencies):

"C:\pylon\pylon\lib\Win32";" C:\pylon\genicam\library\cpp\lib\win32_i86"

They exist. I've checked that.

嗯,不。您需要将编译器指向库的 file(在本例中为 PylonBase_MD_VC100.lib),folder 是不够的. Link 到图书馆,它会起作用:

  • Linker->Additional Dependencies > 添加 PylonBase_MD_VC100.lib

  • #prama comment(lib, "PylonBase_MD_VC100.lib") 在代码的开头,就在任何 #includes
  • 的下方

来自 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] = ' ';
}