Boost undefined references cross compiling linux to windows - c++

I'm trying to cross compile from linux to windows using boost. I've already cross-compiled boost and I do have the DLL, but when I'm linking, I'm getting several undefined references :
src/client/CommunicationHandler.o:CommunicationHandler.cpp:(.text+0x170): undefined reference to `boost::asio::io_service::io_service()'
src/client/CommunicationHandler.o:CommunicationHandler.cpp:(.text+0x1b7): undefined reference to boost::asio::ip::address_v4::from_string(std::__cxx11::basic_string, std::allocator > const&)'
src/client/CommunicationHandler.o:CommunicationHandler.cpp:(.text+0x1c7): undefined reference to boost::asio::ip::address::address(boost::asio::ip::address_v4 const&)'
src/client/CommunicationHandler.o:CommunicationHandler.cpp:(.text+0x54e): undefined reference to `boost::asio::io_service::~io_service()'
src/client/CommunicationHandler.o:CommunicationHandler.cpp:(.text+0x5c0): undefined reference to `boost::asio::io_service::~io_service()'
src/client/CommunicationHandler.o:CommunicationHandler.cpp:(.text+0x97e): undefined reference to `boost::asio::io_service::run()'
src/client/CommunicationHandler.o:CommunicationHandler.cpp:(.text$_ZN5boost4asio2ip14basic_endpointINS1_3tcpEEC1ERKNS1_7addressEt[_ZN5boost4asio2ip14basic_endpointINS1_3tcpEEC1ERKNS1_7addressEt]+0x2a): undefined reference to boost::asio::ip::detail::endpoint::endpoint(boost::asio::ip::address const&, unsigned short)'
src/client/CommunicationHandler.o:CommunicationHandler.cpp:(.text$_ZN5boost4asio2ip16resolver_serviceINS1_3tcpEE7destroyERSt10shared_ptrIvE[_ZN5boost4asio2ip16resolver_serviceINS1_3tcpEE7destroyERSt10shared_ptrIvE]+0x20): undefined reference to boost::asio::detail::resolver_service_base::destroy(std::shared_ptr&)'
...etc
Why does the symbols are not in the DLL? What shall I do to make it link properly?

this make it works
#ifndef BOOST_SYSTEM_USE_LIB
# define BOOST_SYSTEM_USE_LIB
#endif

Related

Compiling of complex_Bessel_function library - linking with Fortran code - mex file

