C++ build error using librealsense in ubuntu - c++

I installed librealsense from the source. It was installed and build successfully.
When I tried to run the sample project (rs-hello-realsense) I have found the build error.
/usr/local/include/librealsense2/hpp/rs_types.hpp:90: undefined reference to `rs2_get_error_message'
/usr/local/include/librealsense2/hpp/rs_types.hpp:92: undefined reference to `rs2_get_failed_function'
/usr/local/include/librealsense2/hpp/rs_types.hpp:92: undefined reference to `rs2_get_failed_function'
Same kind of error from a different type of build.
CMakeFiles/rs-hello-realsense.dir/rs-hello-realsense.cpp.o: In function `rs2::error::error(rs2_error*)':
rs-hello-realsense.cpp:(.text._ZN3rs25errorC2EP9rs2_error[_ZN3rs25errorC5EP9rs2_error]+0x2e): undefined reference to `rs2_get_error_message'
rs-hello-realsense.cpp:(.text._ZN3rs25errorC2EP9rs2_error[_ZN3rs25errorC5EP9rs2_error]+0x73): undefined reference to `rs2_get_failed_function'

Finally, get it. Need to add a couple of lines in CMakeList.txt.
Which linked the libraries in the project.
find_package(realsense2 2.29.0)
target_link_libraries(rs-hello-realsense ${DEPENDENCIES} ${realsense2_LIBRARY})
OR
target_link_libraries(${PROJECT_NAME} ${realsense2_LIBRARY})
Other than all other properties of CMake File will be same

Related

Building Qt project with Network using CMake causes undefined references

