How to fix undefined reference to `__imp_WSACleanup' (Boost.Asio) in CLion - c++

My C++ project includes Boost and WebSocket++ libs. I read other topics I need to add -lws2_32 to gcc command, but I've CLion and I don't know how to fix it.
Console:
CMakeFiles\WsServer.dir/objects.a(main.cpp.obj): In function `boost::asio::detail::winsock_init_base::startup(boost::asio::detail::winsock_init_base::data&, unsigned char, unsigned char)':
C:/MinGW/include/boost/asio/detail/impl/winsock_init.ipp:39: undefined reference to `__imp_WSAStartup'
CMakeFiles\WsServer.dir/objects.a(main.cpp.obj): In function `boost::asio::detail::winsock_init_base::cleanup(boost::asio::detail::winsock_init_base::data&)':
C:/MinGW/include/boost/asio/detail/impl/winsock_init.ipp:56: undefined reference to `__imp_WSACleanup'
collect2.exe: error: ld returned 1 exit status
mingw32-make.exe[3]: *** [CMakeFiles\WsServer.dir\build.make:99: WsServer.exe] Error 1
mingw32-make.exe[2]: *** [CMakeFiles\Makefile2:67: CMakeFiles/WsServer.dir/all] Error 2
mingw32-make.exe[1]: *** [CMakeFiles\Makefile2:79: CMakeFiles/WsServer.dir/rule] Error 2
mingw32-make.exe: *** [Makefile:117: WsServer] Error 2
What I should do?

You can pass ws2_32 via target_link_libraries in your CMakeLists.txt, e.g.:
if(MINGW)
target_link_libraries(YourTargetName ws2_32)
endif()

Related

Want to build openthread for linux

I want to build openthread for Linux (POSIX) and using the library, I want to develop a CoAP client application.
Right now I have disabled UDP_FORWARD in Makefile-posix and enabled OPENTHREAD_CONFIG_PLATFORM_UDP_ENABLE 1 in src/core/config/platform.h file.
My build is failing with the following error:
Making all in apps Making all in cli CC ot_cli_ftd-main.o C
C ot_cli_mtd-main.o CCLD ot-cli-mtd CCLD ot-cli-ftd
../../../src/core/libopenthread-mtd.a(libopenthread_mtd_a-udp6.o): In
function `ot::Ip6::UdpSocket::Open(void (*)(void*, otMessage*,
otMessageInfo const*), void*)':
/home/projects/KNX/openthread/examples/../src/core/net/udp6.cpp:84:
undefined reference to `otPlatUdpSocket'
../../../src/core/libopenthread-mtd.a(libopenthread_mtd_a-udp6.o): In
function `ot::Ip6::UdpSocket::Bind(ot::Ip6::SockAddr const&)':
/home/projects/KNX/openthread/examples/../src/core/net/udp6.cpp:107:
undefined reference to `otPlatUdpBind'
../../../src/core/libopenthread-mtd.a(libopenthread_mtd_a-udp6.o): In
function `ot::Ip6::UdpSocket::Close()':
/home/projects/KNX/openthread/examples/../src/core/net/udp6.cpp:141:
undefined reference to `otPlatUdpClose'
../../../src/core/libopenthread-mtd.a(libopenthread_mtd_a-udp6.o): In
function `ot::Ip6::UdpSocket::SendTo(ot::Message&,
ot::Ip6::MessageInfo const&)':
/home/projects/KNX/openthread/examples/../src/core/net/udp6.cpp:193:
undefined reference to `otPlatUdpSend'
../../../src/core/libopenthread-mtd.a(libopenthread_mtd_a-udp6.o): In
function `ot::Ip6::UdpSocket::Bind(ot::Ip6::SockAddr const&)':
/home/projects/KNX/openthread/examples/../src/core/net/udp6.cpp:114:
undefined reference to `otPlatUdpBind'
../../../src/core/libopenthread-mtd.a(libopenthread_mtd_a-udp6.o): In
function `ot::Ip6::UdpSocket::Connect(ot::Ip6::SockAddr const&)':
/home/projects/KNX/openthread/examples/../src/core/net/udp6.cpp:130:
undefined reference to `otPlatUdpConnect' collect2: error: ld returned
1 exit status Makefile:1284: recipe for target 'ot-cli-mtd' failed
make[5]: *** [ot-cli-mtd] Error 1 make[5]: *** Waiting for unfinished
jobs....
../../../src/core/libopenthread-ftd.a(libopenthread_ftd_a-udp6.o): In
function `ot::Ip6::UdpSocket::Open(void (*)(void*, otMessage*,
otMessageInfo const*), void*)':
/home/projects/KNX/openthread/examples/../src/core/net/udp6.cpp:84:
undefined reference to `otPlatUdpSocket'
../../../src/core/libopenthread-ftd.a(libopenthread_ftd_a-udp6.o): In
function `ot::Ip6::UdpSocket::Bind(ot::Ip6::SockAddr const&)':
/home/projects/KNX/openthread/examples/../src/core/net/udp6.cpp:107:
undefined reference to `otPlatUdpBind'
../../../src/core/libopenthread-ftd.a(libopenthread_ftd_a-udp6.o): In
function `ot::Ip6::UdpSocket::Close()':
/home/projects/KNX/openthread/examples/../src/core/net/udp6.cpp:141:
undefined reference to `otPlatUdpClose'
../../../src/core/libopenthread-ftd.a(libopenthread_ftd_a-udp6.o): In
function `ot::Ip6::UdpSocket::SendTo(ot::Message&,
ot::Ip6::MessageInfo const&)':
/home/projects/KNX/openthread/examples/../src/core/net/udp6.cpp:193:
undefined reference to `otPlatUdpSend'
../../../src/core/libopenthread-ftd.a(libopenthread_ftd_a-udp6.o): In
function `ot::Ip6::UdpSocket::Bind(ot::Ip6::SockAddr const&)':
/home/projects/KNX/openthread/examples/../src/core/net/udp6.cpp:114:
undefined reference to `otPlatUdpBind'
../../../src/core/libopenthread-ftd.a(libopenthread_ftd_a-udp6.o): In
function `ot::Ip6::UdpSocket::Connect(ot::Ip6::SockAddr const&)':
/home/projects/KNX/openthread/examples/../src/core/net/udp6.cpp:130:
undefined reference to `otPlatUdpConnect' collect2: error: ld returned
1 exit status Makefile:1280: recipe for target 'ot-cli-ftd' failed
make[5]: *** [ot-cli-ftd] Error 1 Makefile:442: recipe for target
'all-recursive' failed make[4]: *** [all-recursive] Error 1
Makefile:444: recipe for target 'all-recursive' failed make[3]: ***
[all-recursive] Error 1 Makefile:601: recipe for target
'all-recursive' failed make[2]: *** [all-recursive] Error 1
Makefile:527: recipe for target 'all' failed make[1]: *** [all] Error
2 examples/Makefile-posix:295: recipe for target
'do-build-x86_64-unknown-linux-gnu' failed make: ***
[do-build-x86_64-unknown-linux-gnu] Error 2
My ultimate goal is to use openthread library and develop a Coap Client application. Can anybody help me on this?
Enabling OPENTHREAD_CONFIG_PLATFORM_UDP_ENABLE requires an implementation of the otPlatUdp* APIs.
For Linux, you can look to the POSIX app https://github.com/openthread/openthread/tree/master/src/posix.

CMake Linker Flags

I have a C++ code divided into 2 files image_desc_try.cpp, common.cpp and common.h. This code involves usage of Nvidia CUDA and NVidia NVInfer.
I could compile the entire code using the following with success.
g++ -std=c++11 image_desc_try.cpp common.cpp -I /usr/local/cuda/include -L /usr/local/cuda/lib64 -lcudart -lnvinfer -lnvparsers
Now, I am trying to do the same thing with CMake,
include_directories( "/usr/local/cuda/include" )
add_executable( desc_server
common.cpp
image_desc_try.cpp
)
target_link_libraries( desc_server
${catkin_LIBRARIES}
/usr/lib/aarch64-linux-gnu/libnvinfer.so
/usr/lib/aarch64-linux-gnu/libnvparsers.so
/usr/local/cuda-10.0/targets/aarch64-linux/lib/libcudart.so
)
This is giving me linking errors:
/usr/lib/gcc/aarch64-linux-gnu/7/../../../aarch64-linux-gnu/libnvparsers.so: undefined reference to `getPluginRegistry'
/usr/lib/gcc/aarch64-linux-gnu/7/../../../aarch64-linux-gnu/libnvparsers.so: undefined reference to `getInferLibVersion'
/usr/lib/gcc/aarch64-linux-gnu/7/../../../aarch64-linux-gnu/libnvparsers.so: undefined reference to `getLogger'
/usr/lib/gcc/aarch64-linux-gnu/7/../../../aarch64-linux-gnu/libnvparsers.so: undefined reference to `nvinfer1::utils::reshapeWeights(nvinfer1::Weights const&, int const*, int const*, void*, int)'
collect2: error: ld returned 1 exit status
tx2_whole_image_desc_server/CMakeFiles/desc_server.dir/build.make:157: recipe for target '/home/dji/catkin_ws/devel/lib/tx2_whole_image_desc_server/desc_server' failed
make[2]: *** [/home/dji/catkin_ws/devel/lib/tx2_whole_image_desc_server/desc_server] Error 1
CMakeFiles/Makefile2:1578: recipe for target 'tx2_whole_image_desc_server/CMakeFiles/desc_server.dir/all' failed
make[1]: *** [tx2_whole_image_desc_server/CMakeFiles/desc_server.dir/all] Error 2
Makefile:140: recipe for target 'all' failed
make: *** [all] Error 2
How to fix this?

Linker error while compiling GCC 8.2.0 related to libmpfr.so

I'm trying to compile GCC from scratch like I used to do when I used Linux a lot, I'm trying to install Sourcemage but the compiler version of GCC is 4.6 and the latest version is 8.2.0, so I compiled everything needed to compile GCC from scratch, and everything is going well while compiling the compiler until the very end when it starts giving me a linker error related to libmpfr.so:
Here's what I get when I do my typical make -j3:
/usr/lib/../lib/libmpfr.so: undefined reference to `__gmpn_com'
collect2: error: ld returned 1 exit status
make[3]: *** [../.././gcc/lto/Make-lang.in:81: lto1] Error 1
make[3]: *** Waiting for unfinished jobs....
/usr/lib/../lib/libmpfr.so: undefined reference to `__gmpn_com'
collect2: error: ld returned 1 exit status
make[3]: *** [../.././gcc/c/Make-lang.in:85: cc1] Error 1
/usr/lib/../lib/libmpfr.so: undefined reference to `__gmpn_com'
collect2: error: ld returned 1 exit status
make[3]: *** [../.././gcc/cp/Make-lang.in:120: cc1plus] Error 1
make[2]: *** [Makefile:4657: all-stage2-gcc] Error 2
make[1]: *** [Makefile:22203: stage2-bubble] Error 2
make: *** [Makefile:944: all] Error 2
If you want to look at the full output of the error then I provide a pastebin: https://pastebin.com/g5sn3jDv

