Ambiguous C++ symbols


Carl Hoefs
 

Objc++, macOS 10.14, OpenCV2

I'm trying to issue Objc methods from within a .mm file, without success.

For instance:

[[NSNotificationCenter defaultCenter] postNotificationName:@"GUIStatusUpdate"
object: nil
userInfo: @{@"Status String" : @"Calculating Contour Features..."}];

Xcode gives an error: Use of undeclared identifier 'NSNotificationCenter'

If I add:

#ifdef __cplusplus
#import <UIKit/UIKit.h>
#endif

then Xcode complains about 3 OpenCV C++ types that conflict with similarly named types in /usr/include/MacTypes.h:

∙ Reference to 'Ptr' is ambiguous: Candidate found by name lookup is 'cv::Ptr'
∙ Reference to 'Point' is ambiguous: Candidate found by name lookup is 'cv::Point'
∙ Reference to 'Rect' is ambiguous: Candidate found by name lookup is 'cv::Rect'

Is there some way to disambiguate the symbols?

-Carl


Glenn L. Austin
 

You can always put the #import inside its own namespace, e.g.

namespace OpenCV {
#import "opencv/header.h"
}

To use:

result = OpenCV::opencvAPI(parameters)

-- 
Glenn L. Austin, Computer Wizard and Race Car Driver         <><
<http://www.austinsoft.com>

On Aug 13, 2020, at 5:38 PM, Carl Hoefs <newslists@...> wrote:

Objc++, macOS 10.14, OpenCV2

I'm trying to issue Objc methods from within a .mm file, without success.

For instance:

   [[NSNotificationCenter defaultCenter] postNotificationName:@"GUIStatusUpdate"
             object: nil
             userInfo: @{@"Status String" : @"Calculating Contour Features..."}];

Xcode gives an error: Use of undeclared identifier 'NSNotificationCenter'

If I add:

 #ifdef __cplusplus
 #import <UIKit/UIKit.h>
 #endif

then Xcode complains about 3 OpenCV C++ types that conflict with similarly named types in /usr/include/MacTypes.h:

∙ Reference to 'Ptr' is ambiguous: Candidate found by name lookup is 'cv::Ptr'
∙ Reference to 'Point' is ambiguous: Candidate found by name lookup is 'cv::Point'
∙ Reference to 'Rect' is ambiguous: Candidate found by name lookup is 'cv::Rect'

Is there some way to disambiguate the symbols?

-Carl







Carl Hoefs
 

Glenn,

I got it sorted!
Thanks for the hint!

-Carl


On Aug 13, 2020, at 6:16 PM, Glenn L. Austin <glenn@...> wrote:

You can always put the #import inside its own namespace, e.g.

namespace OpenCV {
#import "opencv/header.h"
}

To use:

result = OpenCV::opencvAPI(parameters)

-- 
Glenn L. Austin, Computer Wizard and Race Car Driver         <><
<http://www.austinsoft.com>

On Aug 13, 2020, at 5:38 PM, Carl Hoefs <newslists@...> wrote:

Objc++, macOS 10.14, OpenCV2

I'm trying to issue Objc methods from within a .mm file, without success.

For instance:

   [[NSNotificationCenter defaultCenter] postNotificationName:@"GUIStatusUpdate"
             object: nil
             userInfo: @{@"Status String" : @"Calculating Contour Features..."}];

Xcode gives an error: Use of undeclared identifier 'NSNotificationCenter'

If I add:

 #ifdef __cplusplus
 #import <UIKit/UIKit.h>
 #endif

then Xcode complains about 3 OpenCV C++ types that conflict with similarly named types in /usr/include/MacTypes.h:

∙ Reference to 'Ptr' is ambiguous: Candidate found by name lookup is 'cv::Ptr'
∙ Reference to 'Point' is ambiguous: Candidate found by name lookup is 'cv::Point'
∙ Reference to 'Rect' is ambiguous: Candidate found by name lookup is 'cv::Rect'

Is there some way to disambiguate the symbols?

-Carl








 



On Aug 13, 2020, at 6:16 PM, Glenn L. Austin <glenn@...> wrote:

namespace OpenCV {
#import "opencv/header.h"
}

To use:

result = OpenCV::opencvAPI(parameters)

Uh … that won't help, just cause link errors — declaring the OpenCV API as being in an OpenCV namespace doesn't change the fact that the implementation isn't in that namespace*. So the code will be calling OpenCV::cv::Foo, but the actual function is named cv::Foo.

The issue seems to be that the source file has a "using namespace opencv" declaration, so all the OpenCV types get dumped into the global namespace where they can conflict with C symbols. The fix is not to do that — just bite the bullet and type "cv::Foo" instead of "Foo".

—Jens

* Kind of like the old joke "Q: How many legs does a dog have, if you call a talk a leg? A: Four. Calling it a leg doesn't make it one."


Carl Hoefs
 

The fix is not to do that — just bite the bullet and type "cv::Foo" instead of "Foo".

Yes, actually, that is what I ended up doing. Glenn's hint prompted the idea of simply namespace-qualifying the offending quantities. Not a big deal in the end.

-Carl


On Aug 14, 2020, at 11:51 AM, Jens Alfke <jens@...> wrote:



On Aug 13, 2020, at 6:16 PM, Glenn L. Austin <glenn@...> wrote:

namespace OpenCV {
#import "opencv/header.h"
}

To use:

result = OpenCV::opencvAPI(parameters)

Uh … that won't help, just cause link errors — declaring the OpenCV API as being in an OpenCV namespace doesn't change the fact that the implementation isn't in that namespace*. So the code will be calling OpenCV::cv::Foo, but the actual function is named cv::Foo.

The issue seems to be that the source file has a "using namespace opencv" declaration, so all the OpenCV types get dumped into the global namespace where they can conflict with C symbols. The fix is not to do that — just bite the bullet and type "cv::Foo" instead of "Foo".

—Jens

* Kind of like the old joke "Q: How many legs does a dog have, if you call a talk a leg? A: Four. Calling it a leg doesn't make it one."