-1

I know LNK2019 is related to unlinked librarys. I know the drill -> Linker - > Input -> Additional Dependencies. I've done that with the libs provided by Basler (HERE). FYI Basler is a camera manufacturer and i need to talk to the camera via their c++ API. I wanted to start today with a new project and thought it would be a good start to compile their 'grab a single frame' sample file. Well in Linux with g++ everything works like a charm and compiling is a thing of a minute but sadly i need Windows for this project for stupid reasons.

I'm working on this now for 4 hours and i'm beginning to go crazy. Help is much appreciated. Here is the Main File and all Project Info from 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;
    }

Included LibrariesFolder (Linker->Additional Dependencies):

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

They exist. I've checked that.

Output from Compiler:

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 can somebody tell me, what is going on ?

  • Have you included the names of the libraries (.lib) or just the path to their location? – Niall Sep 07 '15 at 18:37
  • It seems you only know half the drill. As well as specifying the directories where the libraries are found you also have to specify the names of the libraries as well. Where you do that I can't say, it seems my Visual Studio is different from yours but in my version it's under Linker/Input/Additional Dependencies. I don't have any setting called Linker/Additional Dependencies but I would specify the folders under Linker/General/Additional Library Directories. – john Sep 07 '15 at 18:38
  • thank you guys. i was too stupid too see. – Julian Zimmermann Sep 07 '15 at 18:47

1 Answers1

0

The linker is trying to compile your application, but cannot as it doesn't know what the various Pylon functions refer to as you haven't used the PylonBase_MD_VC100.lib library. You may think you have, but you haven't. Let's explain why:

Included LibrariesFolder (Linker->Additional Dependencies):

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

They exist. I've checked that.

Well, no. You need to point the compiler to the file of the library (in this case, PylonBase_MD_VC100.lib), the folder won't suffice. Link to the library, and it'll work:

  • Linker->Additional Dependencies > Add the PylonBase_MD_VC100.lib library

OR

  • #prama comment(lib, "PylonBase_MD_VC100.lib") at the beginning of your code, just below any #includes

The following sample from the MSDN KB article on this issue will guarantee a LNK2019 error:

// LNK2019.cpp
// LNK2019 expected
extern char B[100];   // B is not available to the linker
int main() {
   B[0] = ' ';
}
AStopher
  • 4,207
  • 11
  • 50
  • 75