undefined reference to `cv::imwrite(...)'

I want to compile doppia, which has OpenCV as a dependency. Currently I am using OpenCV 2.4.9.1, which is the default on Ubuntu 16.04. Everything works fine besides the references to the function imwrite.
...
[100%] Linking CXX executable objects_detection
undefined reference to `cv::imwrite(std::string const&, cv::_InputArray const&, std::vector<int, std::allocator<int> > const&)'
collect2: error: ld returned 1 exit status
CMakeFiles/objects_detection.dir/build.make:103: recipe for target 'objects_detection' failed
make[2]: *** [objects_detection] Error 1
CMakeFiles/Makefile2:104: recipe for target 'CMakeFiles/objects_detection.dir/all' failed
make[1]: *** [CMakeFiles/objects_detection.dir/all] Error 2
Makefile:83: recipe for target 'all' failed
make: *** [all] Error 2
The file that throws the error is IntegralChannelsDetector.cpp.
In it, both opencv2/imgproc/imgproc.hpp and opencv2/highgui/highgui.hpp are included.
Running pkg-config opencv --cflags --libs also returns that all modules are linked correctly.
Researching about my error I learnt that if I was using OpenCV 3.x I'd have to include the img_codecs module, but that is not the case for OpenCV 2.x. I fear I'm stuck on 2.x for compatibility reasons.
Is there something left I could try to get the linking process completed?

Normaliz undefined reference to `boost::system::system_category()'

I'm trying to install the library Normaliz having dependencies like CocoALib, SCIP. I've made its dependencies according to their guidances. However, I get the error while make of Normaliz on both Ubuntu and Mac OSX,
[ 81%] Linking CXX executable normaliz
libnormaliz/libnormaliz.so.3.4.0: undefined reference to `boost::system::system_category()'
libnormaliz/libnormaliz.so.3.4.0: undefined reference to `boost::system::generic_category()'
collect2: error: ld returned 1 exit status
CMakeFiles/normaliz.dir/build.make:99: recipe for target 'normaliz' failed
make[2]: *** [normaliz] Error 1
CMakeFiles/Makefile2:99: recipe for target 'CMakeFiles/normaliz.dir/all' failed
make[1]: *** [CMakeFiles/normaliz.dir/all] Error 2
Makefile:127: recipe for target 'all' failed
make: *** [all] Error 2
I really fed up with it since two weeks! How can it be overcome?
Even if it is boost linkage problem, how can it be linked? There is no option for it. That kinda headaches cause apathy to open-source at least for young programmers like me.