Ask Your Question
0

OpenCV on Mac OS X 10.8 Mountain Lion

asked 2012-08-06 13:40:24 -0600

mjepson gravatar image

I have used OpenCV with Qt Creator on Windows, but now wanted to use it on Mac OS X too. So I installed 2.4.2, used CMake to make and build (install) the whole, which went without any problems. But, when I add #include <cv.hpp> to one of my files, I get the following error 5 times:

/usr/local/include/opencv2/flann/params.h:87: error: explicit instantiation of 'std::basic_ostream<_CharT, _Traits>& std::operator<<(std::basic_ostream<_CharT, _Traits>&, const std::basic_string<_CharT, _Traits, _Alloc>&) [with _CharT = char, _Traits = std::char_traits<char>, _Alloc = std::allocator<char>]' but no definition available

The code around the error is this:

inline void print_params(const IndexParams& params)
{
    IndexParams::const_iterator it;

    for(it=params.begin(); it!=params.end(); ++it) {
        std::cout << it->first << " : " << it->second << std::endl;
    }
}

with the error occurring in the line with std::cout << it->first ...

I can't figure out why this is happening. Any help is greatly appreciated!

edit retag flag offensive close merge delete

Comments

I don't know what IndexParams means, but try to take it->first in a separate line and return it's value and try to print it's fields firstly then if every thing is ok, So "cout << it->first" is illegal.

Adwa gravatar imageAdwa ( 2012-08-08 09:15:25 -0600 )edit

Well, this is code from OpenCV itself, which worked in Mac OS X 10.7. It works as it is on Windows too, so I don't think there's really anything wrong with it. Also, the error complains about the explicit instantiation of std::basic_ostream(etc.), which would be cout I guess. The file has an #include <iostream>, so it should be able to use std::cout.

mjepson gravatar imagemjepson ( 2012-08-08 12:30:43 -0600 )edit

5 answers

Sort by » oldest newest most voted
3

answered 2012-08-16 07:08:04 -0600

natoferreira gravatar image

Hi everyone!

I was having exactly the same issue reported by mjepson and tvdev. It seems there's a small configuration problem with Qt 4.7.4 (my QtCreator's about window says it's 4.7.4, but the version I installed was 4.8.1, though!) and gcc on the new Mac OS X 10.8 Mountain Lion. I've also installed OpenCV 2.4.2 using MacPorts.

So, all you have to do is:

(1) find the right conf file for g++ on mac in your QtSDK folder. I mean, remember there are multiple Qt versions for the multiple targets (desktop, simulator, harmattan are some) under your QtSDK folder. You should find change the file located under "Desktop" in QtSDK folder. So, in my case, here's the file path:

[YourQtSDKFolder]/Desktop/Qt/4.8.1/gcc/mkspecs/common/g++-macx.conf

(2) change the following lines in this file:

QMAKE_CFLAGS_X86_64 += -Xarch_x86_64 -mmacosx-version-min=10.5
QMAKE_CFLAGS_PPC_64 += -Xarch_ppc64 -mmacosx-version-min=10.5

to

QMAKE_CFLAGS_X86_64 += -Xarch_x86_64 -mmacosx-version-min=10.7
QMAKE_CFLAGS_PPC_64 += -Xarch_ppc64 -mmacosx-version-min=10.7

And voilà! This works flawlessly for me.

edit flag offensive delete link more

Comments

And make sure you are using the right compiler if you are a MAC user, the xCode will using APPLE LLVM, you have to change it to LLVM GCC. Otherwise it will report a lot of errors like this.

hihell gravatar imagehihell ( 2013-03-05 13:10:49 -0600 )edit

why do this post has such a low votes? It is super important, and it works for me after days of troubles on mac compilers

nkint gravatar imagenkint ( 2013-06-11 06:34:33 -0600 )edit
0

answered 2012-08-08 05:25:27 -0600

Adwa gravatar image

Firstly If you are using C++ APIs make sure your files are .mm and not .m and .hpp not .h when writing C++.

Also, the tricky part which I don't know why this works. I read that you need include opencv header BEFORE everything else so, look for your prefix.pch file and add #import "opencv/cv.h" before any #import

Now you can work with OpenCV as usual and #import "opencv2/opencv.hpp" in your .mm files if necessary.

Let me know if that helps!

edit flag offensive delete link more

Comments

Are you sure you're talking about C++? I only have .hpp and .cpp files, also, I have #include lines, not #import ...

mjepson gravatar imagemjepson ( 2012-08-08 12:18:13 -0600 )edit

Yes, read the illustration under the ""Include the OpenCV headers"" title from : http://aptogo.co.uk/2011/09/opencv-framework-for-ios/ BTW : #include & #import both works as the file now called an objectiveC++ file.

Adwa gravatar imageAdwa ( 2012-08-09 06:28:49 -0600 )edit

