"Token is not a valid binary operator in a preprocessor subexpression" when using UIKitForMac - xcode11

So I'm trying to compile my iOS project for the mac, and when I try to use
#if !targetEnvironment(UIKitForMac)
I'm getting the error from the title.
I tried setting the build target to iOS 13, but didn't seem to have any effect.

Objective-C
#if !TARGET_OS_MACCATALYST
// Code to exclude from Mac.
#endif
Swift
#if !targetEnvironment(macCatalyst)
// Code to exclude from Mac.
#endif
Sources:
https://developer.apple.com/documentation/uikit/creating_a_mac_version_of_your_ipad_app?language=objc
https://developer.apple.com/documentation/xcode/creating_a_mac_version_of_your_ipad_app

If you're using objective-c and not swift you should use:
#if !TARGET_OS_UIKITFORMAC
#endif

Related

Setting sdkconfig using platform.io for the ESP32

I was wondering if anybody managed to set the SDKConfig.h file for the ESP32 when using platform.io to upload code, and if so how it is done.
Thanks in advance!
✌️
You can copy and modify the file SDKConfig.h into your project include folder from:
/.platformio/packages/framework-arduinoespressif32/tools/sdk/include/config/
or paste "CONFIG_ULP_COPROC_RESERVE_MEM" in your code and <Ctrl+LClick> to go to this file in your system.
And add this to your platformio.ini so that the file in your project has priority
build_flags =
-Iinclude
Tested with framework-arduinoespressif32 Version 3.10006.210326 (1.0.6)
Let me know if it works for you, I'm guessing it could work with the other frameworks?
if some of the definitions gives you a problem because they are defined elsewhere just add a guard like this:
#ifndef CONFIG_FLASHMODE_DIO
#define CONFIG_FLASHMODE_DIO 1
#endif

where is the interface header file of HIDL in AOSP?