I have made a .cpp code that uses the following online library:
Complex_Bessel_functions.
I want to make a .mex file out of my code. When I am typing:
mex GUSTAVsolution.cpp
Matlab gives the following errors:
Error using mex
/tmp/mex_7456790284416_24518/GUSTAVsolution.o: In function `MIEsolution::Spherical_Hankel_function(unsigned int,
std::complex<double>, int)':
GUSTAVsolution.cpp:(.text+0x18c): undefined reference to `zbesh_wrap'
GUSTAVsolution.cpp:(.text+0x28e): undefined reference to `zbesh_wrap'
/tmp/mex_7456790284416_24518/GUSTAVsolution.o: In function `MIEsolution::Spherical_Bessel_function_2k(unsigned int,
std::complex<double>)':
GUSTAVsolution.cpp:(.text+0x3dc): undefined reference to `zbesy_wrap'
GUSTAVsolution.cpp:(.text+0x53d): undefined reference to `zbesj_wrap'
/tmp/mex_7456790284416_24518/GUSTAVsolution.o: In function `MIEsolution::Spherical_Bessel_function_1k(unsigned int,
std::complex<double>)':
GUSTAVsolution.cpp:(.text+0x7a0): undefined reference to `zbesj_wrap'
GUSTAVsolution.cpp:(.text+0x907): undefined reference to `zbesy_wrap'
/tmp/mex_7456790284416_24518/GUSTAVsolution.o: In function
`MIEsolution::Differentation_Spherical_Hankel_function(unsigned int, std::complex<double>, int)':
GUSTAVsolution.cpp:(.text+0xb32): undefined reference to `zbesh_wrap'
GUSTAVsolution.cpp:(.text+0xc4f): undefined reference to `zbesh_wrap'
GUSTAVsolution.cpp:(.text+0xd30): undefined reference to `zbesh_wrap'
GUSTAVsolution.cpp:(.text+0xe4d): undefined reference to `zbesh_wrap'
/tmp/mex_7456790284416_24518/GUSTAVsolution.o: In function
`MIEsolution::Differentation_Spherical_Bessel_function(unsigned int, std::complex<double>, int)':
GUSTAVsolution.cpp:(.text+0xfb8): undefined reference to `zbesj_wrap'
GUSTAVsolution.cpp:(.text+0x112b): undefined reference to `zbesy_wrap'
GUSTAVsolution.cpp:(.text+0x1303): undefined reference to `zbesj_wrap'
GUSTAVsolution.cpp:(.text+0x1476): undefined reference to `zbesy_wrap'
GUSTAVsolution.cpp:(.text+0x161a): undefined reference to `zbesy_wrap'
GUSTAVsolution.cpp:(.text+0x1787): undefined reference to `zbesj_wrap'
GUSTAVsolution.cpp:(.text+0x1935): undefined reference to `zbesy_wrap'
GUSTAVsolution.cpp:(.text+0x1aa2): undefined reference to `zbesj_wrap'
collect2: error: ld returned 1 exit status
One of my functions that these errors happen is:
complex<double> MIEsolution::Spherical_Bessel_function_2k(unsigned n,complex<double> z){
complex<double> Sb2k;
Sb2k = sph_besselY(n, z);
return Sb2k;
}
The point is that this library connects some Fortran code with C++. For example, the sph_besselY function will call the appropriate Fortran code zbesy_wrap.
Am I suppose to compile the Fortran functions somehow? I installed the library the same way as the webpage does. Also, I am importing the library to my code, like that:
#include <complex_bessel.h>
To fix this add the linker flag -lcomplex_bessel, as suggested here:
Compile simpleTest.cpp errors
in Code::Blocks IDE I set this flag in Project->Build Options...->Linker Settings->Other linker options: text-box.
As for the mex, I don't know if this one mex GUSTAVsolution.cpp -lcomplex_bessel is going to work, but for sure you should add this linker flag somehow!

Lubuntu MinGW undefined references [missing GL libraries?]

Trying to compile a third party library on MinGW in Code::Blocks on Lubuntu, and despite my absolute best efforts to eliminate the following undefined references which I've spent ages on, nothing is fixing the issues:
undefined reference to `_sfwgl_ext_EXT_swap_control
undefined reference to `_sfwgl_ext_ARB_pixel_format
undefined reference to `_sf_ptrc_wglChoosePixelFormatARB
undefined reference to `_sf_ptrc_wglGetPixelFormatAttribivARB
undefined reference to `_sfwgl_ext_ARB_multisample
undefined reference to `_sf_ptrc_wglGetPixelFormatAttribivARB
undefined reference to `_sfwgl_ext_ARB_pixel_format
undefined reference to `_sfwgl_ext_ARB_create_context
undefined reference to `_sfwgl_ext_ARB_create_context_profile
undefined reference to `_sf_ptrc_wglCreateContextAttribsARB
undefined reference to `_sf_ptrc_wglCreateContextAttribsARB
undefined reference to `_sf_ptrc_wglGetPixelFormatAttribivARB
undefined reference to `_sfwgl_ext_ARB_multisample
undefined reference to `_sf_ptrc_wglGetPixelFormatAttribivARB
undefined reference to `_sfwgl_LoadFunctions
From what I can tell is it's possibly some sort of missing GL library or graphics library, however I already have opengl32, gdi32, glu32, glut32 and gle added to the link library which has left the following undefined references untouched.
How do I fix the above errors?
[If it is a missing library or libraries, could I be linked to the download page for the appropriate headers and .a files for MinGW on linux? Thanks.]

Eclipse, MinGW, Freeglut undefined reference