Aha, but this is with XCode. I am using Qt Creator and using code I wrote on a Windows Machine. Also, it seems to only produce errors with the gcc compiler. If I choose the Clang compiler, it compiles as it should, but I want to use the gcc compiler. I think the .m files are also XCode only. Weird thing though, that they all include opencv.hpp first, while I have always just includded <cv.hpp>. I will try adding that include when I get home this afternoon (I don't have a Mac at work).

mjepson gravatar imagemjepson ( 2012-08-09 09:20:02 -0600 )edit
0

answered 2012-08-08 08:32:42 -0600

tvdev gravatar image

Hi there!!

I'm having the very same problem reported by mjepson:

error: explicit instantiation of 'std::basic_ostream<_CharT, _Traits>& std::operator<<(std::basic_ostream<_CharT, _Traits>&, const std::basic_string<_CharT, _Traits, _Alloc>&) [with _CharT = char, _Traits = std::char_traits<char>, _Alloc = std::allocator<char>]' but no definition available

caused by a "cout" call.

the very same project was working smoothly before updating to mountain lion.

ENVIRONMENT: IDE: QtCreator 2.4.1 based on qt 4.7.4 (64 bit) Platform macbook pro 2.2ghz early 2011 with mountain lion (osx 10.8). Xcode version 4.4.1

I installed the command line tools using Xcode. Uninstalled and re-installed the Qt so it automatically found the compilers toolchains but nothing worked.

Curiously, if I add

cout << myString.c_str();

The problem is solved both for compilation and running.

I'd rather find out what's the problem, though.

Regards.

edit flag offensive delete link more

Comments

Hi tvdev, please let me know if you find a solution. Where did you add "cout<< myString.c_str();" to make it compile and run?

mjepson gravatar imagemjepson ( 2012-08-09 14:04:35 -0600 )edit

Hi mjepson, thanks a lot. The solution posted by natoferreira works for me. Answering your question, I indeed was able to compile and run the code using string.c_str(). Regards.

tvdev gravatar imagetvdev ( 2012-08-19 09:11:45 -0600 )edit

Still the question remains ... where do you add .c_str() ? If I change params.h and make it read: std::cout << it->first.c_str() << .... I get an error saying that cvflann::any has not member named c_str. If I completely remove the lines (comment them out), I get the same error in another Qt file, and another, etc. So there really is something I have to fix, but cannot find it.

Never mind. Somehow the mac-min-version trick did it this time ... Must have done something wrong last time. /facepalm Thanks for your message though!

mjepson gravatar imagemjepson ( 2012-08-23 15:21:48 -0600 )edit
0

answered 2012-09-23 07:16:56 -0600

stellamarie gravatar image

finally! after days of searching, it was a really simple answer. i was compiling this in matlab. i changed all my compilation options to clang and clang++ v/s gcc and g++

i had to change this in multiple places, and recompile opencv to use the alternate compiles as well...

edit flag offensive delete link more

Comments

can you show us where you fixed your compilation option? (I assume you change it in mexopts.sh?) I'm having the same problem, but changing to clang leads to another problem "Undefined symbols for architecture x86_64:"

12dmodel gravatar image12dmodel ( 2012-10-18 12:31:29 -0600 )edit
0

answered 2012-09-19 14:47:26 -0600

stellamarie gravatar image

any other suggestions for this? I've tried all the suggestions, but i still can't get the program to compile. i'm on mountain lion, updated xcode, installed qt creator, installed latest opencv without too many problems. (64 bit) Platform macbook pro 2.2ghz early 2011 with mountain lion (osx 10.8)

/usr/local/include/opencv2/flann/params.h: In instantiation of 'std::basic_ostream<_CharT, _Traits>& std::operator<<(std::basic_ostream<_CharT, _Traits>&, const std::basic_string<_CharT, _Traits, _Alloc>&) [with _CharT = char, _Traits = std::char_traits<char>, _Alloc = std::allocator<char>]': /usr/local/include/opencv2/flann/params.h:88: instantiated from here /usr/local/include/opencv2/flann/params.h:88: error: explicit instantiation of 'std::basic_ostream<_CharT, _Traits>& std::operator<<(std::basic_ostream<_CharT, _Traits>&, const std::basic_string<_CharT, _Traits, _Alloc>&) [with _CharT = char, _Traits = std::char_traits<char>, _Alloc = std::allocator<char>]' but no definition available /usr/local/include/opencv2/flann/params.h: In instantiation of 'std::basic_ostream<_CharT, _Traits>& std::operator<<(std::basic_ostream<_CharT, _Traits>&, const std::basic_string<_CharT, _Traits, _Alloc>&) [with _CharT = char, _Traits = std::char_traits<char>, _Alloc = std::allocator<char>]': /usr/local/include/opencv2/flann/params.h:88: instantiated from here

edit flag offensive delete link more

Question Tools

1 follower

Stats

Asked: 2012-08-06 13:40:24 -0600

Seen: 5,271 times

Last updated: Sep 23 '12