Skip to content

Commit 1df1e19

Browse files
committed
Fix example build
1 parent 749eff5 commit 1df1e19

File tree

2 files changed

+20
-4
lines changed

2 files changed

+20
-4
lines changed

pkgs/objective_c/example/flutter_app/lib/main.dart

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -23,7 +23,7 @@ class _MainAppState extends State<MainApp> {
2323
void initState() {
2424
super.initState();
2525

26-
message = NSString('Hello World!').toString();
26+
message = NSString('Hello World!').toDartString();
2727
}
2828

2929
@override

pkgs/objective_c/hook/build.dart

Lines changed: 19 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -10,7 +10,9 @@ import 'package:logging/logging.dart';
1010
import 'package:native_toolchain_c/src/cbuilder/compiler_resolver.dart';
1111

1212
const objCFlags = ['-x', 'objective-c', '-fobjc-arc'];
13-
const cFlags = <String>[];
13+
14+
String sdkPath = firstLineOfStdout('xcrun', ['--show-sdk-path']);
15+
final cFlags = <String>['-isysroot', sdkPath];
1416

1517
const assetName = 'objective_c.dylib';
1618

@@ -106,8 +108,13 @@ class Builder {
106108
return output;
107109
}
108110

109-
Future<void> linkLib(List<String> objects, String output) =>
110-
_compile(['-shared', '-undefined', 'dynamic_lookup', ...objects], output);
111+
Future<void> linkLib(List<String> objects, String output) => _compile([
112+
'-shared',
113+
'-undefined',
114+
'dynamic_lookup',
115+
...cFlags,
116+
...objects,
117+
], output);
111118

112119
Future<void> _compile(List<String> flags, String output) async {
113120
final args = [...flags, '-o', output];
@@ -122,3 +129,12 @@ class Builder {
122129
logger.info('Generated $output');
123130
}
124131
}
132+
133+
String firstLineOfStdout(String cmd, List<String> args) {
134+
final result = Process.runSync(cmd, args);
135+
assert(result.exitCode == 0);
136+
return (result.stdout as String)
137+
.split('\n')
138+
.where((line) => line.isNotEmpty)
139+
.first;
140+
}

0 commit comments

Comments
 (0)