Skip to content

Commit 3bfd362

Browse files
authored
No extern "C" main functions (#20223)
A user is reporting a build failure with top-of-tree Clang: https://discourse.llvm.org/t/build-error-of-iree-may-related-to-clang21/85090 > iree/tools/iree-check-module-main.cc:150:16: error: ‘main’ should not be ‘extern “C”’ [-Werror,-Wmain] Clang is correct: `main` really can't be `extern "C"`: https://eel.is/c++draft/basic.start#main-2 > Its type shall have C++ language linkage Anyway, what was the reason for `extern "C"` ? --------- Signed-off-by: Benoit Jacob <[email protected]>
1 parent db5b69a commit 3bfd362

File tree

6 files changed

+12
-8
lines changed

6 files changed

+12
-8
lines changed

runtime/src/iree/base/internal/flags.h

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -318,7 +318,7 @@ void iree_flags_set_usage(const char* program_name, const char* usage);
318318
// Returns <0 if parsing fails.
319319
//
320320
// Usage:
321-
// extern "C" int main(int argc, char** argv) {
321+
// int main(int argc, char** argv) {
322322
// iree_status_t status = iree_flags_parse(&argc, &argv);
323323
// if (!iree_status_is_ok(status)) { exit(1); }
324324
// consume_positional_args(argc, argv);

runtime/src/iree/task/executor_demo.cc

Lines changed: 3 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -37,7 +37,9 @@ static void simulate_work(const iree_task_tile_context_t* tile_context) {
3737
}
3838
}
3939

40-
extern "C" int main(int argc, char* argv[]) {
40+
} // namespace
41+
42+
int main(int argc, char* argv[]) {
4143
IREE_TRACE_APP_ENTER();
4244
IREE_TRACE_SCOPE_NAMED("ExecutorTest::Any");
4345

@@ -168,5 +170,3 @@ extern "C" int main(int argc, char* argv[]) {
168170
IREE_TRACE_APP_EXIT(0);
169171
return 0;
170172
}
171-
172-
} // namespace

runtime/src/iree/testing/gtest_main.cc

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -8,7 +8,7 @@
88
#include "iree/base/internal/flags.h"
99
#include "iree/testing/gtest.h"
1010

11-
extern "C" int main(int argc, char** argv) {
11+
int main(int argc, char** argv) {
1212
IREE_TRACE_APP_ENTER();
1313

1414
// Pass through flags to gtest (allowing --help to fall through).

runtime/src/iree/vm/bytecode/module_size_benchmark.cc

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -9,7 +9,7 @@
99
#include "iree/vm/bytecode/module.h"
1010
#include "iree/vm/bytecode/module_size_benchmark_module_c.h"
1111

12-
extern "C" int main(int argc, char** argv) {
12+
int main(int argc, char** argv) {
1313
iree_vm_instance_t* instance = nullptr;
1414
iree_vm_instance_create(IREE_VM_TYPE_CAPACITY_DEFAULT,
1515
iree_allocator_system(), &instance);

tools/iree-check-module-main.cc

Lines changed: 3 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -147,7 +147,7 @@ iree_status_t Run(iree_allocator_t host_allocator, int* out_exit_code) {
147147

148148
} // namespace
149149

150-
extern "C" int main(int argc, char** argv) {
150+
int main(int argc, char** argv) {
151151
IREE_TRACE_APP_ENTER();
152152

153153
// Pass through flags to gtest (allowing --help to fall through).
@@ -181,3 +181,5 @@ extern "C" int main(int argc, char** argv) {
181181
}
182182

183183
} // namespace iree
184+
185+
int main(int argc, char** argv) { return iree::main(argc, argv); }

tools/iree-run-mlir-main.cc

Lines changed: 3 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -452,7 +452,7 @@ class ArgParser {
452452

453453
} // namespace
454454

455-
extern "C" int main(int argc, char** argv) {
455+
int main(int argc, char** argv) {
456456
IREE_TRACE_APP_ENTER();
457457
IREE_TRACE_ZONE_BEGIN_NAMED(z0, "iree-run-mlir");
458458

@@ -533,3 +533,5 @@ extern "C" int main(int argc, char** argv) {
533533
}
534534

535535
} // namespace iree
536+
537+
int main(int argc, char** argv) { return iree::main(argc, argv); }

0 commit comments

Comments
 (0)