Undefined reference to cv::imread linking error - c++

I'm trying to install a modified version of caffe as part of the installation of this library: https://github.com/wasidennis/ObjectFlow/tree/master/caffe-cedn-dev
I'm on ubuntu 14.04 and am using a cmake install as listed on the caffe website.
I've installed matlab & have the mex file in the path.
after cmake .. I do a make all and get this error:
Linking CXX executable caffe
../lib/libcaffe.a(io.cpp.o): In function `caffe::ReadImageToDatum(std::string const&, int, int, int, bool, caffe::Datum*)':
io.cpp:(.text+0x67d): undefined reference to `cv::imread(cv::String const&, int)'
../lib/libcaffe.a(window_data_layer.cpp.o): In function `caffe::WindowDataLayer<float>::InternalThreadEntry()':
window_data_layer.cpp:(.text._ZN5caffe15WindowDataLayerIfE19InternalThreadEntryEv[_ZN5caffe15WindowDataLayerIfE19InternalThreadEntryEv]+0x44b): undefined reference to `cv::imread(cv::String const&, int)'
../lib/libcaffe.a(window_data_layer.cpp.o): In function `caffe::WindowDataLayer<double>::InternalThreadEntry()':
window_data_layer.cpp:(.text._ZN5caffe15WindowDataLayerIdE19InternalThreadEntryEv[_ZN5caffe15WindowDataLayerIdE19InternalThreadEntryEv]+0x446): undefined reference to `cv::imread(cv::String const&, int)'
collect2: error: ld returned 1 exit status
make[2]: *** [tools/caffe] Error 1
make[1]: *** [tools/CMakeFiles/caffe.bin.dir/all] Error 2
make: *** [all] Error 2
Following https://github.com/BVLC/caffe/issues/1276 I looked at the output of pkg-config --cvflags opencv which is -I/usr/local/include/opencv -I/usr/local/include
This is the same location as the headers of my OpenCV installation are installed. (I'm not sure of the causal relationship on that.) Both OpenCV 3.1 and 2.4 go to those files - I tried installing both and to switch between them I just move the opencv and opencv2 header folders to a tmp folder while I use the other opencv. I think this might be the source of the error, as I don't know how to tell which version of OpenCV my program is using for sure.
More specifically I have done is:
I added opencv_imgcodecs to the Makefile
installed opencv via apt-get
uninstalled opencv via apt-get remove
installed a version of opencv that I don't remember the version
installed 3.1 & 2.4 from src & switched out the header folders as stated above.
Deleted a version of opencv src & header folders that I didn't know how to see what version it was.
From when I started checking, python import cv2 went from version 3.1 to now 3.2-dev.

Related

C++ Tensorflow lite, undefined reference on some functions

I'm trying to build and run a project using tensorflow lite on my debian 11 intel x86_64 architecture. So far I've followed the official documentation and the official github example.
Here are the steps I've followed:
On ~/Desktop/ I ran git clone https://github.com/tensorflow/tensorflow.git tensorflow_src
mkdir tflite_build & cd ~/Desktop/tflite_build
cmake ../tensorflow_src/tensorflow/lite
cmake --build . I've removed the -J flag regardless of what the docs says because it causes my pc to freeze.
mkdir ~/Desktop/tf_test & cd ~/Desktop/tf_test
Create a CMakeLists.txt and a main.cpp file inside tf_testdirectory.
Put the main code from the minimal example on the github repo provided above then this code in CMake:
cmake_minimum_required(VERSION 3.16)
project(minimal C CXX)
set(CMAKE_CXX_FLAGS "${CMAKE_CXX_FLAGS} -DTFLITE_DISABLE_TELEMETRY=1")
set(TENSORFLOW_SOURCE_DIR "" CACHE PATH
"Directory that contains the TensorFlow project" )
if(NOT TENSORFLOW_SOURCE_DIR)
get_filename_component(TENSORFLOW_SOURCE_DIR
"/home/user/Desktop/tensorflow_src" ABSOLUTE)
endif()
add_subdirectory(
"${TENSORFLOW_SOURCE_DIR}/tensorflow/lite"
"${CMAKE_CURRENT_BINARY_DIR}/tensorflow-lite" EXCLUDE_FROM_ALL)
add_executable(minimal minimal.cc)
target_link_libraries(minimal tensorflow-lite)
Created the folder tf_Test/build and ran cmake .. inside it.
After cmake is completed I run make inside the build directory and I'm getting the following error:
...
[100%] Linking CXX executable minimal
/usr/bin/ld: tensorflow-lite/libtensorflow-lite.a(interpreter.cc.o): in function `tflite::impl::Interpreter::ReportTelemetrySettings(char const*)':
interpreter.cc:(.text+0x292f): undefined reference to `tflite::telemetry::TelemetryReportSettings(TfLiteContext*, char const*, TfLiteTelemetryInterpreterSettings const*)'
/usr/bin/ld: tensorflow-lite/libtensorflow-lite.a(subgraph.cc.o): in function `tflite::Subgraph::Invoke()':
subgraph.cc:(.text+0x41c0): undefined reference to `tflite::telemetry::TelemetryReportEvent(TfLiteContext*, char const*, TfLiteStatus)'
/usr/bin/ld: tensorflow-lite/libtensorflow-lite.a(subgraph.cc.o): in function `tflite::Subgraph::ModifyGraphWithDelegate(TfLiteDelegate*)':
subgraph.cc:(.text+0x6ad0): undefined reference to `tflite::telemetry::TelemetryReportEvent(TfLiteContext*, char const*, TfLiteStatus)'
collect2: error: ld returned 1 exit status
make[2]: *** [CMakeFiles/minimal.dir/build.make:184: minimal] Error 1
make[1]: *** [CMakeFiles/Makefile2:1408: CMakeFiles/minimal.dir/all] Error 2
make: *** [Makefile:149: all] Error 2
Notice that it's not saying this for all the functions. For example this works std::unique_ptr<tflite::FlatBufferModel> model = tflite::FlatBufferModel::BuildFromFile(filename); without errors.
These tree are causing trouble: tflite::ops::builtin::BuiltinOpResolver resolver; std::unique_ptr<tflite::Interpreter> interpreter; tflite::InterpreterBuilder(*model, resolver)(&interpreter);
Note: I've trimmed some code compare to the github example for the sake of testing it, so only the above 4 lines are present on my main.
Why am I getting this error? I've tried compiling with bazel aswell but I'm getting the same error. What am I missing?
Probably it is missing from the CMakeLists file
Update CMakeLists.txt and add
tensorflow/lite/profiling/telemetry/telemetry.cc and
tensorflow/lite/profiling/telemetry/telemetry.h
to TFLITE_PROFILER_SRCS
It is also worth creating issue on Tensorflow repo for the team

Linking problems with dlib: recompile with -fPIC

I would like to use this ROS package which relies on dlib. I compile with catkin build, but I get this error in linking I guess:
/usr/bin/ld: /usr/lib/libdlib.a(threads_kernel_shared.o): relocation R_X86_64_PC32 against symbol `_ZN4dlib21threads_kernel_shared14thread_starterEPv' can not be used when making a shared object; recompile with -fPIC
/usr/bin/ld: final link failed: Bad value
collect2: error: ld returned 1 exit status
make[2]: *** [/home/alberto/tiago_dual_public_ws/devel/.private/gazr/lib/libgazr.so] Error 1
make[1]: *** [CMakeFiles/gazr.dir/all] Error 2
make: *** [all] Error 2
I have installed dlib using sudo apt-get install libdlib-dev on my Ubuntu 18.05 (ROS Melodic) machine. How can I solve this problem? Documentation of dlib and the repo instruction does not help me a lot.
Thanks in advance.
I found 2 possible solution to the problem.
Installing dlib with sudo apt-get install libdlib-dev
In this case you should link dlib to your library target like target_link_libraries(gazr dlib ${OpenCV_LIBRARIES})
Rememberto use find_package(dlib REQUIRED)
Installing dlib from source
It's also possible to use directly the dlib source file. In this case you need to add the dlib source directory to the project using add_subdirectory(your_path/dlib dlib) and add it to the library target_link_libraries(gazr dlib ${OpenCV_LIBRARIES}).
ATTENTION: In this case you shall not use find_package(dlib REQUIRED)
Hope this is helpful!

Undefined reference using external library with CMake and Conan

I am trying to develop a program that communicates with a PCSC USB reader using Conan and CMake with the LibLogicalAccess library. I followed the instructions of building and installing the library which seemed to have gone fine. I created a small simple console project with a "main.cpp" file. Following the C++ guide on the wiki of the library I tried to call a function from the library which resulted in a "Undefined reference to function. I know there are a lot of topics covering this but I have read as many as I could but could not seem to find the right solution.
I don't have much experience with Ubuntu/CMake/Conan/C++ so it might as well be a very simple fix.
OS: Kubuntu 18.04
Lang: C++
Related software: LibLogicalAccess
2.2.1,
CMake 3.17.1,
Conan 1.25.0
main.cpp
#include <iostream>
#include <logicalaccess/dynlibrary/librarymanager.hpp>
#include <logicalaccess/readerproviders/readerconfiguration.hpp>
#include <logicalaccess/cards/chip.hpp>
int main()
{
std::cout << "Program started\n";
// Reader configuration object to store reader provider and reader unit selection.
std::shared_ptr<logicalaccess::ReaderConfiguration> readerConfig(new logicalaccess::ReaderConfiguration());
// Set PCSC ReaderProvider by calling the Library Manager which will load the function from the corresponding plug-in
readerConfig->setReaderProvider(logicalaccess::LibraryManager::getInstance()->getReaderProvider("PCSC"));
std::cout << "after..\n";
}
CMakeLists.txt
cmake_minimum_required(VERSION 3.16)
project(project)
include(${CMAKE_BINARY_DIR}/conanbuildinfo.cmake)
conan_basic_setup(TARGETS)
set(CMAKE_CXX_FLAGS "-I /usr/include/PCSC")
add_executable(project main.cpp)
target_link_libraries(project PUBLIC CONAN_PKG::LogicalAccess)
When I try to build the program using cmake --build . this is the output:
[100%] Linking CXX executable bin/project
CMakeFiles/project.dir/main.cpp.o: In function `main':
main.cpp:(.text+0x140): undefined reference to `logicalaccess::LibraryManager::getReaderProvider(std::__cxx11::basic_string<char, std::char_traits<char>, std::allocator<char> > const&)'
collect2: error: ld returned 1 exit status
CMakeFiles/project.dir/build.make:191: recipe for target 'bin/project' failed
make[2]: *** [bin/project] Error 1
CMakeFiles/Makefile2:95: recipe for target 'CMakeFiles/project.dir/all' failed
make[1]: *** [CMakeFiles/project.dir/all] Error 2
Makefile:103: recipe for target 'all' failed
make: *** [all] Error 2
The weird part is that the first line of code: std::shared_ptr<logicalaccess::ReaderConfiguration> readerConfig(...) works fine and the second line of code gives an undefined reference.
I have tried other functions in the same file which give the same result. The file compiles and runs fine when I remove the last "setReaderProvider" line of code. Also tried a lot of different little adjustments regarding the conanfile.txt and CMakeLists.txt.
Your error says:
main.cpp:(.text+0x140): undefined reference to `logicalaccess::LibraryManager::getReaderProvider(std::__cxx11::basic_string, std::allocator > const&)'
It occurs because your CMake is using libstdc++11 to link, however, Conan is configured to use libstdc++ due backward compatibility.
You need to update your default libcxx:
conan profile update settings.compiler.libcxx=libstdc++11 default
Please, read this section in Conan docs How to Manage GCC ABI to get more information.
Also, it's explained on step 5 of Getting Started.
Now when building again, you will need that your local packages won't be available, because it's a new package, using different settings, so you will need to install, or build from sources. The link to libstdc++11 is automatically managed by Conan, it passes the definitions to CMake.
Regards!

llvm Linking CXX shared library ../../lib/libLTO.so undefiened refernece to target

i tried to install tiramisu compiler
and once trying install it's sub-modules ( (ISL, LLVM and Halide) by using this command
dina#dina-VBox:~/tiramisu$ ./utils/scripts/install_submodules.sh ./
i get the error
Done installing isl
#### Installing LLVM ####
cd .//3rdParty/llvm
.//utils/scripts/functions.sh: line 6: cd: .//3rdParty/llvm: No such file or directory
and to fix it i used the command shared on the answer here
./utils/scripts/install_submodules.sh $PWD
it worked better then the first one i reached 95% of the installation however it stop here with this error
Linking CXX shared library ../../lib/libLTO.so undefiened refernece to target
Here is the detail of the error
[ 95%] Linking CXX executable ../../bin/opt
[ 95%] Linking CXX shared library ../../lib/libLTO.so
../../lib/libLLVMX86AsmParser.a(X86AsmParser.cpp.o): In function `llvm::RegisterMCAsmParser<(anonymous namespace)::X86AsmParser>::Allocator(llvm::MCSubtargetInfo const&, llvm::MCAsmParser&, llvm::MCInstrInfo const&, llvm::MCTargetOptions const&)':
X86AsmParser.cpp:(.text._ZN4llvm19RegisterMCAsmParserIN12_GLOBAL__N_112X86AsmParserEE9AllocatorERKNS_15MCSubtargetInfoERNS_11MCAsmParserERKNS_11MCInstrInfoERKNS_15MCTargetOptionsE+0x164): undefined reference to `llvm::CreateX86AsmInstrumentation(llvm::MCTargetOptions const&, llvm::MCContext const&, llvm::MCSubtargetInfo const*&)'
CMakeFiles/llvm-mc.dir/llvm-mc.cpp.o: In function `main':
llvm-mc.cpp:(.text.startup.main+0xe4): undefined reference to `LLVMInitializeX86Disassembler'
../../lib/libLLVMX86Desc.a(X86MCTargetDesc.cpp.o): In function `LLVMInitializeX86TargetMC':
X86MCTargetDesc.cpp:(.text.LLVMInitializeX86TargetMC+0xc7): undefined reference to `llvm::createX86_32AsmBackend(llvm::Target const&, llvm::MCRegisterInfo const&, llvm::Triple const&, llvm::StringRef, llvm::MCTargetOptions const&)'
...
...
../../lib/libLLVMAArch64CodeGen.a(AArch64TargetObjectFile.cpp.o):(.data.rel.ro._ZTVN4llvm29AArch64_MachoTargetObjectFileE[_ZTVN4llvm29AArch64_MachoTargetObjectFileE]+0xa0): undefined reference to `llvm::TargetLoweringObjectFileMachO::SelectSectionForGlobal(llvm::GlobalObject const*, llvm::SectionKind, llvm::TargetMachine const&) const'
collect2: error: ld returned 1 exit status
tools/opt/CMakeFiles/opt.dir/build.make:349: recipe for target 'bin/opt' failed
make[2]: *** [bin/opt] Error 1
CMakeFiles/Makefile2:44345: recipe for target 'tools/opt/CMakeFiles/opt.dir/all' failed
make[1]: *** [tools/opt/CMakeFiles/opt.dir/all] Error 2
Makefile:151: recipe for target 'all' failed
make: *** [all] Error 2
dina#dina-VBox:~/tiramisu$ ^C
I do not know what should i do to fix this new error can someone help please.
I have not been able to fix the problem on it's self but i have changed the way of installing tiramisu.
I did pay attention to that and i do want to pay your attention to too that may serve your time and success your installation.
Never ever install tiramisu on virtual box cause tiramisu require a bit high performance machine i mean at least 6G of RAM once compiling it consume >= 6GRAM.
Means it's better to have partition or Linux system directly.
You may find issues from version to version means some succeed to install it in 18.04 where some in 16 where some in 14. So if you fail in version never give up try another version better then still paralyzed.
It better to not lunch anything in parallel once installing tiramisu.
You need to have a good network to clone tiramisu sub-modules and tiramisu on itself with a network of 35kb/s it may took 24h to get clone all stuff.
Respect the all the tips listed to install tiramisu to avoid have trouble ex if it's said you should CMake 5.0 version do it because they have tested in this version and they insure that work nothing grantee that in 6 version it will work so be careful.
If you scattered things in the way that you could not fix issues. It's better to clean up everything and restart from "0".
Be patient : Installing tiramisu is a bit heavy task so be Broad-minded and Zen.
it took me one month to be able to install tiramisu i had many issues. But once i install it in a partition and doing the steps show above carefully i have been finally to install successfully.
Best of luck :).

opencv installation error ubuntu

I'm trying to install opencv to my Ubuntu 14.04 machine using the documentation provided in
http://docs.opencv.org/doc/tutorials/introduction/linux_install/linux_install.html#linux-installation
However, during the compilation process I get the following error.
Linking CXX shared library ../../lib/libopencv_videoio.so
/usr/bin/ld: /usr/local/lib/libavcodec.a(avpacket.o): relocation R_X86_64_32 against `.rodata.str1.1' can not be used when making a shared object; recompile with -fPIC
/usr/local/lib/libavcodec.a: error adding symbols: Bad value
collect2: error: ld returned 1 exit status
make[2]: *** [lib/libopencv_videoio.so.3.0.0] Error 1
make[1]: *** [modules/videoio/CMakeFiles/opencv_videoio.dir/all] Error 2
make: *** [all] Error 2
I noticed a few posts mentioning similar errors and some solutions suggest removing the libavcodec.a from /usr/local/lib/. I'd like not to do that as I need ffmpeg libraries in the machine as well.
Could someone please help me to resolve this issue?.
Thanks
I got it to work (for installing ffmpeg) by simply reinstalling the whole thing from the beginning with all instances of $ ./configure replaced by $ ./configure --enable-shared (first make sure to delete all the folders and files including the .so files from the previous attempt).
Apparently this works because https://stackoverflow.com/a/13812368/10593190.
And this matches with #camino's comment on https://stackoverflow.com/a/19365454/10593190 and XavierStuvw's answer.
Just run these 2 lines in your terminal/environment:
pip install opencv-python==3.4.5.20
pip install opencv-contrib-python==3.4.5.20