I have a relatively unique project layered with file types (top to bottom) SwiftUI, Swift, Objective C, and C. The purpose of this layering is that I have a C language firmware application framework for development of firmware on custom electronic boards.
Specifically, I use the standard C preprocessor in specific ways to make data driven structures, not code. There are header files shared between the firmware project and the Xcode iPhone app to set things like the BLE protocol and communication command/reply protocols, etc. The app is forced to adhere to that defined by the firmware, rather than rely a design to get it right.
The Objective C code is mainly to utilize the Bluetooth stack provided by iOS. I specifically use this approach to allow C files to be compiled. Normally, everything has worked perfectly, but a serious and obtuse problem just surfaced a couple days ago.
My important project was created long ago. More recently, I started a new project using most of the same technology, but its project is newer. Ironically, it continues to work perfectly, but ironically the older project stopped working. (Talking about the Xcode iOS side.)
Essentially, the Objective C handling of the C preprocessor is not fully adhering to the standard C preprocessing in one project. It's very confusing because there is no code change. It seems Xcode was updated, but looks like the project was not updated, accordingly? I'm guessing there is some setting that forces Objective C to adhere to the standard C preprocessor rules.
I did see a gnu compiler version that did not get updated compared to the newer project, but updating that in the Build Settings did not fix the problem.
The error is in the title:
Token is not a valid binary operator in a preprocessor subexpression.
The offending macro appears in a header file, included in several implementation files. Compiling a single implementation files isolates the issue somewhat. An implementation with no Objective C objects compiles just fine. If there are Objective C objects then I get the errors. Both cases include the same header.
It seems like the Objective C compiler, being invoked, uses a different C preprocessor parser, rather than the standard. I guess I should mention the bridging header file where these headers exist, as well. The offending header with the problem macro appears as an error in the bridging header if a full build is initiated.
Is there an option somewhere, that forces the Objective C compiler to honor the standard C processor? Note, one project seems to.
#define BLE_SERVICE_BLANK( enumTag, uuid, serviceType )
#define BLE_CHARACTERISTIC_BLANK( enumTag, uuid, properties, readPerm, writePerm, value)
#define BLE_SERVICE_ENUM_COUNTER( enumTag, uuid, serviceType) +1
#define BLE_CHARACTERISTIC_ENUM_COUNTER( enumTag, uuid, properties, readPerm, writePerm, value) +1
#if 0 BLE_SERVICE_LIST(BLE_SERVICE_ENUM_COUNTER, BLE_CHARACTERISTIC_BLANK) > 0
#define USING_BLE_SERVICE
...
#if 0 BLE_SERVICE_LIST(BLE_SERVICE_BLANK, BLE_CHARACTERISTIC_ENUM_COUNTER) > 0
#define USING_BLE_CHARACTERISTIC
...
token is not a valid binary operator in a preprocessor subexpression
refers to the comparison. BLE_SERVICE_LIST() does a +1 for each item in the list. There is no further expansion. One counts services. The other counts characteristics. The errors are associated with the comparisons.
General
RSS for tagDive into the world of programming languages used for app development.
Post
Replies
Boosts
Views
Activity
When Xcode is connected to the mobile phone for debugging, the app that contains the logic of executing machine code runs normally, but if Xcode is disconnected and the app is run alone, it will crash.
First use the xcode-run execution function to start the app
The machine code logic executes normally
Disconnect the phone from xcode
Start the app
5.Crash
Here is the test code:https://gitee.com/FanChiang_admin/demo.git
So I found out clang can do multiarch compiles (-arch arm64 -arch x86_64). But Apple seems to have left precompiled header support out. So I built the pch separately for each arch. That all works.
The next problem is that one needs to specify -include-pch foo.x64.pch and -include-pch foo.arm64.pch on the command line. This doesn't work on the compile line, since it tries to prepend arm64 AST to a x64 .o file, and vice versa.
So there is -Xarch_arm64 and -Xarch_x86_64 . But that option is limited to one argument. But "-include-pch foo.x64.pch" is two arguments.
More details of failed attempts here:
https://github.com/llvm/llvm-project/issues/114626
And no splitting out the builds isn't the same, because then -valid_arch I don't think skips the other build. This are all libraries being built by Make, and then the universal app built using an Xcode project from the libraries.
Hello,
Im developing an app entirely with C++, and I need to call various swift functions because it requires the Swift library.
Ive seen several posts on forums about C++ callbacks and honestly I dont understand how its done exactly. I get the general idea but I am not able to understand it and make it work. I feel like people throw vague ideas and weird function names and everything gets confusing.
Could anyone give me the smallest example that works please ?
Just to make sure you know what I mean, here is an example of what I want to do, but you dont have to generate the code exactly for this, I want an example that I can understand please, but the swift code has to depend on a swift library. I dont want to simply call a swift function that returns x*2 ...
{1} notif.swift file : coded in swift language
include <UserNotifications/UserNotifications.h>
function A that show notification in swift code.
{2} mainwindow.cpp file : coded in C++ language
import notif.swift ??
button connected to slot/function mybuttonclicked.
MainWindow::mybuttonclicked(){
std::string my_result = call function A_from_swift_file(argument_1);
}
--The end ---
I wrote the notif.swift with '?' because I dont know how you include the swift file from your cpp code and I could not find that anywhere. Maybe it is obvious, but I would really appreciate getting some help on this, Thank you everyone
I tried to install the flang-new compiler from Homebrew on Sequoia OSX. Complex division is broken because file divdc3 is missing. This file comes from libclang_rt.osx.a, a standard LLVM library. This library is missing on OSX.
program test
integer, parameter :: n=2
complex(kind=8), dimension(n,n) :: V
complex(kind=8) :: PER
V(1,1)=cmplx(4.0,2.0)
V(2,2)=cmplx(5.0,3.0)
V(1,2)=0.0
V(2,1)=0.5
PER=cmplx(1.2,1.2)
V(:,:)=V(:,:)/PER
end program test
alainhebert@Alains-MacBook-Air-2 test_complex % flang-new test.f90
Undefined symbols for architecture arm64:
“___divdc3”, referenced from:
__QQmain in test-fc2bb3.o
ld: symbol(s) not found for architecture arm64
flang-new: error: linker command failed with exit code 1 (use -v to see invocation)
In my project, i am initialising bytes with some character in cpp function, func CreateByteWithVal (), and passing to a function, func CreateNSStringFromCString(_ pPtr : UnsafeMutableRawPointer, _ pLength : Int), in swift using Swift-Cpp interop.
CreateByteWithVal () allocates bytes on heap with value "AAAAAAAAAA", also calls swift function CreateNSStringFromCString.
And func CreateNSStringFromCString (_ pPtr : UnsafeMutableRawPointer, _ pLength : Int) creates a NSString instance using NSString's BytesNoCopy initialiser using the bytes (pPtr) passed to it in parameter.
Cpp code:
void
CppClass::CreateByteWithVal ()
{
char * bytesForString = (char *) malloc (10);
memset (bytesForString, 65, 10);
Interop_Swift::CreateNSStringFromCString (bytesForString, 10);
}
Swift code:
public func CreateNSStringFromCString (_ pPtr : UnsafeMutableRawPointer, _ pLength : Int) {
let ns_string:NSString = NSString (bytesNoCopy: pPtr, length: pLength, encoding: String.Encoding.utf8.rawValue, freeWhenDone: false)
}
If we modify the byte values in memory from C++ directly, the NSString instance, which is supposed to be immutable by nature, reflects these changes. Is this approach appropriate, or is there something we're overlooking or need to address? In our project, we are mutating the byte values directly like this, and the changes are being reflected in the NSString instance :
memset (bytesForString, 66, 5);
Essentially, I want to confirm whether we can use this method to modify values through C++ without directly mutating the NSString instance.
For the UI, we'll be reading the NSString instance by creating a native Swift String instance from it, like this:
let str:String = ns_string as String
Will the value of str remain consistent as long as we ensure that the correct bytes are provided by C++?
Every time a (valid) vector instruction is added to the .s file, xcode report an error
(without vector instruction the .s file compile correctly)
By example
vand q8, q8, q10
found in https://developer.apple.com/forums/thread/104424
give an error
What I am missing to tell xcode to accept vector instruction ?
I'm working on a cross-platform C# application that converts HTML content to PDF. The goal is to render dynamic HTML pages (including CSS and JavaScript) as high-quality, printable PDF files. Additionally, I need to support features like adding headers/footers, securing PDFs with passwords, and controlling user permissions. While everything works well on Windows, I need some help rendering consistency and handling permissions on MacOS.
I am using CHCSVParser in objective-c to use the CSVString extension of the Array instance method.
When I installed a new app on iOS18.1.1, the correct value (@"Application,"abc,def"") was returned for both the first and second turns, but
when I installed a new app on iOS18.2, the correct value was returned for the first turn, but @"" was returned for the second turn.
Even when I debug with step into, I can enter the CSVString for the first turn, but I cannot enter it for the second turn and after. It's as if the instance method is not being generated.
There are in-app purchases between the first and second turns, but the view controllers that are called are also the same.
Is there any change between iOS18.1.1 and iOS18.2?
[Code]
NSArray *application = [NSArray arrayWithObjects:KEY_APPLICATION, @"abc,def", nil];
NSString *applistring = [application CSVString];
NSString *appliStr = [application CSVString];
[Debug window 18.1.1 First]
application __NSArrayI * @"2 elements" 0x0000000302118c00
[0] __NSCFConstantString * @"Application" 0x00000001005deab8
[1] __NSCFConstantString * @"abc,def" 0x00000001005deb78
applistring __NSCFString * @"Application,"abc,def"" 0x0000000302f7d050
appliStr __NSCFString * @"Application,"abc,def"" 0x0000000302f706f0
[18.1.1 Second]
application __NSArrayI * @"2 elements" 0x00000003021b5200
[0] __NSCFConstantString * @"Application" 0x00000001005deab8
[1] __NSCFConstantString * @"abc,def" 0x00000001005deb78
applistring __NSCFString * @"Application,"abc,def"" 0x0000000302ff6dc0
appliStr __NSCFString * @"Application,"abc,def"" 0x0000000302fa4d20
[18.2 First]
sapplication __NSArrayI * @"2 elements" 0x00000003019d7e80
[0] __NSCFConstantString * @"Application" 0x00000001041c6ab8
[1] __NSCFConstantString * @"abc,def" 0x00000001041c6b78
applistring __NSCFString * @"Application,"abc,def"" 0x000000030179e430
appliStr __NSCFString * @"Application,"abc,def"" 0x000000030179e5e0
[18.2 Second]
application __NSArrayI * @"2 elements" 0x00000003019679a0
[0] __NSCFConstantString * @"Application" 0x00000001041c6ab8
[1] __NSCFConstantString * @"abc,def" 0x00000001041c6b78
applistring __NSCFConstantString * @"" 0x00000001efa04768
appliStr __NSCFConstantString * @"" 0x00000001efa04768
We are Java application developers and we have a question regarding camera access via WebRTC on iPadOS. Specifically, on iPadOS 17.1, we are encountering an issue when trying to access the camera via the WKWebView API in the Chrome browser, where an error occurs and the camera capture fails. Our investigation suggests that device access through the navigator.mediaDevices property via the WKWebView API may not work in Chrome. However, it works as expected in the Safari browser, leading us to wonder if this is a Chrome-specific limitation, or if it's due to an iPadOS setting or specification.
At this point, we are unsure if this issue is related to the WKWebView and WebRTC specifications on iPadOS 17.1, or if there are specific limitations in Chrome. We would appreciate any insights or solutions regarding camera access in iPadOS 17.1 with WKWebView and WebRTC, especially in relation to Chrome.
Hello,
I have a problem with Xcode, in C++ language. When I create a new project, I put my program in a file and click Build. It works correctly and without any problems, but when I enter a second file in the same project and click build, it says build failed. In the log it says, duplicate symbols appear.
Hello everyone.
macOS, IOBluetooth framework.
My goal is to create a temporary SDP service. According to the documentation, by default a temporary service is created (aka Persistent = NO), which is deleted after the application is closed.
The documentation also mentions the IOBluetoothRemoveServiceWithRecordHandle function for forced removal of the service. This function is deprecated and is currently unavailable. I guesse that it has been replaced by the IOBluetoothSDPServiceRecord.removeServiceRecord method.
The essence of the problem is that the server is not deleted either using removeServiceRecord or even after app closing.
That is, if you create several services and try to delete them, they will remain alive. Only turning Bluetooth off and on in the OS helps.
I tested all versions of macOS starting with Monteray. The same behavior.
for (int i = 0; i < 10; i++) {
service = [IOBluetoothSDPServiceRecord publishedServiceRecordWithDictionary:dictionary];
if (!service) {
NSLog(@"Failed to create service");
}
else
{
[service getRFCOMMChannelID:&channelID];
[service getServiceRecordHandle:&serverHandle];
NSLog(@"A new service has been created handle=%u, channelID=%hhu", serverHandle, channelID);
if (service.removeServiceRecord != kIOReturnSuccess) {
NSLog(@"Failed to delete service");
}
//service.release;
service = nil;
}
}
Can someone confirm this behavior? And is there a solution?
A minimal test example is available at the link
We want to do below addition to iOS Mobile App.
Airpod announces Push notification = which is workking
now we want to use voice command that "Reply to this" and sending Reply to that notification but it is saying it is not supported in your app.
So basically we need to use feature - Listen and respond to messages with AirPods
Do we need to add any integration inside app for this or it will directly worked with Siri settings ?
Is it possible to do in non messaging App?
Is it possible to do without syncing contacts ?
Crash Log
We have a issue with our watch app. When we do a release build with xcode 16 the watch app will not launch and crashes on watchOS 10 and below devices.
It does not do this on debug builds...and it does not do this on xcode 15 release/debug builds.
Anybody running into watch crashes on xcode 16?
Thanks
I have a class object created dynamically using Runtime, and I want to release some manually allocated memory resources when this object is deallocated. To achieve this, I added a custom implementation of the dealloc method using the following code:
SEL aSel = NSSelectorFromString(@"dealloc");
class_addMethod(kvoClass, aSel, (IMP)custom_dealloc, method_getTypeEncoding(class_getInstanceMethod(kvoClass, aSel)));
However, I encountered some issues. If I don't call the superclass's dealloc method in the cus_dealloc function, the superclass's dealloc implementation will not be executed. On the other hand, if I explicitly call the superclass's dealloc method, the program crashes.
Here is the implementation of the cus_dealloc function:
void custom_dealloc(id self, SEL _cmd) {
// Release other memory

Class superClass = class_getSuperclass(object_getClass(self));
void (*originIMP)(struct objc_super *, SEL, ...) = (void *)objc_msgSendSuper;
struct objc_super *objcSuper = &(struct objc_super){self, superClass};
originIMP(objcSuper, _cmd);
}
demo
Hello, I am a software engineer student and I have recently been getting problems on my Mac regarding the C/C++ libraries. I have used my macbook for uni work for months, but around 3 or 4 months ago my macbook could not compile my work since it couldnt find the basic libraries I was using. For example, iostream. I have been using VSCode, and what it exactly says is "cannot open source file "iostream". Please run the 'Select IntelliSense Configuration...' command to locate your system headers." I have tried researching, changing the include path, even using chatgpt, and nothing. Is anyone having this same problem, or is able to help me? If any other information is needed, please let me know!
I have a simple shell script as follows:
#!/bin/bash
OUTPUT="network.$(date +'%d-%m-%y').info.txt"
SUPPORT_ID="emailaddress"
echo "---------------------------------------------------" > $OUTPUT
echo "Run date and time: $(date)" >> $OUTPUT
echo "---------------------------------------------------" >> $OUTPUT
ifconfig >> $OUTPUT
echo "---------------------------------------------------" >> $OUTPUT
echo "Network info written to file: $OUTPUT."
echo "Please email this file to: $SUPPORT_ID."
It just dumps the network config into a file. At some point I will have the file emailed out, but right now I'm just trying to figure out why the output looks like the following?
bash ./test.sh
.etwork info written to file: network.26-01-25.info.txt
.lease email this file to: emailaddress
Why in the world does the initial character of the last couple of "echo" commands get clipped and turned into periods? The echos for the output of the commands piped into the output file are fine. Strange...
Any ideas?
I have a simple shell script as follows:
#!/bin/bash
OUTPUT="network.$(date +'%d-%m-%y').info.txt"
SUPPORT_ID="email"
echo "---------------------------------------------------" > $OUTPUT
echo "Run date and time: $(date)" >> $OUTPUT
echo "---------------------------------------------------" >> $OUTPUT
ifconfig >> $OUTPUT
echo "---------------------------------------------------" >> $OUTPUT
echo "Network info written to file: $OUTPUT."
echo "Please email this file to: $SUPPORT_ID."
It just dumps the network config into a file. At some point I will have the file emailed out, but right now I'm just trying to figure out why the output looks like the following?
bash ./test.sh
.etwork info written to file: network.26-01-25.info.txt
.lease email this file to: email
Why in the world does the initial character of the last couple of "echo" commands get clipped and turned into periods? The echos for the output of the commands piped into the output file are fine. Strange...
Any ideas?
Hi!
We are seeing a bit surprising behavior of dispatch_main on macOS where it seems to spawn a different thread instead of preserving the one it gets called from.
Managed to reproduce it in a completely empty command-line tool project in Xcode
int main(int argc, const char * argv[]) {
@autoreleasepool {
dispatch_main();
return 0;
}
}
I put a breakpoint on the line with dispatch_main and see that I am on Thread 1 and inside main function. That makes sense.
I resume execution and pause again. Looking at Thread output in Xcode, I can only see Thread 2.
Thread 1 is gone and the executable keeps on running.
So dispatch_main did what was expected (prevented the process from termination) but throws out the thread it was called from and creates a new one? Is that behavior expected or am I missing something?
Just a brain teaser at this point. But we could not make sense out of it. :)
Hello Apple Team,
I'm trying to import the Audodesk FBX SDK to my Objective-C iOS Project.
The SDK is written in C++, but has support for iOS and the iOS simulator architectures.
I've added the path to the include folder in the Header Search Path
I've also added the paths to libfbxsdk.a in the Library Search Paths
Finally, I've added the libfbxsdk.a file to the Link Binary with Libraries.
However, when I build the project, I get the following error:
building for 'iOS', but linking in object file (/Users/Lond/Documents/v2/Autodesk/iOS/2020.3.7/lib/ios/debug/libfbxsdk.a[28](fbxalloc.cxx.o)) built for 'macOS'
In the terminal, if I type the command:
lipo -info libfbxsdk.a
I get the message
Non-fat file: libfbxsdk.a is architecture: arm64
confirming that I'm using the library for the correct architecture.
Do I need to add any other confifuration option? (Like the other linker flag or something else)
I'm quite new to C++, and integrating a C++ SDK into iOS is not easy.
I'm using Mac Os Sonoma 14.6.1
Tested on Xcode 15.4 and 16.2
Target Device: iPhone 13 Pro (iOS 17.6.1)
iOS FBX SDK version: 2020.3.7
Link to the SDK if needed:
https://aps.autodesk.com/developer/overview/fbx-sdk
Any help would be greatly appreciated
Thank you