I studied the HIDL using Nfc code in AOSP .
As i know, when INfc.hal is compiled, INfc.h is autogenerated like following picture.
In NxpService.cpp, there is code like following
#include <android/hardware/nfc/1.1/INfc.h>
But, I couldn't find that path.
where is the real path of android/hardware/nfc/1.1/INfc.h?
In addition, I became curious how gcc compile works in NxpService.cpp that uses INfc.h.
Could you explain how gcc compiler can find INfc.h and work without compile error?
INfc.hal
Path: /hardware/interfaces/nfc/1.1/INfc.hal
Android.bp
hidl_interface {
name: "android.hardware.nfc#1.1",
root: "android.hardware",
NxpService.cpp
Path: /hardware/nxp/nfc/1.1/NxpService.cpp
#include <android/hardware/nfc/1.1/INfc.h>
...
int main(){
sp<INfc> nfc_service = new Nfc();
status_t status = nfc_service->registerAsService();
android.hardware.nfc#1.1 would be at hardware/interfaces/nfc/1.1/ here.
The mappings for Android provided interfaces to their actual location are shown here https://source.android.com/devices/architecture/hidl/interfaces.
The files you look for are all auto-generated by hidl-gen, and they usually locate in out directory, e.g.
$ANDROID_ROOT/out/soong/.intermediates/hardware/interfaces/nfc/1.1/android.hardware.nfc#1.1_genc++_headers/gen/android/hardware/nfc/1.1

Use of unresolved identifier GGLContext and GAI

I am having a bit of trouble. I am attempting to install Google Analytics into an app and am consistently getting the use of unresolved identifier GGLContext and GAI error. I receive the same error whether I am using CocoaPods or not. The location of the error is in the AppDelegate.swift here:
func application(application: UIApplication, didFinishLaunchingWithOptions launchOptions: [NSObject: AnyObject]?) -> Bool {
// Override point for customization after application launch.
var configureError:NSError?
GGLContext.sharedInstance().configureWithError(&configureError)
assert(configureError == nil, "Error configuring Google services: \(configureError)")
// Optional: configure GAI options.
let gai = GAI.sharedInstance()
gai.trackUncaughtExceptions = true // report uncaught exceptions
return true
}
Nothing additional is able to be imported into the AppDelegate.swift(such as Google), just the standard UIKit.
I have been through many tutorials and other SO questions, all to no avail. I figure that there is some small thing I am missing, but cannot find it.
What I've done:
I have the .h files in my project, along with libGoogleAnalyticsServices.a, libsqlite3.0.tbd, libz.tbd, libsqlite3.tbd (all of which have been linked to library as well as CoreData and SystemConfiguration).
You can see the layout of all these files here:
and here:
I have created the -Bridging-Header.h and included these .h imports in it.
#import "GAI.h"
#import "GAIDictionaryBuilder.h"
#import "GAIEcommerceFields.h"
#import "GAIEcommerceProduct.h"
#import "GAIEcommerceProductAction.h"
#import "GAIEcommercePromotion.h"
#import "GAIFields.h"
#import "GAILogger.h"
#import "GAITrackedViewController.h"
#import "GAITracker.h"
The -Bridging-Header.h is linked in the Build Settings and I receive no errors with that. That is the main solution that I have found during my research, which hasn't helped me in this situation.
I have tried to start over from scratch twice with CocoaPods and without (I made a copy of my project before starting) and I received the same error each time.
Any help would certainly be appreciated. Thanks in advance.
Well, it looks like I was able to get it squared away.
There were several problems with all attempts on this.
Cocoapods had not installed correctly. I reinstalled and then had better success importing the correct files.
Doing it manually, as I posted above is not the best option.
After the Cocoapods re-install and starting over from a fresh copy of my project, I was able to import Google into my AppDelegate.swift.
Key points for those who may end up in the same boat I was in:
Be sure to add the correct directory for your -Bridging-Header.h. You can find this under Project - Build Settings - Swift Compiler Code Generation. Use this to easily target your header file $(SWIFT_MODULE_NAME)-Bridging-Header.h
In your -Bridging-Header.h, do not #import <Google/Analytics.h>, instead import the files individually. Here is an image of the files available to be imported.
When in doubt, reinstall Cocoapods
Do not trust Google tutorials to provide the most effective instruction and utilize the many SO posts on the topic.
I really hope this helps someone not spend 10 hours on the problem as I have.
Swift 4.0 and xcode 9.0.1 finally I resolved.
For me after 2 days I resolved.. Don't follow Google's old documentation says #import <Google/Analytics.h>
Go to Terminal type pod init
Reopen project as workspace obvious after pod workspace is created, open podfile. write pod 'GoogleAnalytics' in your pod file before target 'GoogleAnalytics' do
Go back to Terminal pod install you will find frameworks GAI.h and other files will be there under pods folder
Create Header.h file to your root. Don't add #import <Google/Analytics.h> instead import following individually in bridging header file
e.g. in bridging header file remove #import <Google/Analytics.h>
#import GAI.h
#import "GAITracker.h"
#import "GAIFields.h"
#import "GAIDictionaryBuilder.h"
Point your bridge under Build Settings for target Swift Compiler - General -> Objective-C Bridging Header. write Header.h of your bridging file name
Add code from google for swift to didFinishLaunchingWithOptions Don't forget to replace your tracking id from Google Analytics page
guard let gai = GAI.sharedInstance() else {
assert(false, "Google Analytics not configured correctly")
}
gai.tracker(withTrackingId: "YOUR_TRACKING_ID")
// Optional: automatically report uncaught exceptions.
gai.trackUncaughtExceptions = true
// Optional: set Logger to VERBOSE for debug information.
// Remove before app release.
gai.logger.logLevel = .verbose;
Tada.... Run your project...
My error was use of unresolved identifier when i was using the singleton GAI.sharedInstance().
My steps to bring this to work were:
add pod 'Google/Analytics'
pod install
restart xcode
create a objc class in my project to get a bridging header
added #import "GAI.h" in to the bridging header file
everything works perfectly.
This works for swift 2.3, swift 3.0 and swift 4:
add the GoogleService-Info.plist file to the root of your project
add this to the podfile:
pod 'Google/Analytics'
quit Xcode, run "pod install" in terminal and open Xcode again
create a header file in the project root, named Bridging-Header.h, under build settings make sure the bridging header is defined like in the picture
make sure your Bridging-Header.h looks like this:
#ifndef Bridging_Header_h
#define Bridging_Header_h
#import <Google/Analytics.h>
#endif /* Bridging_Header_h */
add to AppDelegate:
import Google
add this code to AppDelegate in the didFinishLaunchingWithOptions method:
// Configure tracker from GoogleService-Info.plist.
var configureError: NSError?
GGLContext.sharedInstance().configureWithError(&configureError)
assert(configureError == nil, "Error configuring Google services:\(configureError)")
// Optional: configure GAI options.
guard let gai = GAI.sharedInstance() else {
assert(false, "Google Analytics not configured correctly")
}
gai.trackUncaughtExceptions = true // report uncaught exceptions
gai.logger.logLevel = GAILogLevel.Verbose // remove before app release
If there are errors, deleting DerivedData and cleaning the project can help.
The only way to make it work for me was downgrade Google Analytics pod version to 2.0.4.
pod 'Google/Analytics', '~> 2.0.4'

apt-pkg compile issue

I am trying to compile a third party code which uses apt-pkg. The error is
/usr/include/apt-pkg/depcache.h:188: error: ‘regex_t’ was not declared in this scope
I've verified that regex.h exists at /usr/include/regex.h
I am using ubuntu 10.4 64 bit to compile code.
what could be wrong?
You need to include regex.h in depcache.h before you use regex_t, or include it in whatever code includes depcache.h, before you include depcache.h.
Or perhaps there is an #ifdef that is set incorrectly for your environment and that is blocking the include of regex.h.

Where is the "App Bundle" looking for my media folder? Folder found when running app from Qt Creator, "file not found" when using Terminal

I'm having a little trouble making my app bundle work from the terminal or just double clicking it.
This App actually compiles, links and runs perfectly within the Qt Creator IDE. But, if I try to open it from the terminal I get a "media/file.x file not found" error. The App bundle nor the /Contents/MacOS/executable is finding the "media" folder that is supposed to be beside the executable.
In my app I do something like:
openFile("media/file.x");
In Windows and Linux, this file WILL be found if the "media" folder is exactly in the same hierarchical position of the executable (beside it). On the Mac I have discovered it works differently cause Qt Creator builds an "App Bundle" and the actual executable is inside the /Contents/MacOS folder, so I copied the "media" manually there. This worked without any hassle when "playing" my app from the Qt Creator but as mentioned before it doesn't work when running the bundle itself.
So does anyone know where or how can I homogenize the look for this "media" folder so it works on both: Qt Creator and the App bundle?
Lately, I have been using the following command to "install" the folder on the bundle.
mac {
MediaFiles.files = media
MediaFiles.path = Contents/MacOS
QMAKE_BUNDLE_DATA += MediaFiles
}
Thanks for your help.
After looking for a few days I found a couple of posts discussing the relative path problem. I was just not searching with the right words... The answer is displayed in:
Relative Paths Not Working in Xcode C++
http://www.experimentgarden.com/2009/06/how-to-load-resource-from-your.html
Basically it is necessary to add this:
//On the include part
#ifdef __APPLE__
#include "CoreFoundation/CoreFoundation.h"
#endif
// On the main of your app
// This makes relative paths work in C++ in Xcode by changing directory to the Resources folder inside the .app bundle
#ifdef __APPLE__
CFBundleRef mainBundle = CFBundleGetMainBundle();
CFURLRef resourcesURL = CFBundleCopyResourcesDirectoryURL(mainBundle);
char path[PATH_MAX];
if (!CFURLGetFileSystemRepresentation(resourcesURL, TRUE, (UInt8 *)path, PATH_MAX))
{
// error!
}
CFRelease(resourcesURL);
chdir(path);
std::cout << "Current Path: " << path << std::endl;
#endif
// ----------------------------------------------------------------------------
IMPORTANT:
The chdir, changes the working path of the app, so it is not necessary to change you relative code after that...

Resources