I'm working on a Qt project using the Network package (in particular QTcpSocket). I can easily compile it using qmake, but I fail to do so using cmake (which I need for cross compilation), due to some undefined references regarding the Network package.
My CmakeLists contains, amongst others, the following lines (with ... being placeholders for other things):
find_package(Qt5 COMPONENTS Network REQUIRED)
qt5_use_modules(... Network ...)
target_link_libraries(... Qt5::Network ...)
I thought those are all that is required, but apparently not so.
The undefined reference errors I get when linking are a huge lists, so I will only show a small exempt, unless somebody requires more:
/opt/mxe/usr/x86_64-w64-mingw32.static/qt5/lib/libQt5Network.a(qsslsocket_openssl.o):qsslsocket_openssl.cpp:(.text+0x139c): undefined reference to `__imp_CertCreateCertificateContext'
/opt/mxe/usr/x86_64-w64-mingw32.static/qt5/lib/libQt5Network.a(qsslsocket_openssl.o):qsslsocket_openssl.cpp:(.text+0x1441): undefined reference to `__imp_CertGetCertificateChain'
/opt/mxe/usr/x86_64-w64-mingw32.static/qt5/lib/libQt5Network.a(qsslsocket_openssl.o):qsslsocket_openssl.cpp:(.text+0x14c2): undefined reference to `__imp_CertFreeCertificateChain'
/opt/mxe/usr/x86_64-w64-mingw32.static/qt5/lib/libQt5Network.a(qsslsocket_openssl.o):qsslsocket_openssl.cpp:(.text+0x14cb): undefined reference to `__imp_CertFreeCertificateContext'
/opt/mxe/usr/x86_64-w64-mingw32.static/qt5/lib/libQt5Network.a(qnetworkinterface_win.o):qnetworkinterface_win.cpp:(.text+0x15): undefined reference to `ConvertInterfaceNameToLuidW'
/opt/mxe/usr/x86_64-w64-mingw32.static/qt5/lib/libQt5Network.a(qnetworkinterface_win.o):qnetworkinterface_win.cpp:(.text+0x2e): undefined reference to `ConvertInterfaceLuidToIndex'
/opt/mxe/usr/x86_64-w64-mingw32.static/qt5/lib/libQt5Network.a(qnetworkinterface_win.o):qnetworkinterface_win.cpp:(.text+0x5b): undefined reference to `ConvertInterfaceIndexToLuid'
/opt/mxe/usr/x86_64-w64-mingw32.static/qt5/lib/libQt5Network.a(qnetworkinterface_win.o):qnetworkinterface_win.cpp:(.text+0x75): undefined reference to `ConvertInterfaceLuidToNameW'
/opt/mxe/usr/x86_64-w64-mingw32.static/qt5/lib/libQt5Network.a(qnetworkinterface_win.o):qnetworkinterface_win.cpp:(.text+0xec): undefined reference to `GetNetworkParams'
/opt/mxe/usr/x86_64-w64-mingw32.static/qt5/lib/libQt5Network.a(qnetworkinterface_win.o):qnetworkinterface_win.cpp:(.text+0x1cd): undefined reference to `GetNetworkParams'
/opt/mxe/usr/x86_64-w64-mingw32.static/qt5/lib/libQt5Network.a(qnetworkinterface_win.o):qnetworkinterface_win.cpp:(.text+0x243): undefined reference to `GetAdaptersAddresses'
/opt/mxe/usr/x86_64-w64-mingw32.static/qt5/lib/libQt5Network.a(qnetworkinterface_win.o):qnetworkinterface_win.cpp:(.text+0x3c4): undefined reference to `ConvertInterfaceLuidToNameW'
/opt/mxe/usr/x86_64-w64-mingw32.static/qt5/lib/libQt5Network.a(qnetworkinterface_win.o):qnetworkinterface_win.cpp:(.text+0x91e): undefined reference to `GetAdaptersAddresses'
What did I miss? Are there some other modules I have to add? Is this problem related to me cross compiling using MXE (I didn't tag it as such for now)?
So far I found MXE - Undefined reference to Qt when cross compiling with cmake and mingw, which makes it seem like MXE might be the problem, but that one is not answered.
Qt's cmake module's dependencies must be messed up. You can manually link with Iphlpapi. Add target_link_libraries(... Iphlpapi) to the CMakeFile.txt and try linking again. You can easily find the necessary libraries by googling the name of the symbol. That will bring up the relevant MSDN page. When you scroll to the bottom, you'll see what library file needs to be linked to make that API available to your program.
The explicit link directive will be a no-op when the library is properly referenced by Qt's cmake module(s). You can also make this linking conditional on the target being Windows:
if (WIN32)
target_link_libraries (mytarget Iphlpapi)
endif ()

RcppGSL Windows installation trouble

I'm trying to install RcppGSL as presented in
Linking GSL library to RcppGSL on Windows machine
after copping the library as presented in the link above to C:/local323
and moving all the files in x64 up one directory into into LIB_GSL/lib as presented in the link. I used the following code.
library(Rcpp)
Sys.setenv("LIB_GSL" = "C:/local323") # this is where the library is located
Sys.setenv("PKG_LIBS"="-L(LIB_GSL)/lib -lgsl -lgslcblas")
install.packages("RcppGSL")
I added the line
Sys.setenv("PKG_LIBS"="-L(LIB_GSL)/lib -lgsl -lgslcblas")
after getting the following error(and I still got the same error) after doing some research and thought there might be a linking problem(just guessing).
The error I received was
RcppExports.o:RcppExports.cpp:(.text+0x916): undefined reference to `gsl_matrix_alloc'
RcppExports.o:RcppExports.cpp:(.text+0x945): undefined reference to `gsl_matrix_set'
RcppExports.o:RcppExports.cpp:(.text+0x993): undefined reference to `gsl_vector_calloc'
fastLm.o:fastLm.cpp:(.text+0x122): undefined reference to `gsl_vector_calloc'
fastLm.o:fastLm.cpp:(.text+0x131): undefined reference to `gsl_matrix_alloc'
fastLm.o:fastLm.cpp:(.text+0x142): undefined reference to `gsl_multifit_linear_alloc'
fastLm.o:fastLm.cpp:(.text+0x16d): undefined reference to `gsl_multifit_linear'
fastLm.o:fastLm.cpp:(.text+0x175): undefined reference to `gsl_multifit_linear_free'
fastLm.o:fastLm.cpp:(.text+0x24f): undefined reference to `gsl_matrix_diagonal'
setErrorHandler.o:setErrorHandler.cpp:(.text+0x104): undefined reference to `gsl_set_error_handler_off'
setErrorHandler.o:setErrorHandler.cpp:(.text+0x133): undefined reference to `gsl_set_error_handler'
any help is greatly appreciated!
Very best,
Steve
I would try this on the command-line, ie in cmd.exe -- not from R.
That way you should see the compilation and linking steps which may help when something go south.
"It builds at CRAN ..." so with the right files in the right location, and the proper env var set it should for you too.
Well I do not know why the following worked but I'm able to use RcppGSL
I followed the procedure from the link I posted exactly. Then instead of using
install.packages("RcppGSL")
I downloaded the zip file from CRAN and installed the package via the R GUI with the option to install from a zip. These should be identical I know, but using install.packages("RcppGSL").
Also
Sys.setenv("LIB_GSL" = "C:/local323")
is required anytime I try to compile an Rcpp file that uses the library.
I'm not sure why, but I can use the library at least.
Dirk thank you for your help. I will go over the tutorial on R-extensions to see if I can figure out what is going on.

vtk autoinit linker error

