Ask Your Question

Linking ThinPlateSplineShapeTransformer failed (undefined reference)

asked 2016-08-17 09:15:22 -0600

Asalle gravatar image

Hi all,

I built OpenCV 3.1.0-dev (latest by today) and installed it to a subdir of my home dir. Now, I want to compile a simple example cpp-file, using my freshly installed OpenCV

#include <iostream>
#include <opencv2/shape/shape_transformer.hpp>
#include <opencv2/core/core.hpp>
#include <opencv2/imgproc/imgproc.hpp>
#include <opencv2/highgui/highgui.hpp>
#include <vector>

int main()
    auto tps = cv::createThinPlateSplineShapeTransformer();
    std::vector<cv::Point2f> sourceP, targetP;
    sourceP.push_back(cv::Point2f(0, 0));
    targetP.push_back(cv::Point2f(100, 0));
    sourceP.push_back(cv::Point2f(799, 0));
    targetP.push_back(cv::Point2f(799, 0));
    sourceP.push_back(cv::Point2f(0, 599));
    targetP.push_back(cv::Point2f(0, 599));
    sourceP.push_back(cv::Point2f(799, 599));
    targetP.push_back(cv::Point2f(799, 599));

    std::vector<cv::DMatch> matches;

    for (int i = 0; i < sourceP.size(); ++i)    
         matches.push_back(cv::DMatch(i, i, 0)); 

    return 0;

with the following Makefile

try: try.cpp
    g++ -ggdb -std=c++11 `pkg-config --cflags --libs ../install/lib/pkgconfig/opencv.pc` try.cpp -o try

install is the directory, where I installed the opencv, it contains include, lib, share and others

try.cpp is the code snippet

The error I'm getting is as follows: asalle@azazaz:~/opencv/try$ make

g++ -ggdb -std=c++11 `pkg-config --cflags --libs ../install/lib/pkgconfig/opencv.pc` try.cpp -o try
/tmp/ccncYN0U.o: In function `main':
/home/asalle/opencv/try/try.cpp:10: undefined reference to `cv::createThinPlateSplineShapeTransformer(double)'
collect2: error: ld returned 1 exit status
make: *** [try] Error 1

I already tried

g++ -std=c++11 -I../install/include -L../install/lib/ -lopencv_shape try.cpp -o try

but with no success.

Any help will be appreciated, Asalle

edit retag flag offensive close merge delete


what does

`pkg-config --cflags --libs ../install/lib/pkgconfig/opencv.pc`

resolve to ?

(also, g++ will never complain about libs that just don't exist)

berak gravatar imageberak ( 2016-08-17 23:54:34 -0600 )edit

I am sorry, I have not quite understood what do you mean by 'what does X resolve to?'. If you're asking about its meaning then is equivalent to the following

 -I/home/asalle/opencv/install/include/opencv -I/home/asalle/opencv/install/include -L/home/asalle/opencv/install/lib -lopencv_shape -lopencv_stitching -lopencv_objdetect -lopencv_superres -lopencv_videostab -lopencv_calib3d -lopencv_features2d -lopencv_highgui -lopencv_videoio -lopencv_imgcodecs -lopencv_video -lopencv_photo -lopencv_ml -lopencv_imgproc -lopencv_flann -lopencv_core

Fortunately, I figured it out and already answered my own question, but it has not shown yet. Is there some kind of answers moderation here?

Thanks anyway!

Asalle gravatar imageAsalle ( 2016-08-18 01:33:05 -0600 )edit

sorry for being unclear, but that's exactly, what was meant ! ;)

berak gravatar imageberak ( 2016-08-18 01:38:49 -0600 )edit

1 answer

Sort by ยป oldest newest most voted

answered 2016-08-18 04:20:08 -0600

Asalle gravatar image

updated 2016-08-18 04:25:10 -0600

It was a stupid mistake. It seems that the order of g++'s arguments matter:

g++ -std=c++11 -I../install/include -L../install/lib -lopencv_shape -o try try.cpp won't work, while

g++ -std=c++11 -I../install/include -L../install/lib -o try try.cpp -lopencv_shape will. So, all I did was postpone the -lopencv_shape to the end. Silly Billy.

Thank you for such a warm welcome and support, I hope to become a valuable member of this community!

edit flag offensive delete link more

Question Tools

1 follower


Asked: 2016-08-17 09:15:22 -0600

Seen: 678 times

Last updated: Aug 18 '16