Ask Your Question
1

after turning BUILD_SHARED_LIBS to OFF , there are too many undefined references

asked 2018-09-05 02:52:20 -0600

nobot gravatar image

previously during dynamic linking of opencv , I was using

'pkg-config --cflags --libs opencv'

for linking, but after I rebuild my opencv with flag BUILD_SHARED_LIBS to OFF, pkg-config --cflags --libs opencv is giving too much undefined reference error. I dont know how to link statically opencv, what parameters should be passed, If someone knows please tell me.

main.cpp

#include "opencv2/highgui/highgui.hpp"
#include "opencv2/opencv.hpp"
#include "opencv2/imgproc/imgproc.hpp"
#include <iostream>
using namespace std;

int main()
{

 cout<< "enter the limit";
    int limit;
    cin>>limit;

    cv::Mat m= cv::imread("/home/odroid/Pictures/spider_man_1280x720.jpg"); //input image
    cv::imshow("input grey scale", m);

    cv::Ptr<cv::CLAHE> clahe = cv::createCLAHE();
    clahe->setClipLimit(limit);

    cv::Mat dst;
    clahe->apply(m, dst);
    cv::imshow("CLAHE output ",dst);

    cv::waitKey();

}

g++ main.cpp -o op0 pkg-config --cflags --libs opencv

edit retag flag offensive close merge delete

1 answer

Sort by ยป oldest newest most voted
0

answered 2018-09-05 03:14:19 -0600

berak gravatar image

static linking is somewhat different. you now have to add all those dependancy libs manually, that were conveniently linked to the dynamic so's before. also -- order matters !

pkg-config can't handle this. you could try to generate a makefile with cmake:

cmake_minimum_required(VERSION 2.8)
project( DisplayImage )
find_package( OpenCV REQUIRED )
set( OpenCV_STATIC ON )        ##### <--- need to add this !!
include_directories( ${OpenCV_INCLUDE_DIRS} )
add_executable( DisplayImage DisplayImage.cpp )
target_link_libraries( DisplayImage ${OpenCV_LIBS} )

or try to specify everything explicitly (extremely painful !):

g++ main.cpp  -L /usr/local/share/OpenCV/3rdparty/lib -lopencv_imgcodecs -lopencv_highgui -lopencv_imgproc -lopencv_core  <what_ever_gui_libs_you_need>   -littnotify -ljpeg -llibpng -llibtiff -llibwebp -lrt -ldl -lz -lpthread -o myprog

the gist here is: if lib A depends on lib B, the order must be: -lA -lB (and all the system libs go to the end of the list)

edit flag offensive delete link more

Comments

Thank you Berak, somehow things got a bit simplified, if I try to specify everything explicitly, how will I come to know all the dependencies I have, that I have to Link @berak

nobot gravatar imagenobot ( 2018-09-05 06:19:01 -0600 )edit

yea, that's the painful part. you have to look at the err msg, try to find the resp. lib, and the correct place for it, one by one.

did the cmake idea work ? should be much easier to accomplish

berak gravatar imageberak ( 2018-09-05 06:28:50 -0600 )edit

nope unfortunately it didn,t.

odroid@odroid:~/Desktop/is2/@_opencl/static/s.0.1.0/s.0.1.0/main$ cmake . -- The C compiler identification is GNU 7.3.0 -- The CXX compiler identification is GNU 7.3.0 -- Check for working C compiler: /usr/bin/cc -- Check for working C compiler: /usr/bin/cc -- works -- Detecting C compiler ABI info -- Detecting C compiler ABI info - done -- Detecting C compile features -- Detecting C compile features - done -- Check for working CXX compiler: /usr/bin/c++ -- Check for working CXX compiler: /usr/bin/c++ -- works -- Detecting CXX compiler ABI info -- Detecting CXX compiler ABI info - done -- Detecting CXX compile features -- Detecting CXX compile features - done -- Found OpenCV: /usr/local (found version "3.4.2") -- Configuring done -- Generating done ...

nobot gravatar imagenobot ( 2018-09-05 06:43:06 -0600 )edit

-- Build files have been written to: /home/odroid/Desktop/is2/@_opencl/sta... odroid@odroid:~/Desktop/is2/@_opencl/static/s.0.1.0/s.0.1.0/main$ make Scanning dependencies of target main [ 50%] Building CXX object CMakeFiles/main.dir/main.cpp.o [100%] Linking CXX executable main /usr/bin/arm-linux-gnueabihf-ld: cannot find -lgflags_shared collect2: error: ld returned 1 exit status CMakeFiles/main.dir/build.make:181: recipe for target 'main' failed make[2]: * [main] Error 1 CMakeFiles/Makefile2:67: recipe for target 'CMakeFiles/main.dir/all' failed make[1]: [CMakeFiles/main.dir/all] Error 2 Makefile:83: recipe for target 'all' failed make: ** [all] Error 2

nobot gravatar imagenobot ( 2018-09-05 06:43:35 -0600 )edit

/usr/bin/arm-linux-gnueabihf-ld: cannot find -lgflags_shared any lead ??@berak

nobot gravatar imagenobot ( 2018-09-05 06:46:17 -0600 )edit

are you cross-compiling for arm ? (i have no idea about it)

berak gravatar imageberak ( 2018-09-05 07:04:04 -0600 )edit

yes, I intend to do so.

nobot gravatar imagenobot ( 2018-09-05 22:51:31 -0600 )edit

Question Tools

1 follower

Stats

Asked: 2018-09-05 02:52:20 -0600

Seen: 2,272 times

Last updated: Sep 05 '18