'Why is there no console output from Xcode when it calls a C++ dylib on my attached iPad?
Hello and thanks for taking the time to read my question. I've been trying to fix this issue myself for more than a week. I scoured the internet for an answer. I even opened a support ticket with Apple, but they declined to help.
I coded a SwiftUI app using Xcode on a MacBook. The app has two targets: one for MacOS and and another for iOS. It calls a function named start_stream() in a C++ dylib, which I built from source for both platforms. I added the iOS dylib to the frameworks list of the iOS target, and the MacOS dylib to the MacOS target.
The function prints a message to the console. I see that message in the Xcode console window, but only when I run the MacOS target on my MacBook. I do not see the message when I run the iOS target on my attached iPad.
The C++ function is:
int start_stream (int buffer_size, const char *streamer_params, int board_id,
const char *json_brainflow_input_params)
{
std::cout << "BLOOP" << std::endl;
Board::board_logger->info ("start_stream() board_id: {}", board_id);
std::lock_guard<std::mutex> lock (mutex);
std::pair<int, struct BrainFlowInputParams> key;
int res = check_board_session (board_id, json_brainflow_input_params, key, false);
if (res != (int)BrainFlowExitCodes::STATUS_OK)
{
return res;
}
auto board_it = boards.find (key);
return board_it->second->start_stream (buffer_size, streamer_params);
}
My Swift wrapper for the start_stream call is:
func startStream (bufferSize: Int32, streamerParams: String) throws {
try? BoardShim.logMessage(.LEVEL_INFO, "start streaming. buffer size: \(bufferSize)")
var cStreamerParams = streamerParams.cString(using: String.Encoding.utf8)!
var jsonBFParams = self.jsonBrainFlowInputParams
let errorCode = start_stream (bufferSize, &cStreamerParams, boardId.rawValue, &jsonBFParams)
try checkErrorCode("failed to start stream", errorCode)
}
And its entry in the bridging header is:
SHARED_EXPORT int CALLING_CONVENTION start_stream (int buffer_size, const char *streamer_params,
int board_id, const char *json_brainflow_input_params);
I expect to see the console message, "BLOOP", but I only see it for the MacOS target.
I am using Xcode 13.3 on a MacBook Pro M1 running MacOS 12.3, and an iPad Pro running iOS 15.3.1. Thanks in advance for any light you can shed on this issue, and please let me know if I can provide additional details.
Solution 1:[1]
I finally figured it out. The dyld linker found a symbol with a matching signature in a different dylib and blithely used that one instead of the one I had modified. I discovered it by renaming start_stream to xstart_stream, and then rebuilding the first dylib, expecting to get a dyld error when I tried to run my app, but no such error occurred. The macOS target ran without error, but also without the BLOOP message. So I dug around using the nm -g command and uncovered the other dylib with the matching signature. I removed that other dylib from my frameworks, et voila: dyld error!
Sources
This article follows the attribution requirements of Stack Overflow and is licensed under CC BY-SA 3.0.
Source: Stack Overflow
| Solution | Source |
|---|---|
| Solution 1 | Scott T. Miller |
