Ask Your Question
1

Sudden linker error with GCC 5.2.0

asked 2015-09-09 16:07:16 -0600

Plankalkuel gravatar image

I am using OpenCV 2.4 in a project and up to GCC 5.1.0 I had no problems with compiling.

Suddenly, after installing GCC 5.2.0 (from source) I get a linker error for some of the OpenCV functions. The majority seems to work. Only the cs::im* functions seem to cause problems.

CMakeFiles/2DSIL.dir/main.cpp.o: In function `main':
/home/c7031105/Dropbox/2DSIL/main.cpp:35: undefined reference to `cv::imread(std::__cxx11::basic_string<char, std::char_traits<char>, std::allocator<char> > const&, int)'
/home/c7031105/Dropbox/2DSIL/main.cpp:110: undefined reference to `cv::imwrite(std::__cxx11::basic_string<char, std::char_traits<char>, std::allocator<char> > const&, cv::_InputArray const&, std::vector<int, std::allocator<int> > const&)'
CMakeFiles/2DSIL.dir/V4.cpp.o: In function `V4::getWeights(std::vector<int, std::allocator<int> >, double&)':
/home/c7031105/Dropbox/2DSIL/V4.cpp:313: undefined reference to `cv::imread(std::__cxx11::basic_string<char, std::char_traits<char>, std::allocator<char> > const&, int)'
CMakeFiles/2DSIL.dir/V4.cpp.o: In function `V4::compare(std::vector<int, std::allocator<int> >, std::__cxx11::basic_string<char, std::char_traits<char>, std::allocator<char> >)':
/home/c7031105/Dropbox/2DSIL/V4.cpp:110: undefined reference to `cv::imread(std::__cxx11::basic_string<char, std::char_traits<char>, std::allocator<char> > const&, int)'
CMakeFiles/2DSIL.dir/V4.cpp.o: In function `V4::getWeights(cv::Mat, cv::Mat, double&)':
/home/c7031105/Dropbox/2DSIL/V4.cpp:352: undefined reference to `cv::imread(std::__cxx11::basic_string<char, std::char_traits<char>, std::allocator<char> > const&, int)'
/home/c7031105/Dropbox/2DSIL/V4.cpp:379: undefined reference to `cv::imread(std::__cxx11::basic_string<char, std::char_traits<char>, std::allocator<char> > const&, int)'
CMakeFiles/2DSIL.dir/V4.cpp.o: In function `V4::compare(cv::Mat, cv::Mat, std::__cxx11::basic_string<char, std::char_traits<char>, std::allocator<char> >)':
/home/c7031105/Dropbox/2DSIL/V4.cpp:179: undefined reference to `cv::imread(std::__cxx11::basic_string<char, std::char_traits<char>, std::allocator<char> > const&, int)'
CMakeFiles/2DSIL.dir/V4.cpp.o: In function `void cv::Mat::push_back<int>(int const&)':
/usr/local/include/opencv2/core/mat.hpp:689: undefined reference to `cv::Exception::Exception(int, std::__cxx11::basic_string<char, std::char_traits<char>, std::allocator<char> > const&, std::__cxx11::basic_string<char, std::char_traits<char>, std::allocator<char> > const&, std::__cxx11::basic_string<char, std::char_traits<char>, std::allocator<char> > const&, int)'
CMakeFiles/2DSIL.dir/img_read_write.cpp.o: In function `dsil::visualize(cv::Mat const&, int)':
/home/c7031105/Dropbox/2DSIL/img_read_write.cpp:91: undefined reference to `cv::namedWindow(std::__cxx11::basic_string<char, std::char_traits<char>, std::allocator<char> > const&, int)'
/home/c7031105/Dropbox/2DSIL/img_read_write.cpp:92: undefined reference to `cv::imshow(std::__cxx11::basic_string<char, std::char_traits<char>, std::allocator<char> > const&, cv::_InputArray const&)'
CMakeFiles/2DSIL.dir/img_read_write.cpp.o: In function `dsil::imgwrite(std::__cxx11::basic_string<char, std::char_traits<char>, std::allocator<char> > const&, std::__cxx11::basic_string<char, std::char_traits<char>, std::allocator<char> > const&, cv::Mat const&)':
/home/c7031105/Dropbox/2DSIL/img_read_write.cpp:49: undefined reference to `cv::imwrite(std ...
(more)
edit retag flag offensive close merge delete

Comments

What platform you run on?

peter_cz gravatar imagepeter_cz ( 2015-09-10 00:57:28 -0600 )edit
1

did you rebuild opencv libs with your new compiler ?

berak gravatar imageberak ( 2015-09-10 03:11:32 -0600 )edit

1 answer

Sort by ยป oldest newest most voted
3

answered 2015-09-10 04:27:20 -0600

Plankalkuel gravatar image

updated 2015-09-10 06:06:11 -0600

I now solved the problem by building OpenCV 3.0 from source. I never had to rebuild a library because of switching to a newer version of gcc.

After reading a bit I assume the reason is that with GCC 5.2.0 a new ABI is activated by default.

From the GCC release notes:

If you get linker errors about undefined references to symbols that involve types in the std::__cxx11 namespace or the tag [abi:cxx11] then it probably indicates that you are trying to link together object files that were compiled with different values for the _GLIBCXX_USE_CXX11_ABI macro. This commonly happens when linking to a third-party library that was compiled with an older version of GCC. If the third-party library cannot be rebuilt with the new ABI then you will need to recompile your code with the old ABI.

Switching to the old ABI works like this:

The old ABI is still supported and can be used by defining the macro _GLIBCXX_USE_CXX11_ABI to 0 before including any C++ standard library headers.

So maybe that will be of help to someone else.

edit flag offensive delete link more

Comments

Hmm then you were just lucky all this time. If you change the compiler then you should always consider rebuilding your code to be sure.

StevenPuttemans gravatar imageStevenPuttemans ( 2015-09-11 06:41:50 -0600 )edit

My code: Yes. But I don't generally rebuild all libraries that I use when I switch to a new compiler version. And since this "error" is explicitly mentioned in the release notes I would expect that in general that is also not necessary.

Plankalkuel gravatar imagePlankalkuel ( 2015-09-13 08:32:41 -0600 )edit

Like you said, it probably isn't really necessary, but it cannot harm to do it. I have seen wrong compilers do very strange things to software projects.

StevenPuttemans gravatar imageStevenPuttemans ( 2015-09-14 05:44:25 -0600 )edit

Question Tools

1 follower

Stats

Asked: 2015-09-09 16:06:47 -0600

Seen: 3,217 times

Last updated: Sep 10 '15