All of a sudden, I'm getting "Expected unqualified-id" and "Type name declared as a reference to a reference" parsing issues from importing opencv2/opencv.hpp I tried relinking opencv3, upgraded from opencv 3 to 4 and restarted Xcode. How can this be resolved?
Used prebuilt opencv from here: https://opencv.org/releases/ and Xcode 10.2
See All Parsing Errors
Expected unqualified-id:
CODE - Removed everything and left with this, but it still has parsing errors.
-------
.mm
------
#import <opencv2/opencv.hpp>
#import <opencv2/imgcodecs/ios.h>
#import <Foundation/Foundation.h>
#import "OpenCVWrapper3.h"
#include <vector>
using namespace std;
#implementation OpenCVWrapper3
+ (NSString *) openCVVersionString
{
return [NSString stringWithFormat:#"OpenCV Version %s", CV_VERSION];
}
#end
----
.h
----
#import <Foundation/Foundation.h>
#import <UIKit/UIKit.h>
#interface OpenCVWrapper3 : NSObject
+ (NSString *) openCVVersionString;
#end
Ok so... I don't have a clue what caused the error. I opened another ios project that uses opencv and it gave the same errors. Then I created a new project and added #include iostream, ostream and got the same error. So its was not isolated to opencv. So I deleted and reinstalled Xcode and now it works!! Bizarre!
Related
Project “app” gets build err: "Undefined symbol: run_mobile_session()"
Proj app includes ObjC class lib project hub_lib.
Proj hub_lib has folder with main.cpp file that has function "run_mobile_session()" that is undefined in app build
I build without error the hub_lib project and did ctrl-drag of its .h and .a from its Xcode folders pane to a folder within project app.
I dragged .h & .a from folder within app to folder pane of app. (ie. imported)
I selected target to be my provisioned iPhone.
Built app, got error.
I ran nm on and get this...
DOUGs-MacBook-Pro:mobile_sys_hub_lib dbell$ nm libmobile_sys_hub_lib.a | grep run_mobile_session
U __Z18run_mobile_sessionv
DOUGs-MacBook-Pro:mobile_sys_hub_lib
The U at the front of the line is "undefined". nm thinks you have a reference to the symbol but no implementation. – Phillip Mills
Doug: main.cpp seems to be getting compiled in the class lib: I put junk "zzzzzz" within run_mobile_session() and get build error.
THE CODE...
------------------------------------------- ObjC app project...
//app.h ...........................
#import <UIKit/UIKit.h>
#interface ViewController : UIViewController
#end
// ViewController.mm ....................
#import <UIKit/UIKit.h>
#import "hub_lib.h"
#interface ViewController ()
#end
#implementation ViewController
. . .
- (IBAction)start_session:(id)sender
{
hub_lib* _lib = [hub_lib new];
NSLog(#"app: %d", [ _lib start_session]);
}
#end
--------------------------------------- lib project...
// hub_lib.h ....................
#import <Foundation/Foundation.h>
#interface hub_lib : NSObject
#end
// hub_lib.mm ......................................
#import "hub_lib.h"
#import <UIKit/UIKit.h>
#implementation hub_lib
extern void run_mobile_session(void);
. . .
-(int)start_session
{
run_mobile_session();
return 0;
}
#end
--------------------------------------- C++ folder within lib project...
// main.cpp .....................
#include <stdio.h>
void run_mobile_session(void);
. . .
void run_mobile_session(void)
{
. . .
}
Solution was to move the extern from hub_lib.mm to hub_lib.h and mod to be C++:
extern "C++" void run_mobile_session(void);
Thanks for solution, gnasher729.
I've built opencv2.framework using OpenCV 3.4 and opencv_contrib in order to use the aruco library. I'm importing this framework into Xcode and I am able to import and use standard OpenCV modules with no compile errors.
I can #import <aruco/aruco.h> with no compile errors. However, as soon as I try to use any classes from aruco I get a compile error. In this case:
Undefined symbols for aruco::MarkerDetector::~MarkerDetector()
#import <opencv2/opencv.hpp>
#import <opencv2/core.hpp>
#import <opencv2/imgcodecs/ios.h>
#import <opencv2/imgproc/imgproc.hpp>
#import <aruco/aruco.h>
-(void)doSomething() {
//anything in cv:: lib is fine, no compile errors
cv::Mat mat(3,3,CV_32);
//but as soon as I try to use aruco I get compile error
aruco::MarkerDetector detector;
}
I got this working. If I include, vs import aruco - #include "opencv/aruco.hpp" I can then use aruco cv::aruco::detectMarkers(....).
For some reason when I import aruco, the code completion doesn't seem to accurately reflect the API and that was causing additional confusion.
I am trying to use one of my Objective-C class from another target, in my Swift class inside extension target.
I created the <Project-Name>-Bridging-Header.h and included that objective-c file, but the build is not compiling because of build error in "Cryptor.h" and <CommonCrypto/CommonDigest.h>. I believe this has to do something with CommonCrypto framework.
This is how my Bridging-Header.h looks:
#import <UIKit/UIKit.h>
#import <FacebookSDK/FacebookSDK.h>
#import <GooglePlus/GooglePlus.h>
#import <Security/Security.h>
#import <CommonCrypto/CommonCrypto.h>
#import <CommonCrypto/CommonDigest.h>
I guess this is due to Common Crypto library. Has anybody encountered the same issue and solved it?
EDIT:
Specifically, i am getting build error - "Missing #end" in CommonDigest.h and because CommonDigest.h is not getting build hence the error in Cryptor.h.
I don't know if it will fix your problem, but the bridge-header is sometimes a bit buggy. At least it was the case for me.
Try to edit your header and import your files like that:
#import "FacebookSDK.h"
#import "GooglePlus.h"
#import "Security.h"
#import "CommonCrypto.h"
#import "CommonDigest.h"
I have removed the UIKit-header, because you don't really need it, because swift has it's own UIKit.
I've been using Objective-C mixed with C++ in Qt without any issues; using .mm files where required.
After upgrading my build machine to Mavericks, I initially noticed that the framework headers were missing, so installed the XCode command line tools, which fixed the issue.
Now, I'm getting a problem compiling Objective-C files with errors complaining about code in the frameworks. For example: -
System/Library/Frameworks/Foundation.framework/Versions/C/Headers/NSUserNotification.h:16:44: error: missing ',' between enumerators
NSUserNotificationActivationTypeReplied NS_AVAILABLE(10_9, NA) = 3
And
/System/Library/Frameworks/AppKit.framework/Versions/C/Headers/NSApplication.h:58:34: error: expected ';' after top level declarator
typedef NSInteger NSModalResponse NS_AVAILABLE_MAC(10_9);
I've upgraded to Qt 5.2.1, but the issues remain and it's coming from including standard framework headers; in this case: -
#import <NSUserNotification.h>
#import <NSApplication.h>
Can someone please explain what's changed in Mavericks and how I can fix these errors?
You're supposed to include the frameworks as Framework/Header.h. It seems that you've added some unnecessary includes to your project file.
The following works for me:
#project.pro
TEMPLATE = app
LIBS += -framework AppKit -framework Foundation
OBJECTIVE_SOURCES = main.mm
//main.mm
#import <Foundation/NSUserNotification.h>
#import <AppKit/NSApplication.h>
#include <QCoreApplication>
int main(int argc, char ** argv)
{
QCoreApplication a(argc, argv);
NSApplication * app = [NSApplication sharedApplication];
return 0;
}
I have the following Objective-C headers:
// Menu.h
#import <UIKit/UIKit.h>
#import "GameController.h"
#interface Menu : UIImageView {
GameController *gameController; // "Expected specifier-qualifier-list
// before GameController"
}
- (void)appear;
#end
and
// GameController.h
#import <UIKit/UIKit.h>
#import "Menu.h"
#interface GameController : UIView {
Menu *menu; // "Unknown type name 'Menu'"
}
- (void)startLevel0;
- (void)startLevel1;
- (void)startLevel2;
#end
When I try to build the project, Xcode (v4) yells at me, saying Expected specifier-qualifier-list before GameController and unknown type name 'Menu'. I'm sure that they are somehow related, but I have no idea how?
It's not good practice to have mutually-including header files. Instead of importing Menu.h, use the #class directive. Try removing #import "Menu.h" and adding #class Menu in its place. Ditto for Menu.h (remove GameController include, and add the #class directive)
You have a circular reference in your imports. The compiler builds a dependency tree from the import statements so when two Classes rely on each other it doesn't know how to compile one before the other.
Sadly, gcc kicks out a fairly nonsensical error statement when this happens "Expected specifier-qualifier-list". #yan is correct that you should use the #class directive. Check out this question for a solid explanation: #class vs. #import