I have a very confusing (at least for me :) ) problem with linking to vtk-libraries. On one desktop pc, my code compiles without any error. I have an identical installation on another pc, but there, I get linker errors.
On both pc's are installed: itk 4.8, vtk 6.3 and cmake 3.3. Both are debian-systems (8.1 - jessie).
[ 96%] Linking CXX executable project
CMakeFiles/project.dir/main.cpp.o: In function vtkRenderingVolume_AutoInit::~vtkRenderingVolume_AutoInit()':
/usr/local/include/vtk-6.3/vtkRenderingVolumeModule.h:44: undefined reference tovtkRenderingVolumeOpenGL_AutoInit_Destruct()'
CMakeFiles/project.dir/main.cpp.o: In function vtkRenderingVolumeOpenGL_ModuleInit::~vtkRenderingVolumeOpenGL_ModuleInit()':
project/main.cpp:4: undefined reference tovtkRenderingVolumeOpenGL_AutoInit_Destruct()'
CMakeFiles/project.dir/main.cpp.o: In function vtkRenderingVolumeOpenGL_ModuleInit':
project/main.cpp:4: undefined reference tovtkRenderingVolumeOpenGL_AutoInit_Construct()'
CMakeFiles/project.dir/main.cpp.o: In function vtkRenderingVolume_AutoInit':
/usr/local/include/vtk-6.3/vtkRenderingVolumeModule.h:44: undefined reference tovtkRenderingVolumeOpenGL_AutoInit_Construct()'
libcommon.a(datareader.cpp.o): In function vtkRenderingVolume_AutoInit':
/usr/local/include/vtk-6.3/vtkRenderingVolumeModule.h:44: undefined reference tovtkRenderingVolumeOpenGL_AutoInit_Construct()'
collect2: error: ld returned 1 exit status
CMakeFiles/project.dir/build.make:326: recipe for target 'project' failed
I tried to fix those errors with adding
#include <vtkAutoInit.h>
VTK_MODULE_INIT(vtkRenderingOpenGL);
VTK_MODULE_INIT(vtkRenderingVolumeOpenGL);
to the file where I am using the vtk libraries, but it didn't help.
Does anyone know what I'm doing wrong? I am wondering, why it works on one of those pcs but not on the other one.
thank you very much!
Update: I fixed my problem by switching the position of
find_package(VTK REQUIRED)
include(${VTK_USE_FILE})
in the CMakeLists to the end. However, does anyone know, why it makes such a huge difference for different pcs?
As long as the VTK_USE_FILE is found, your code should compile correctly. In your other PC, VTK_USE_FILE was already found from a previous configuration and sits in a CMake cache entry, so that is why it compiles fine.
If your are using Nightly,
Your should put these in front of your including any vtk headers.
#include <vtkAutoInit.h>
VTK_MODULE_INIT(vtkRenderingOpenGL);
VTK_MODULE_INIT(vtkInteractionStyle);
VTK_MODULE_INIT(vtkRenderingFreeType);
VTK_MODULE_INIT(vtkRenderingVolumeOpenGL);
and link all the library you made from vtk source

Boost filesystem3 calls undefined

Encountering "boost::filesystem3" undefined reference errors while trying to link:
RawStreamReader.cpp:(.text._ZNK5boost11filesystem34path4leafEv[_ZNK5boost11filesystem34path4leafEv]+0x1f): undefined reference to `boost::filesystem3::path::filename() const'
This is on Linux 64.
I rebuilt the boost 1.55 with same c++11 options that I am using for my build.
The output from this symbol dump seems to indicate that none of the symbols contain "filesystem3" in the name (the 3 part is missing).
Note, that I have read these questions / answers (to no avail):
Failed at linking C++ [undefined reference boost::filesystem3 ... ]
c++ boost::filesystem undefined reference to `boost::filesystem3::path::root_name() const'
The code is compiling on other systems against same boost version. This is a fresh install with a new cmake build setup that I am trying to debug. All other boost libraries seem to be linking fine.

How to Install/Use libcurl with C++ on Windows/Eclipse CDT

Can someone please explain how to use libcurl with C++ on Windows with Eclipse CDT/Code::Blocks or a similar IDE?
I'm very new to C++ but I know my way around Java very well.
I'm using MinGW but I keep getting this error:
C:\Core\src>g++ -I"C:\curl\include\curl" -L"C:\curl\lib64" -lcurldll core.cpp -o
core.exe
C:\Users\Bob\AppData\Local\Temp\cc2BV0HI.o:core.cpp:(.text+0xc81): undefined
reference to `_imp__curl_easy_init'
C:\Users\Bob\AppData\Local\Temp\cc2BV0HI.o:core.cpp:(.text+0xca7): undefined
reference to `_imp__curl_easy_setopt'
C:\Users\Bob\AppData\Local\Temp\cc2BV0HI.o:core.cpp:(.text+0xcc4): undefined
reference to `_imp__curl_easy_setopt'
C:\Users\Bob\AppData\Local\Temp\cc2BV0HI.o:core.cpp:(.text+0xcd1): undefined
reference to `_imp__curl_easy_perform'
C:\Users\Bob\AppData\Local\Temp\cc2BV0HI.o:core.cpp:(.text+0xce1): undefined
reference to `_imp__curl_easy_cleanup
What I've Tried:
If I give the wrong library path/name it will tell me that it can not find the library. So clearly it FOUND the libcurldll.a/libcurl.a files but it isn't linking with them properly.
I've tried putting the actual libcurl.dll file from the bin into every source folder possible in my project.
I've tried going to C/C++ General > Paths and Symbols then added "curl" and "curldll" to libraries and "C:\curl\lib64" to the library search path.
I've tried manually adding the -lcurl, -lcurldll, -DCURL_STATICLIB, -L"C:\curl\lib64" options to the MinGW Linker tool.
This has been stumping me for days. Please help.