Ubuntu Balser TOF

在一台新的电脑上,想要测试一下Basler 的TOF相机,安装好TOF的SDK之后(在这台电脑上我还装了pylon5),编译自己的程序发现出现下面的报错:

Failed to load the producer file ProducerTOF.cti: /opt/pylon5/lib64/gentlproducer/gtl/ProducerTOF.cti: cannot open shared object file: No such file or directory

BaslerToF的包含目录和库目录设置都没问题,这个错是加载这个.cti文件路径不对导致的。

我看了一下SDK里加载这个文件的代码位置(/opt/BaslerToF/include/ConsumerImplHelper/ProducerProxy.h 244行):

 template 
    void CProducerProxy::Init(const char* dllname)
    {
        bool loaded = false;
        std::string strDllName(dllname);
        const bool isGenICamTLPathSet = ! GetGenicamGenTLPath().empty();
        const bool nameContainsSeparator = strDllName.find('/') != std::string::npos || strDllName.find('\\') != std::string::npos;

        // If there is a path separator in dllname we are going to ignore the GENICAM_GENTL_PATH. We directly try to load the module.
        // Also directly load the module if there is no GENICAM_GENTL_PATH is set.
        if ( nameContainsSeparator || ! isGenICamTLPathSet  )
        {
#ifdef CIH_WIN_BUILD
            if ( ! nameContainsSeparator )
            {
                // Assume that the producer is located in the directory indicated by the BASLER_TOF_BIN/BASLER_TOF_BIN64 environment variable
#pragma warning(push, 1)
#pragma warning(disable: 4996)
#  if CIH_WORDSIZE == 64
                const char* szBaslerTofBinDir = getenv("BASLER_TOF_BIN64");
#else
                const char* szBaslerTofBinDir = getenv("BASLER_TOF_BIN");
#endif

#  if CIH_WORDSIZE == 64
#endif // endif

#pragma warning(pop)
                if ( NULL != szBaslerTofBinDir  )
                {
                    std::string strBinDir( szBaslerTofBinDir );
                    if ( *strBinDir.rbegin() != '\\' && *strBinDir.rbegin() != '/' )
                    {
                        strBinDir += "\\";
                    }
#  if CIH_WORDSIZE == 64
                    strBinDir += "x64\\";
#  else
                    strBinDir += "win32\\";
#  endif
                    strDllName = strBinDir + strDllName;
                }
            }
#endif
            m_pProducerLib = new Internal::CDynamicLib();
            loaded = m_pProducerLib->Load( strDllName.c_str() );
        }
        else
        {
            // Iterate over all entries in GENICAM_GENTL_PATH and try to load the desired module from there
#if defined CIH_WIN_BUILD
            const char* delimiter = ";";
#else
            const char* delimiter = ":";
#endif
            std::list lstPathEntries = Tokenize( GetGenicamGenTLPath(), delimiter );
            for (std::list::const_iterator it = lstPathEntries.begin(); it != lstPathEntries.end() && ! loaded; ++it )
            {
                std::string strFullPath = *it;
                if ( *strFullPath.rbegin() != '\\' && *strFullPath.rbegin() != '/' )
                    strFullPath += CIH_PATH_SEPARATOR;
                strFullPath += strDllName;
                m_pProducerLib = new Internal::CDynamicLib();
                loaded = m_pProducerLib->Load( strFullPath.c_str() );
            }
        }

        if (!loaded)
        {
            std::ostringstream s;
            throw RUNTIME_EXCEPTION( static_cast(s << "Failed to load the producer file " << dllname << ": " << m_pProducerLib->GetLastErrorMsg() ).str());
        }

应该是:GetGenicamGenTLPath()将gentl位置定位到pylon5文件下了。

解决方案:设置正确的GENICAM_GENTL_PATH (/opt/BaslerToF/lib64/gentlproducer/gtl)

或者向我一样偷懒(不推荐),修改代码:

 strFullPath = "/opt/BaslerToF/lib64/gentlproducer/gtl/";
 strFullPath += strDllName;
 m_pProducerLib = new Internal::CDynamicLib();
 loaded = m_pProducerLib->Load( strFullPath.c_str() );

 

你可能感兴趣的:(c++)