Doesn't build OBJ-C code in Qmake project - c++

/Users/uuu/Projects/osx/Menu.mm:28:
error: attempting to use the forward class 'NSObject' as superclass
of 'MenuProvider' #interface MenuProvider : NSObject
~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~ ^
in code:
#interface MenuProvider : NSObject
- (void)share:(bool)force userData:(NSString*)data;
#end
Qt Creator (qt 5.3), clang-600.0.51, osx

Add #import <Foundation/Foundation.h> above that #interface definition.

Related

ObjC app project gets build error at its reference to a C function within a .cpp file within ObjC class lib imported into app

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.

Parsing issues - Opencv with Xcode

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!

Build fail when trying to use ObjectiveC code in Swift

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.

Using Foundation 5 with Hammer for Mac and Bourbon

I asked a similar question yesterday because of the amount of time Compass was taking to watch and compile my Sass files.
So, I pose this question. What is the ideal way to use a framework like Foundation 5, and still have the ability to update it in the future, while using Hammer for Mac for compiling and optimising my stylesheets and allows me to use the Bourbon mixins instead of Compass.
Any help is appreciated. Thanks in advance!
If you want to update Foundation in the future without any problems, you should follow rule: don't change files in foundation/components directory
all variables, that you need, you can find in foundation/settings.
some example of app.scss:
#import "bourbon";
#import "settings"; //where you can change all variables
#import "foundation"; //better
settings file look like:
https://github.com/zurb/foundation/blob/master/scss/foundation/_settings.scss
I arrange my styles as follows to ensure a clear separation:
styles/
app.scss
_settings.scss
external/
_bourbon.scss
_foundation5.scss
My externals folder above does not contain vendor CSS but is instead used for (selectively) importing vendor CSS located elsewhere in my project by using a sass load path.
I currently fetch vendor CSS using bower, therefore all my CSS lives in a bower_components/ folder at the root of my project. This way I can easily update to newer versions and there is a clear separation from what is vendor source and what is specific to my project.
I found I also had to resolve a few conflicts with bourbon and foundation as follows. I am currently using Bourbon 3.1.8 but experimented briefly with 3.2 (which doesn't yet compile with he current sass toolchain) hence the commented out lines specific to Bourbon 3.2:
// external/_bourbon.scss
// we comment out things that conflict with foundation styles
//#import "bower-bourbon/settings/prefixer"; // 3.2+ only
//#import "settings/px-to-em"; // 3.2+ only
// Custom Helpers
#import "bower-bourbon/helpers/deprecated-webkit-gradient"; // 3.1.8 only
#import "bower-bourbon/helpers/gradient-positions-parser";
#import "bower-bourbon/helpers/linear-positions-parser";
#import "bower-bourbon/helpers/radial-arg-parser";
#import "bower-bourbon/helpers/radial-positions-parser";
#import "bower-bourbon/helpers/render-gradients";
#import "bower-bourbon/helpers/shape-size-stripper";
// Custom Functions
//#import "bower-bourbon/functions/assin"; // 3.2+ only
#import "bower-bourbon/functions/compact"; // 3.1.8 only
//#import "bower-bourbon/functions/flex-grid"; // foundation conflict
//#import "bower-bourbon/functions/grid-width"; // foundation conflict
#import "bower-bourbon/functions/linear-gradient";
#import "bower-bourbon/functions/modular-scale";
#import "bower-bourbon/functions/px-to-em";
#import "bower-bourbon/functions/radial-gradient";
//#import "bower-bourbon/functions/strip-units"; // 3.2+ only
#import "bower-bourbon/functions/tint-shade";
#import "bower-bourbon/functions/transition-property-name";
//#import "bower-bourbon/functions/unpack"; // 3.2+ only
// CSS3 Mixins
#import "bower-bourbon/css3/animation";
#import "bower-bourbon/css3/appearance";
#import "bower-bourbon/css3/backface-visibility";
#import "bower-bourbon/css3/background";
#import "bower-bourbon/css3/background-image";
#import "bower-bourbon/css3/border-image";
#import "bower-bourbon/css3/border-radius";
//#import "bower-bourbon/css3/box-sizing"; // foundation conflict
//#import "bower-bourbon/css3/calc"; // 3.2+ only
//#import "bower-bourbon/css3/columns"; // foundation conflict
#import "bower-bourbon/css3/flex-box";
#import "bower-bourbon/css3/font-face";
//#import "bower-bourbon/css3/hyphens"; // 3.2+ only
#import "bower-bourbon/css3/hidpi-media-query";
#import "bower-bourbon/css3/image-rendering";
#import "bower-bourbon/css3/inline-block";
#import "bower-bourbon/css3/keyframes";
#import "bower-bourbon/css3/linear-gradient";
#import "bower-bourbon/css3/perspective";
#import "bower-bourbon/css3/radial-gradient";
#import "bower-bourbon/css3/transform";
#import "bower-bourbon/css3/transition";
#import "bower-bourbon/css3/user-select";
#import "bower-bourbon/css3/placeholder";
// Addons & other mixins
//#import "bower-bourbon/addons/button"; // foundation conflict
//#import "bower-bourbon/addons/clearfix"; // foundation conflict
#import "bower-bourbon/addons/font-family";
#import "bower-bourbon/addons/hide-text";
//#import "bower-bourbon/addons/directional-values"; // 3.2+ only
//#import "bower-bourbon/addons/ellipsis"; // 3.2+ only
#import "bower-bourbon/addons/html5-input-types";
#import "bower-bourbon/addons/position";
#import "bower-bourbon/addons/prefixer";
//#import "bower-bourbon/addons/rem"; // 3.2+ only
#import "bower-bourbon/addons/retina-image";
#import "bower-bourbon/addons/size";
#import "bower-bourbon/addons/timing-functions";
//#import "bower-bourbon/addons/triangle"; // foundation conflict
// Soon to be deprecated Mixins
#import "bower-bourbon/bourbon-deprecated-upcoming";
Importing foundation is just a one-liner currently but you could tweak it to only source what you need from foundation:
// external/_foundation5.scss
#import 'foundation/scss/foundation';

Expected specifier-qualifier-list before

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