代码之家  ›  专栏  ›  技术社区  ›  Julian Zimmermann

Visual Studio 2015中的LNK2019 Basler Pylon API[副本]

  •  -1
  • Julian Zimmermann  · 技术社区  · 10 年前

    我知道LNK2019与未链接的库有关。我知道演习->链接器->输入->其他依赖项。我用Basler提供的libs做到了这一点( HERE ). 仅供参考,巴斯勒是一家相机制造商,我需要通过他们的c++API与相机交谈。 我今天想从一个新项目开始,并认为这将是一个很好的开始来编译他们的“抓取一帧”示例文件。 好吧,在带有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;
        }
    

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

    “C:\pylore\pylor\lib\Win32”;" C: \portal\geniam\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$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 ==========
    

    请有人告诉我,发生了什么事?

    1 回复  |  直到 10 年前
        1
  •  0
  •   AStopher    10 年前

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

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

    “C:\pylore\pylor\lib\Win32”;" C: \portal\geniam\library\cpp\lib\win32_i86“

    他们存在。我查过了。

    不,你需要把编译器指向 文件 库(在这种情况下, PylonBase_MD_VC100.lib ) 文件夹 这是不够的。链接到库,它将工作:

    • Linker->Additional Dependencies >添加 PylonBase_MD_VC100.lib 图书馆

    • #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] = ' ';
    }