I have a large codebase with multiple files and multiple Cmake files as well. The structure is src/folder1 src/folder2 etc and I run catkin_make -j1 from the src directory level. I am unable to link MKL. A small clip of the error is
/usr/bin/ld: /opt/intel/oneapi/mkl/2021.3.0/lib/intel64/libmkl_intel_thread.so: undefined reference to `mkl_sparse_d_xESB_SpMV_8_i4'
/usr/bin/ld: /opt/intel/oneapi/mkl/2021.3.0/lib/intel64/libmkl_intel_thread.so: undefined reference to `mkl_spblas_zcoo0ssunc__mmout_par'
/usr/bin/ld: /opt/intel/oneapi/mkl/2021.3.0/lib/intel64/libmkl_intel_thread.so: undefined reference to `mkl_spblas_zcoo1ntuuf__mmout_par'
/usr/bin/ld: /opt/intel/oneapi/mkl/2021.3.0/lib/intel64/libmkl_intel_thread.so: undefined reference to `mkl_spblas_lp64_scsr0ntunc__smout_par'
/usr/bin/ld: /opt/intel/oneapi/mkl/2021.3.0/lib/intel64/libmkl_intel_thread.so: undefined reference to `mkl_spblas_lp64_ccsr0nd_nc__svout_seq'
/usr/bin/ld: /opt/intel/oneapi/mkl/2021.3.0/lib/intel64/libmkl_intel_thread.so: undefined reference to `mkl_spblas_ccoo1stlnf__svout_seq'
/usr/bin/ld: /opt/intel/oneapi/mkl/2021.3.0/lib/intel64/libmkl_intel_thread.so: undefined reference to `mkl_pds_pds_her_pos_fwd_ker_seq_nrhs_cmplx'
collect2: error: ld returned 1 exit status
I even added the following line to each cmake:
SET(GCC_COVERAGE_LINK_FLAGS " -L${MKLROOT}/lib/intel64 -Wl,--no-as-needed -lmkl_intel_ilp64 -lmkl_gnu_thread -lmkl_core -lgomp -lpthread -lm -ldl")
The code does not use MKL BLAS directly but rather it is used by libraries like Opencv and Eigen (OpenCV was built with MKL).
I do define EIGEN_USE_MKL_ALL.
How do I link MKL?
You can make use of oneMKL link line advisor which recommends what are the required libraries and necessary compiler options for the use case on which you are working.
Here is the link
https://software.intel.com/content/www/us/en/develop/tools/oneapi/components/onemkl/link-line-advisor.html
Related
I have been trying very hard to set up OpenVINO for my C++ programme. But the official guide was very unclear to me (partially because I am a very beginner). I was struggling to understand how it finds "InferenceEngine_LIBRARIES" (or "OpenCV_LIBS") without even defining it.
I have tried to understand some examples in GitHub but sadly many of them are for older versions. I was wondering if I could have a minimum demo of the CMakeLists.txt to use the OpenVINO. Thank you very much.
--- Updates ---
Thanks for the comments. I understand some things were handled by CMake behind the scene. Going to the point, here is my CMakeLists file
cmake_minimum_required(VERSION 3.21)
project(openvino)
set(CMAKE_CXX_STANDARD 14)
# OpenVINO
set(ngraph_DIR "/opt/intel/openvino_2021/deployment_tools/ngraph/cmake")
find_package(ngraph REQUIRED)
set(InferenceEngine_DIR "/opt/intel/openvino_2021/deployment_tools/inference_engine/share")
find_package(InferenceEngine REQUIRED)
set(OpenCV_DIR "/opt/intel/openvino_2021/opencv/cmake")
find_package(OpenCV REQUIRED)
add_executable(openvino main.cpp)
target_link_libraries(
${PROJECT_NAME}
PRIVATE ${InferenceEngine_LIBRARIES}
${OpenCV_LIBS}
${NGRAPH_LIBRARIES})
And my "main.cpp" is just
#include <inference_engine.hpp>
int main() {
InferenceEngine::Core core;
InferenceEngine::ExecutableNetwork executable_network;
executable_network = core.LoadNetwork("./models/decoder.xml", "CPU");
auto infer_request = executable_network.CreateInferRequest();
return 0;
}
But When I build it, I got the following error, and I would like to ask for any help. Thank you very much!
====================[ Build | openvino | Debug ]================================
/home/kent/.local/share/JetBrains/Toolbox/apps/CLion/ch-0/213.6777.58/bin/cmake/linux/bin/cmake --build /media/kent/DISK2/CLionProjects/openvino/cmake-build-debug --target openvino
[2/2] Linking CXX executable openvino
FAILED: openvino
: && /usr/bin/c++ -g CMakeFiles/openvino.dir/main.cpp.o -o openvino -Wl,-rpath,/opt/intel/openvino_2021/opencv/lib:/opt/intel/openvino_2021/deployment_tools/inference_engine/lib/intel64:/opt/intel/openvino_2021/deployment_tools/ngraph/lib /opt/intel/openvino_2021/opencv/lib/libopencv_gapi.so.4.5.3 /opt/intel/openvino_2021/opencv/lib/libopencv_highgui.so.4.5.3 /opt/intel/openvino_2021/opencv/lib/libopencv_ml.so.4.5.3 /opt/intel/openvino_2021/opencv/lib/libopencv_objdetect.so.4.5.3 /opt/intel/openvino_2021/opencv/lib/libopencv_photo.so.4.5.3 /opt/intel/openvino_2021/opencv/lib/libopencv_stitching.so.4.5.3 /opt/intel/openvino_2021/opencv/lib/libopencv_video.so.4.5.3 /opt/intel/openvino_2021/opencv/lib/libopencv_videoio.so.4.5.3 /opt/intel/openvino_2021/opencv/lib/libopencv_dnn.so.4.5.3 /opt/intel/openvino_2021/deployment_tools/inference_engine/lib/intel64/libinference_engine.so /opt/intel/openvino_2021/deployment_tools/inference_engine/lib/intel64/libinference_engine_c_api.so /opt/intel/openvino_2021/deployment_tools/ngraph/lib/libngraph.so /opt/intel/openvino_2021/opencv/lib/libopencv_imgcodecs.so.4.5.3 /opt/intel/openvino_2021/opencv/lib/libopencv_calib3d.so.4.5.3 /opt/intel/openvino_2021/opencv/lib/libopencv_features2d.so.4.5.3 /opt/intel/openvino_2021/opencv/lib/libopencv_flann.so.4.5.3 /opt/intel/openvino_2021/opencv/lib/libopencv_imgproc.so.4.5.3 /opt/intel/openvino_2021/opencv/lib/libopencv_core.so.4.5.3 && :
/usr/bin/ld: warning: libtbb.so.2, needed by /opt/intel/openvino_2021/deployment_tools/inference_engine/lib/intel64/libinference_engine.so, not found (try using -rpath or -rpath-link)
/usr/bin/ld: /opt/intel/openvino_2021/deployment_tools/inference_engine/lib/intel64/libinference_engine.so: undefined reference to `tbb::interface7::internal::task_arena_base::internal_max_concurrency(tbb::interface7::task_arena const*)'
/usr/bin/ld: /opt/intel/openvino_2021/deployment_tools/inference_engine/lib/intel64/libinference_engine.so: undefined reference to `tbb::interface7::internal::task_arena_base::internal_initialize()'
/usr/bin/ld: /opt/intel/openvino_2021/deployment_tools/inference_engine/lib/intel64/libinference_engine.so: undefined reference to `tbb::internal::task_scheduler_observer_v3::observe(bool)'
/usr/bin/ld: /opt/intel/openvino_2021/deployment_tools/inference_engine/lib/intel64/libinference_engine.so: undefined reference to `tbb::internal::concurrent_vector_base_v3::internal_grow_by(unsigned long, unsigned long, void (*)(void*, void const*, unsigned long), void const*)'
/usr/bin/ld: /opt/intel/openvino_2021/deployment_tools/inference_engine/lib/intel64/libinference_engine.so: undefined reference to `tbb::internal::concurrent_vector_base_v3::~concurrent_vector_base_v3()'
/usr/bin/ld: /opt/intel/openvino_2021/deployment_tools/inference_engine/lib/intel64/libinference_engine.so: undefined reference to `tbb::internal::NFS_Allocate(unsigned long, unsigned long, void*)'
/usr/bin/ld: /opt/intel/openvino_2021/deployment_tools/inference_engine/lib/intel64/libinference_engine.so: undefined reference to `tbb::internal::concurrent_vector_base_v3::internal_clear(void (*)(void*, unsigned long))'
/usr/bin/ld: /opt/intel/openvino_2021/deployment_tools/inference_engine/lib/intel64/libinference_engine.so: undefined reference to `tbb::interface7::internal::task_arena_base::internal_current_slot()'
/usr/bin/ld: /opt/intel/openvino_2021/deployment_tools/inference_engine/lib/intel64/libinference_engine.so: undefined reference to `tbb::internal::allocate_via_handler_v3(unsigned long)'
/usr/bin/ld: /opt/intel/openvino_2021/deployment_tools/inference_engine/lib/intel64/libinference_engine.so: undefined reference to `tbb::interface7::internal::task_arena_base::internal_execute(tbb::interface7::internal::delegate_base&) const'
/usr/bin/ld: /opt/intel/openvino_2021/deployment_tools/inference_engine/lib/intel64/libinference_engine.so: undefined reference to `tbb::interface7::internal::task_arena_base::internal_terminate()'
/usr/bin/ld: /opt/intel/openvino_2021/deployment_tools/inference_engine/lib/intel64/libinference_engine.so: undefined reference to `tbb::internal::NFS_Free(void*)'
/usr/bin/ld: /opt/intel/openvino_2021/deployment_tools/inference_engine/lib/intel64/libinference_engine.so: undefined reference to `tbb::internal::thread_get_id_v3()'
/usr/bin/ld: /opt/intel/openvino_2021/deployment_tools/inference_engine/lib/intel64/libinference_engine.so: undefined reference to `tbb::internal::deallocate_via_handler_v3(void*)'
collect2: error: ld returned 1 exit status
ninja: build stopped: subcommand failed.
The linker error shows that it cannot find the TBB symbols. The TBB library should be pointed to by the TBB_DIR variable. You don't have to set those variables manually using cmake's set() function. Instead - in the shell where you compile your own app - you can source OpenVINO's setupvars.sh script. Just run something like: source /opt/intel/openvino_2021/bin/setupvars.sh and re-run the compiler.
I can see you're using CLion, not the terminal directly. In that case you can try adding the variable manually. The TBB location might be slightly different between the OV versions but in general it should point to a subdirectory of /opt/intel/openvino_2021 - just browse the installation directory and try to find it or source setupvars.sh in the terminal and copy the TBB_DIR env var value to your IDE.
I'm just making my way through finishing the boost http server project, which was written in visual studio using msvc compiler. All went well until I started porting this to linux. Here's a linking error displayed in console
http_server.cpp:(.text+0x995): undefined reference to `vtable for boost::detail::thread_data_base'
/usr/bin/ld: http_server.cpp:(.text+0xa05): undefined reference to `pthread_condattr_setclock'
/usr/bin/ld: http_server.cpp:(.text+0xb83): undefined reference to `boost::thread::start_thread_noexcept()'
/usr/bin/ld: http_server.cpp:(.text+0xc69): undefined reference to `boost::thread::native_handle()'
/usr/bin/ld: http_server.cpp:(.text+0xc82): undefined reference to `boost::thread::join_noexcept()'
/usr/bin/ld: /tmp/ccFIQ0RA.o: in function `boost::detail::thread_data<boost::_bi::bind_t<unsigned long, boost::_mfi::mf0<unsigned long, boost::asio::io_context>, boost::_bi::list1<boost::_bi::value<boost::asio::io_context*> > > >::~thread_data()':
Here's my Makefile
STANDARD = c++11
LIBPATH=/usr/lib/x86_64-linux-gnu
LINUX_THREAD=-lpthread
BOOST_THREAD=/usr/lib/x86_64-linux-gnu/libboost_thread.a
OUTPUT=cppserver
build_gcc:
g++ -O2 -std=$(STANDARD) $(LINUX_THREAD) -o $(OUTPUT) CppServer/servers/http_server/http_server.cpp ;\
CppServer/servers/http_server/connection.cpp CppServer/core/app.cpp CppServer/core/dbconn.cpp ;\
CppServer/servers/http_server/response.cpp CppServer/servers/http_server/request.cpp ;\
CppServer/math_unit.cpp CppServer/main.cpp $(BOOST_THREAD) -L$(LIBPATH)
I also tried to set BOOST_THREAD to 'boost_thread', but it failed as well.
Any ideas?
I am a beginner to organizing C++ projects and I have been trying to start an Open Dynamics Engine project for a week now but I keep getting several errors. First, what I have done:
Installed ode-0.13.1 with automake as directed in the manual.
Created a file test.cpp with the code from the bouncing ball HOWTO.
Wrote a makefile to compile.
But when I run my makefile, I get the following errors:
gcc -Wall -g -DdDOUBLE -o test test.o -L/home/username/ode-0.13.1/ode/src/libode.la -L/home/username/ode-0.13.1/drawstuff/src/libdrawstuff.la -L/usr/X11R6/lib -L/usr/lib -L/usr/local/lib -I. -I/home/username/ode-0.13.1/include/ -I/usr/X11R6/include -I/usr/include -lm -lode -lGL -lGLU
/usr/local/lib/libode.a(collision_trimesh_box.o): In function dCalcVectorLength3':
/home/username/ode-0.13.1/ode/src/../../include/ode/odemath.h:148: undefined reference tosqrt'
/home/username/ode-0.13.1/ode/src/../../include/ode/odemath.h:148: undefined reference to sqrt'
/home/username/ode-0.13.1/ode/src/../../include/ode/odemath.h:148: undefined reference tosqrt'
/usr/local/lib/libode.a(util.o): In function dxStepBody(dxBody*, double)':
/home/username/ode-0.13.1/ode/src/util.cpp:618: undefined reference tosincos'
/home/username/ode-0.13.1/ode/src/util.cpp:630: undefined reference to sincos'
/home/username/ode-0.13.1/ode/src/util.cpp:628: undefined reference tosqrt'
/home/username/ode-0.13.1/ode/src/util.cpp:590: undefined reference to `sqrt'
... (and this keeps going for pages)
/usr/local/lib/libode.a(OPC_AABBTree.o): In function Opcode::AABBTree::Build(Opcode::AABBTreeBuilder*)':
/home/username/ode-0.13.1/OPCODE/OPC_AABBTree.cpp:413: undefined reference tooperator new[](unsigned long)'
/home/username/ode-0.13.1/OPCODE/OPC_AABBTree.cpp:427: undefined reference to operator new[](unsigned long)'
/usr/local/lib/libode.a(OPC_AABBTree.o): In functionOpcode::AABBTreeNode::~AABBTreeNode()':
/home/username/ode-0.13.1/OPCODE/OPC_AABBTree.cpp:83: undefined reference to operator delete[](void*, unsigned long)'
/usr/local/lib/libode.a(OPC_Collider.o): In functionOpcode::Collider::~Collider()':
/home/username/ode-0.13.1/OPCODE/OPC_Collider.cpp:54: undefined reference to operator delete(void*, unsigned long)'
/usr/local/lib/libode.a(OPC_Collider.o):(.data.rel.ro._ZTIN6Opcode8ColliderE[_ZTIN6Opcode8ColliderE]+0x0): undefined reference tovtable for __cxxabiv1::__class_type_info'
/usr/local/lib/libode.a(OPC_Collider.o):(.data.rel.ro._ZTVN6Opcode8ColliderE[_ZTVN6Opcode8ColliderE]+0x20): undefined reference to `__cxa_pure_virtual'
collect2: error: ld returned 1 exit status
makefile:14: recipe for target 'test' failed
make: *** [test] Error 1
These errors seem like the library has not been set up correctly, but I'm pretty sure I've properly installed and my -L's are set to the correct paths.
Note 1: the demos included with the ode library work.
Note 2: I've tried (and failed) to install other versions of ode previously. I did my best with make uninstall and make clean to clean these failed installs, but I think they may be affecting new installs because when I run sudo make install for the first time there is an awful lot of Nothing to do here... messages.
a C++ code built into a shared library for HELib is using NTL and GMP static library. But it gets following error:
/usr/bin/ld: /usr/local/lib/libntl.a(FFT.o): relocation R_X86_64_32 against `.rodata.str1.8' can not be used when making a shared object; recompile with -fPIC
/usr/local/lib/libntl.a: error adding symbols: Bad value
collect2: error: ld returned 1 exit status
It was suggested int the post Click here
to recompile NTL and GMP with "-fPIC " flags.
I'am not able to find how I should do that.
Edit:
I'm able to build the shared library now after :
recompiling GMP and NTL by:
./configure --enable-shared
for gmp and
./configure SHARED=on
After make Install of HELib. I get error when I run the example codes.
The link to the Makefile : click to see makefile
Error:
g++ -g -O2 -std=c++11 -pthread -DFHE_THREADS -DFHE_BOOT_THREADS -DFHE_DCRT_THREADS -o Test_General_x Test_General.cpp -L/usr/local/lib -lntl -lgmp -lm -lfhe
/usr/local/lib/libfhe.so: undefined reference to write_raw_int(std::ostream&, long, long)'
/usr/local/lib/libfhe.so: undefined reference toread_raw_ZZ(std::istream&, NTL::ZZ&)'
/usr/local/lib/libfhe.so: undefined reference to void write_raw_vector<long>(std::ostream&, std::vector<long, std::allocator<long> > const&)'
/usr/local/lib/libfhe.so: undefined reference towriteEyeCatcher(std::ostream&, char const*)'
/usr/local/lib/libfhe.so: undefined reference to write_raw_xdouble(std::ostream&, NTL::xdouble)'
/usr/local/lib/libfhe.so: undefined reference toread_ntl_vec_long(std::istream&, NTL::Vec&)'
/usr/local/lib/libfhe.so: undefined reference to void read_raw_vector<long>(std::istream&, std::vector<long, std::allocator<long> >&)'
/usr/local/lib/libfhe.so: undefined reference toreadEyeCatcher(std::istream&, char const*)'
/usr/local/lib/libfhe.so: undefined reference to read_raw_int(std::istream&, long)'
/usr/local/lib/libfhe.so: undefined reference toread_raw_xdouble(std::istream&)'
/usr/local/lib/libfhe.so: undefined reference to write_raw_ZZ(std::ostream&, NTL::ZZ const&)'
/usr/local/lib/libfhe.so: undefined reference towrite_ntl_vec_long(std::ostream&, NTL::Vec const&, long)'
collect2: error: ld returned 1 exit status
Makefile:179: recipe for target 'Test_General_x' failed
make: *** [Test_General_x] Error 1
For NTL v11.5.1 atleast, doing ./configure --help | grep -i pic (as suggested in one of the comments for GMP) did not help at all - it found no matches. However, making a one line change in the file ntl-11.5.1/src/DoConfig (on line 17) from:
'CXXFLAGS' => '-g -O2'
to:
'CXXFLAGS' => '-g -O2 -fPIC',
solved the problem for me.
Marc Glisse provided the answer for the first two parts of the question.For the third part "Undefined Reference error" the answer is I'd not compiled and linked a x.cpp containing the functions that caused the undefined reference into my shared library. hence check : nm -CD /usr/local/lib/libfhe.so to see if these functions are listed with a linking address or not. If not then check which code provides this functionality. Link that code to the shared library.
I am trying to compile a program written in C++ using the lpsolve external library.
I have written the following line in my .cpp :
#include</var/lib/lpsolve/lp_lib.h>
However, when I'm trying to compile this using g++, I get this weird message :
/usr/bin/ld: skipping incompatible /usr/lib/gcc/x86_64-linux-gnu/5/../../../../lib/liblpsolve55.so when searching for -llpsolve55
/usr/bin/ld: skipping incompatible /usr/lib/../lib/liblpsolve55.so when searching for -llpsolve55
/usr/bin/ld: skipping incompatible /usr/lib/gcc/x86_64-linux-gnu/5/../../../liblpsolve55.so when searching for -llpsolve55
/usr/bin/ld: skipping incompatible //usr/local/lib/liblpsolve55.so when searching for -llpsolve55
/usr/bin/ld: skipping incompatible //usr/local/lib/liblpsolve55.a when searching for -llpsolve55
/usr/bin/ld: skipping incompatible //usr/lib/liblpsolve55.so when searching for -llpsolve55
/usr/bin/ld: cannot find -llpsolve55
/usr/bin/ld: cannot find -lcolamd
collect2: error: ld returned 1 exit status
I tried many different things... Even tried to install the library manually, by downloading it from sourceforge taking care of the right version (dev-ux64 in my case) and it seems like none of the solutions I've found on the internet are working ...
By the way, I am using the following command to compile my program :
g++ prog.cpp -llpsolve55 -lcolamd -ldl -o MyExe
EDIT : after specifying the path to the librairies explicitly, i get this :
/tmp/ccIvoPiS.o: In function `main':
flot_max.cpp:(.text+0x36): undefined reference to `make_lp'
flot_max.cpp:(.text+0xd7): undefined reference to `set_int'
flot_max.cpp:(.text+0x159): undefined reference to `set_maxim'
flot_max.cpp:(.text+0x16c): undefined reference to `set_obj_fn'
flot_max.cpp:(.text+0x1d6): undefined reference to `add_constraint'
flot_max.cpp:(.text+0x240): undefined reference to `add_constraint'
flot_max.cpp:(.text+0x2aa): undefined reference to `add_constraint'
flot_max.cpp:(.text+0x314): undefined reference to `add_constraint'
flot_max.cpp:(.text+0x37e): undefined reference to `add_constraint'
/tmp/ccIvoPiS.o:flot_max.cpp:(.text+0x3e8): more undefined references to `add_constraint' follow
/tmp/ccIvoPiS.o: In function `main':
flot_max.cpp:(.text+0x6a4): undefined reference to `solve'
flot_max.cpp:(.text+0x6bd): undefined reference to `get_objective'
flot_max.cpp:(.text+0x704): undefined reference to `get_variables'
collect2: error: ld returned 1 exit status
It just looks like the library isn't loaded as every function listed above are part of the library...