Boost filesystem3 calls undefined - c++

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.

Related

How to fix undefined references after libtorch custom build?

I've built libtorch from source (as shared objects) with the purpose of slimming it down, but now when I try to link it into an application, I get this:
error: undefined reference to 'std::invalid_argument::invalid_argument(char const*)'
...
error: undefined reference to 'torch::serialize::OutputArchive::write(std::string const&, at::Tensor const&, bool)'
This doesn't happen when I link with the corresponding pre-built libtorch instead. My application links with -lstdc++ -ltorch -ltorch_cpu -lc10. I've noticed that
Some of these undefined references are from std, others from torch. This surprises me - how is it possible I'm missing stuff from std when I'm linking in stdc++?
The pre-built libtorch includes several .so's I don't have, such as glom. None of these seem necessary to my application though, and I don't need to link them in when using pre-built libtorch.
So what might be the reason I'm getting these undefined references, or how can I go about debugging it?

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 ()

C++ build error using librealsense in ubuntu

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

How to solve mingw-w64 MSVCRT dependency issues

I'm building a golang project by using Go1.12 + msys2/mingw-w64(9.2.0), it shows errors:
D:\Go\pkg\tool\windows_amd64\link.exe: running gcc failed: exit status 1
D:/msys64/mingw64/bin/../lib/gcc/x86_64-w64-mingw32/9.2.0/../../../../x86_64-w64-mingw32/bin/ld.exe: D:/msys64/mingw64/bin/../lib/gcc/x86_64-w64-mingw32/9.2.0/../../../../x86_64-w64-mingw32/lib/../lib/crt2.o: in function `pre_c_init':
E:/mingwbuild/mingw-w64-crt-git/src/mingw-w64/mingw-w64-crt/crt/crtexe.c:146: undefined reference to `__p__fmode'
D:/msys64/mingw64/bin/../lib/gcc/x86_64-w64-mingw32/9.2.0/../../../../x86_64-w64-mingw32/bin/ld.exe: D:/msys64/mingw64/bin/../lib/gcc/x86_64-w64-mingw32/9.2.0/../../../../x86_64-w64-mingw32/lib/../lib/crt2.o: in function `__tmainCRTStartup':
E:/mingwbuild/mingw-w64-crt-git/src/mingw-w64/mingw-w64-crt/crt/crtexe.c:290: undefined reference to `_set_invalid_parameter_handler'
D:/msys64/mingw64/bin/../lib/gcc/x86_64-w64-mingw32/9.2.0/../../../../x86_64-w64-mingw32/bin/ld.exe: E:/mingwbuild/mingw-w64-crt-git/src/mingw-w64/mingw-w64-crt/crt/crtexe.c:299: undefined reference to `__p__acmdln'
D:/msys64/mingw64/bin/../lib/gcc/x86_64-w64-mingw32/9.2.0/../../../../x86_64-w64-mingw32/bin/ld.exe: D:/msys64/mingw64/bin/../lib/gcc/x86_64-w64-mingw32/9.2.0/../../../../x86_64-w64-mingw32/lib/../lib/libmingw32.a(lib64_libmingw32_a-merr.o): in function `_matherr':
E:/mingwbuild/mingw-w64-crt-git/src/mingw-w64/mingw-w64-crt/crt/merr.c:46: undefined reference to `__acrt_iob_func'
D:/msys64/mingw64/bin/../lib/gcc/x86_64-w64-mingw32/9.2.0/../../../../x86_64-w64-mingw32/bin/ld.exe: D:/msys64/mingw64/bin/../lib/gcc/x86_64-w64-mingw32/9.2.0/../../../../x86_64-w64-mingw32/lib/../lib/libmingw32.a(lib64_libmingw32_a-pseudo-reloc.o): in function `__report_error':
E:/mingwbuild/mingw-w64-crt-git/src/mingw-w64/mingw-w64-crt/crt/pseudo-reloc.c:149: undefined reference to `__acrt_iob_func'
D:/msys64/mingw64/bin/../lib/gcc/x86_64-w64-mingw32/9.2.0/../../../../x86_64-w64-mingw32/bin/ld.exe: E:/mingwbuild/mingw-w64-crt-git/src/mingw-w64/mingw-w64-crt/crt/pseudo-reloc.c:150: undefined reference to `__acrt_iob_func'
collect2.exe: error: ld returned 1 exit status
After some research I'm sure it's a msvcrt compatibility issue of mingw64.
I know there are workarounds like this: unresolved external symbol __imp__fprintf and __imp____iob_func, SDL2
But it doesn't solve all of my issues.
I try to link the library: LDFLAGS: -L%filepath% -llegacy_stdio_definitions, nothing changes.
Is there a patch to fix it, or do I have to build my custom version of mingw64?
So I answer my question by myself, the case is closed.
Yes, Mingw64 uses msvcrt.
Here are some tips that could help to solve dependency problems between Mingw64 & msvcrt.
The major goal is to let compiler load the correct version of MSVCRT library family.
1.Update Mingw64.
2.Check out MSVCRT_VERSION in Mingw64\include_mingw.h(or x86_64-w64-mingw32\include), make sure the version number matches your windows version, or modify it.
3.Take a look at linker option like "#cgo LDFLAGS: -Lxxx", don't mess the library path. Remove any unnecessary library path setting, let linker finds libraries itself.
Make sure everything is built with same libraries.

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.