I've been trying to compile this OpenGL tutorial (originally purposed for Visual Studio) but I keep having 'undefined reference' errors. The compiler output is as follows:
Info: Internal Builder is used for build
g++ -o OpenGLTutorial.exe "src\\main.o" "src\\Camera.o" -lglew32 -lglu32 -lopengl32 -lfreeglut
src\main.o: In function `Z6InitGLiPPc':
C:\Users\jordanrich\Documents\programming\C++\GameDev\OpenGLTutorial\Debug/../src/main.cpp:75: undefined reference to `glutInit'
C:\Users\jordanrich\Documents\programming\C++\GameDev\OpenGLTutorial\Debug/../src/main.cpp:76: undefined reference to `glutSetOption'
C:\Users\jordanrich\Documents\programming\C++\GameDev\OpenGLTutorial\Debug/../src/main.cpp:77: undefined reference to `glutGet'
C:\Users\jordanrich\Documents\programming\C++\GameDev\OpenGLTutorial\Debug/../src/main.cpp:78: undefined reference to `glutGet'
C:\Users\jordanrich\Documents\programming\C++\GameDev\OpenGLTutorial\Debug/../src/main.cpp:80: undefined reference to `glutInitDisplayMode'
C:\Users\jordanrich\Documents\programming\C++\GameDev\OpenGLTutorial\Debug/../src/main.cpp:82: undefined reference to `glutInitContextVersion'
C:\Users\jordanrich\Documents\programming\C++\GameDev\OpenGLTutorial\Debug/../src/main.cpp:83: undefined reference to `glutInitContextProfile'
C:\Users\jordanrich\Documents\programming\C++\GameDev\OpenGLTutorial\Debug/../src/main.cpp:84: undefined reference to `glutInitContextFlags'
C:\Users\jordanrich\Documents\programming\C++\GameDev\OpenGLTutorial\Debug/../src/main.cpp:86: undefined reference to `glutInitWindowPosition'
C:\Users\jordanrich\Documents\programming\C++\GameDev\OpenGLTutorial\Debug/../src/main.cpp:87: undefined reference to `glutInitWindowSize'
C:\Users\jordanrich\Documents\programming\C++\GameDev\OpenGLTutorial\Debug/../src/main.cpp:89: undefined reference to `glutCreateWindow'
C:\Users\jordanrich\Documents\programming\C++\GameDev\OpenGLTutorial\Debug/../src/main.cpp:91: undefined reference to `glutIdleFunc'
C:\Users\jordanrich\Documents\programming\C++\GameDev\OpenGLTutorial\Debug/../src/main.cpp:92: undefined reference to `glutDisplayFunc'
C:\Users\jordanrich\Documents\programming\C++\GameDev\OpenGLTutorial\Debug/../src/main.cpp:93: undefined reference to `glutKeyboardFunc'
C:\Users\jordanrich\Documents\programming\C++\GameDev\OpenGLTutorial\Debug/../src/main.cpp:94: undefined reference to `glutKeyboardUpFunc'
C:\Users\jordanrich\Documents\programming\C++\GameDev\OpenGLTutorial\Debug/../src/main.cpp:95: undefined reference to `glutSpecialFunc'
C:\Users\jordanrich\Documents\programming\C++\GameDev\OpenGLTutorial\Debug/../src/main.cpp:96: undefined reference to `glutSpecialUpFunc'
C:\Users\jordanrich\Documents\programming\C++\GameDev\OpenGLTutorial\Debug/../src/main.cpp:97: undefined reference to `glutMouseFunc'
C:\Users\jordanrich\Documents\programming\C++\GameDev\OpenGLTutorial\Debug/../src/main.cpp:98: undefined reference to `glutMotionFunc'
C:\Users\jordanrich\Documents\programming\C++\GameDev\OpenGLTutorial\Debug/../src/main.cpp:99: undefined reference to `glutReshapeFunc'
src\main.o: In function `main':
C:\Users\jordanrich\Documents\programming\C++\GameDev\OpenGLTutorial\Debug/../src/main.cpp:236: undefined reference to `glutMainLoop'
src\main.o: In function `Z9ReshapeGLii':
C:\Users\jordanrich\Documents\programming\C++\GameDev\OpenGLTutorial\Debug/../src/main.cpp:249: undefined reference to `glutPostRedisplay'
src\main.o: In function `Z9DisplayGLv':
C:\Users\jordanrich\Documents\programming\C++\GameDev\OpenGLTutorial\Debug/../src/main.cpp:262: undefined reference to `glutSwapBuffers'
src\main.o: In function `Z6IdleGLv':
C:\Users\jordanrich\Documents\programming\C++\GameDev\OpenGLTutorial\Debug/../src/main.cpp:278: undefined reference to `glutPostRedisplay'
src\main.o: In function `Z10KeyboardGLhii':
C:\Users\jordanrich\Documents\programming\C++\GameDev\OpenGLTutorial\Debug/../src/main.cpp:313: undefined reference to `glutLeaveMainLoop'
collect2.exe: error: ld returned 1 exit status
21:39:05 Build Finished (took 1s.154ms)
Can anyone tell me what is wrong?
If you need any more information to help answer the question just ask.
Edit (Some additional info):
As you can see from the compiler output I have linked the library that these functions require and the compiler does not complain that it could not find said library. Also I placed the freeglut dll into the binary folder.
This problem was apparently mainly due to user error and was completely circumstantial. I'm posting this for the people of the future who might have this problem.
In my header file I defined FREEGLUT_STATIC. After changing this to another variable, the linker no longer produced errors. Though I can't actually check -- very easily at least -- somewhere in my freeglut library this variable was used in an ifndef statement to determine whether freeglut needed to be linked (in case it was already linked).

How can I verify linked libraries?

I am having lots of trouble getting a specific set of drivers working, called libnifalcon.
I am pretty sure that the installation was successful, but when I try to compile the example programs I get the errors:
mars#marslab:~/Documents/libnifalcon-1.0/examples/findfalcons$ g++ findfalcons.cpp
/tmp/cc8TtfGn.o: In function `runFalconTest()':
findfalcons.cpp:(.text+0x6b): undefined reference to `libnifalcon::FalconDevice::FalconDevice()'
findfalcons.cpp:(.text+0xdd): undefined reference to `libnifalcon::FalconDevice::getDeviceCount(unsigned int&)'
findfalcons.cpp:(.text+0x1bd): undefined reference to `libnifalcon::FalconDevice::open(unsigned int)'
findfalcons.cpp:(.text+0x224): undefined reference to `libnifalcon::FalconDevice::isFirmwareLoaded()'
findfalcons.cpp:(.text+0x2ac): undefined reference to `libnifalcon::FalconFirmware::loadFirmware(bool, unsigned int const&, unsigned char*)'
findfalcons.cpp:(.text+0x33b): undefined reference to `libnifalcon::FalconDevice::isFirmwareLoaded()'
findfalcons.cpp:(.text+0x3dd): undefined reference to `libnifalcon::FalconDevice::runIOLoop(unsigned int)'
findfalcons.cpp:(.text+0x504): undefined reference to `libnifalcon::FalconDevice::runIOLoop(unsigned int)'
findfalcons.cpp:(.text+0x512): undefined reference to `libnifalcon::FalconDevice::close()'
findfalcons.cpp:(.text+0x52b): undefined reference to `libnifalcon::FalconDevice::~FalconDevice()'
findfalcons.cpp:(.text+0x53f): undefined reference to `libnifalcon::FalconDevice::~FalconDevice()'
/tmp/cc8TtfGn.o: In function `void libnifalcon::FalconDevice::setFalconFirmware<libnifalcon::FalconFirmwareNovintSDK>()':
findfalcons.cpp:(.text._ZN11libnifalcon12FalconDevice17setFalconFirmwareINS_23FalconFirmwareNovintSDKEEEvv[void libnifalcon::FalconDevice::setFalconFirmware<libnifalcon::FalconFirmwareNovintSDK>()]+0x1d): undefined reference to `libnifalcon::FalconFirmwareNovintSDK::FalconFirmwareNovintSDK()'
collect2: ld returned 1 exit status
How can I verify the libraries are linked correctly? What can I do if they aren't?
You're not linking with anything, i.e.
g++ file.cpp
does not link to any libraries other than the standard library. You need to link with other modules or libraries, probably libnifalcon
g++ findfalcons.cpp -lnifalcon
or... you probably will need to do something like
g++ -L/path/to/libnifalcon findfalcons.cpp -lnifalcon
where -I tells where to look for libraries.

ROS Linking errors using boost::filesystem library using C++ under linux

I get the following errors:
CMakeFiles/ndt_visualiser.dir/src/fromFile.o: In function `boost::filesystem3::path::codecvt()':
/usr/include/boost/filesystem/v3/path.hpp:377: undefined reference to `boost::filesystem3::path::wchar_t_codecvt_facet()'
CMakeFiles/ndt_visualiser.dir/src/fromFile.o: In function `directory_iterator':
/usr/include/boost/filesystem/v3/operations.hpp:594: undefined reference to `boost::filesystem3::detail::directory_iterator_construct(boost::filesystem3::directory_iterator&, boost::filesystem3::path const&, boost::system::error_code*)'
CMakeFiles/ndt_visualiser.dir/src/fromFile.o: In function `boost::filesystem3::path::codecvt()':
/usr/include/boost/filesystem/v3/path.hpp:377: undefined reference to `boost::filesystem3::path::wchar_t_codecvt_facet()'
CMakeFiles/ndt_visualiser.dir/src/fromFile.o: In function `path<boost::filesystem3::directory_entry>':
/usr/include/boost/filesystem/v3/path.hpp:134: undefined reference to `boost::filesystem3::path_traits::dispatch(boost::filesystem3::directory_entry const&, std::basic_string<char, std::char_traits<char>, std::allocator<char> >&, std::codecvt<wchar_t, char, __mbstate_t> const&)'
CMakeFiles/ndt_visualiser.dir/src/fromFile.o: In function `is_directory':
/usr/include/boost/filesystem/v3/operations.hpp:223: undefined reference to `boost::filesystem3::detail::status(boost::filesystem3::path const&, boost::system::error_code*)'
CMakeFiles/ndt_visualiser.dir/src/fromFile.o: In function `boost::iterator_facade<boost::filesystem3::directory_iterator, boost::filesystem3::directory_entry, boost::single_pass_traversal_tag, boost::filesystem3::directory_entry&, int>::operator++()':
/usr/include/boost/filesystem/v3/operations.hpp:630: undefined reference to `boost::filesystem3::detail::directory_iterator_increment(boost::filesystem3::directory_iterator&, boost::system::error_code*)'
CMakeFiles/ndt_visualiser.dir/src/fromFile.o: In function `boost::filesystem3::path::codecvt()':
/usr/include/boost/filesystem/v3/path.hpp:377: undefined reference to `boost::filesystem3::path::wchar_t_codecvt_facet()'
CMakeFiles/ndt_visualiser.dir/src/fromFile.o: In function `is_directory':
/usr/include/boost/filesystem/v3/operations.hpp:223: undefined reference to `boost::filesystem3::detail::status(boost::filesystem3::path const&, boost::system::error_code*)'
CMakeFiles/ndt_visualiser.dir/src/fromFile.o: In function `~dir_itr_imp':
/usr/include/boost/filesystem/v3/operations.hpp:563: undefined reference to `boost::filesystem3::detail::dir_itr_close(void*&, void*&)'
/usr/include/boost/filesystem/v3/operations.hpp:563: undefined reference to `boost::filesystem3::detail::dir_itr_close(void*&, void*&)'
CMakeFiles/ndt_visualiser.dir/src/fromFile.o: In function `__static_initialization_and_destruction_0':
/usr/include/boost/system/error_code.hpp:214: undefined reference to `boost::system::generic_category()'
/usr/include/boost/system/error_code.hpp:215: undefined reference to `boost::system::generic_category()'
/usr/include/boost/system/error_code.hpp:216: undefined reference to `boost::system::system_category()'
I've seen quite a few posts with similar errors. In pretty much all of those posts (e.g. Linking Boost Library in Linux) it seems the solution is, that you need to add the -lboost_filesystem and -lboost_system flags. I've tried adding these as lflags or cflags to the manifest.xml, but that changes absolutely nothing. And I've tried adding something to the CMakeLists.txt of my package, but I guess I was doing that wrong.
So any ideas?
You'll need to add lines like the following to your CMakeLists.txt:
rosbuild_add_boost_directories()
rosbuild_link_boost(ndt_visualizer filesystem system)
See http://www.ros.org/wiki/rosbuild/CMakeLists#rosbuild_link_boost for some more details.
Adding lines to the lflags or cflags in you manifest affects other packages linking against yours, not yours linking against others.
In the future, ROS questions are better asked on ROS Answers per the Support Guidelines
Just as a small follow-up, I was having a problem with undefined references to something involving file statuses and error codes.
The problem came up with the ordering library linking ("less dependent" libraries come after "more dependent" libraries, at least with GCC). My project used a custom library whcih was dependent on Boost.Filesystem and yaml-cpp. Before, I had my custom library linked after the boost libraries, bu that did not work. I had to fix it by making sure that boost was linked afterwards:
rosbuild_add_boost_directories()
rosbuild_add_executable(${PROJECT_NAME} ${SRCS})
target_link_libraries(${PROJECT_NAME} custom_lib yaml-cpp)
rosbuild_link_boost(${PROJECT_NAME} filesystem system)