Skip to content

@main declaration within main.swift file makes build fail #658

@johnbute

Description

@johnbute

I am not entirely sure if this is a bug related to the native build system, or related to swift build:

For context, I have an executable target containing only a main.swift file with an @main attribute. With the native build system, this builds perfectly fine. However, whenever I remove the @main attribute, I get the following error message:

Undefined symbols for architecture arm64: "_PartsService_main", referenced from: _main in command-line-aliases-file ld: symbol(s) not found for architecture arm64 clang: error: linker command failed with exit code 1 (use -v to see invocation)

However, with SwiftBuild, I am capable of building my project when there is a main.swift file and no @main attribute.
Yet, whenever I do include the @main attribute, I get the following error message

'main' attribute cannot be used in a module that contains top-level code

Now, I am not exactly sure if this is a bug related to the native build system, or whether this is an issue where previous packages that build under the native build system should also be able to be built using swiftbuild. At the end of the day, there seems to be a difference in behaviour between the native and swift-build build systems

Metadata

Metadata

Assignees

No one assigned

    Labels

    No labels
    No labels

    Type

    No type

    Projects

    No projects

    Milestone

    No milestone

    Relationships

    None yet

    Development

    No branches or pull requests

    Issue actions