Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

[SR-13651] Linker error while linking unit test cases #4493

Closed
swift-ci opened this issue Oct 3, 2020 · 3 comments
Closed

[SR-13651] Linker error while linking unit test cases #4493

swift-ci opened this issue Oct 3, 2020 · 3 comments
Labels

Comments

@swift-ci
Copy link
Contributor

swift-ci commented Oct 3, 2020

Previous ID SR-13651
Radar rdar://problem/69942433
Original Reporter santman (JIRA User)
Type Bug
Status Resolved
Resolution Invalid
Additional Detail from JIRA
Votes 0
Component/s Package Manager
Labels Bug
Assignee None
Priority Medium

md5: f8dac577e81da680c48fd00de4a149a0

relates to:

  • SR-1393 [SwiftPM] Enforce Swift module import dependencies

Issue Description:

There seems to be a bug while linking a unit test case.
You can easily reproduce the issue by cloning this repo.

This issue has been discussed in the swift forum.

// main.swift
public struct myNumber<T: Numeric> { 
   var num:T = .zero
   public init(_ n:T) { 
       self.num = n
   }
}

let v = myNumber.init(5)
print(v.num)

Here is the unit test case for the same

import XCTest
@testable import swiftNumber
final class swiftNumberTests: XCTestCase {
 func testNum() {
 let v = myNumber.init(1)
 XCTAssertEqual(1, v.num)
 }
}

Here is the linker error

swiftNumberTests.swift:8: error: undefined reference to '$s11swiftNumber02myB0V3numACyxGx_tcfC'
clang-10: error: linker command failed with exit code 1 (use -v to see invocation)

You can also find the detailed logs here.

@typesanitizer
Copy link

@swift-ci create

@CodaFi
Copy link
Member

CodaFi commented Oct 13, 2020

The configuration of this package is such that an executable target is a dependency of a test target. SwiftPM will allow you to set up this relationship to ensure that the executable target gets built before the test suite, but you cannot consume the resulting executable as a library. Please convert the `swiftNumber` target into a library (by removing or renaming `main.swift`) to link with it.

@CodaFi
Copy link
Member

CodaFi commented Oct 13, 2020

I'm resolving this because it is behaving as intended. I wish we could provide some better ergonomics here for the end user to eliminate this source - I've linked a separate ticket that does just that.

@swift-ci swift-ci transferred this issue from apple/swift-issues Apr 25, 2022
@shahmishal shahmishal transferred this issue from apple/swift May 4, 2022
This issue was closed.
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
Projects
None yet
Development

No branches or pull requests

3 participants