[swift-build-dev] swift test undefined reference error

Daniel Dunbar daniel_dunbar at apple.com
Tue May 24 10:47:18 CDT 2016


Currently your Tests subdirectory needs to be named WindFarmIRR, which is not something we do a good job of diagnosing. I filed:
  https://bugs.swift.org/browse/SR-1607
to track fixing this.

 - Daniel

> On May 24, 2016, at 7:05 AM, G J via swift-build-dev <swift-build-dev at swift.org> wrote:
> 
> I am attempting to use unit tests on a swift project in linux with Swift DEVELOPMENT.SNAPSHOT.2016.05.09.a.
> 
> The executable is built in a module named WindFarmIRR with directory structure:
> 
> Package.swift
> Sources (D)
>       main.swift
>       irr.swift
>       stringHelpers.swift
> Tests (D)
>       LinuxMain.swift
>       WindFarmIRRTests (D)
>              WindFarmIRRTests.swift
> 
> 
> my test file, WindFarmIRRTests.swift, includes a line to import the WindFarmIRR module:    @testable import WindFarmIRR.
> 
> I am able to build the module successfully.   When I run swift test, however, the build fails with an 'undefined reference to' error.   Sample output is:   
> 
> swift test
> Compile Swift Module 'WindFarmIRRTestsTestSuite' (1 sources)
> Linking .build/debug/WindFarmIRRTests.xctest
> /home/greg/Dropbox/common_files/Programming/Swift/commercial/WindFutureLLC/WindFarmIRR/linux/WindFarmIRR-SwiftPM/.build/debug/WindFarmIRRTestsTestSuite.build/WindFarmIRRTests.swift.o: In function `_TFC25WindFarmIRRTestsTestSuite16WindFarmIRRTests26testCashFlowStructCashFlowfT_T_':
> /home/greg/Dropbox/common_files/Programming/Swift/commercial/WindFutureLLC/WindFarmIRR/linux/WindFarmIRR-SwiftPM/Tests/WindFarmIRRTests/WindFarmIRRTests.swift:19: undefined reference to `_TFV11WindFarmIRR8CashFlowCfT_S0_'
> /home/greg/Dropbox/common_files/Programming/Swift/commercial/WindFutureLLC/WindFarmIRR/linux/WindFarmIRR-SwiftPM/.build/debug/WindFarmIRRTestsTestSuite.build/WindFarmIRRTests.swift.o: In function `_TFFC25WindFarmIRRTestsTestSuite16WindFarmIRRTests26testCashFlowStructCashFlowFT_T_u_KzT_GSqSd_':
> /home/greg/Dropbox/common_files/Programming/Swift/commercial/WindFutureLLC/WindFarmIRR/linux/WindFarmIRR-SwiftPM/Tests/WindFarmIRRTests/WindFarmIRRTests.swift:26: undefined reference to `_TFV11WindFarmIRR8CashFlow8cashFlowfT_Sd'
> clang-3.8: error: linker command failed with exit code 1 (use -v to see invocation)
> <unknown>:0: error: link command failed with exit code 1 (use -v to see invocation)
> <unknown>:0: error: build had 1 command failures
> error: exit(1): /usr/bin/swift-build-tool -f /home/greg/Dropbox/common_files/Programming/Swift/commercial/WindFutureLLC/WindFarmIRR/linux/WindFarmIRR-SwiftPM/.build/debug.yaml test
> 
> Text of LinuxMain.swift is:
> ------------------
> import XCTest
> 
> @testable import WindFarmIRRTestsTestSuite
> 
> XCTMain([
>     testCase(WindFarmIRRTests.allTests)
> ])
> -------------------
> 
> Text of WindFarmIRRTests.swift is:
> --------------------
> #if os(Linux)
> extension WindFarmIRRTests {
>      static var allTests : [(String, (WindFarmIRRTests) -> () throws -> Void)] {
>         return [
>             ("testCashFlowStructCashFlow", testCashFlowStructCashFlow)
>         ]
>     }
> }
> #endif
> 
> import XCTest
> @testable import WindFarmIRR
> 
> class WindFarmIRRTests: XCTestCase {
> 
>         
>     func testCashFlowStructCashFlow(){
> 
>         var cf = CashFlow()
>         cf.electricitySaleIncome = 100
>         cf.capitalCosts = 0
>         cf.oAndMCosts = 0
>         cf.transmissionCosts = 0
> 
>         
>         XCTAssertEqual(cf.cashFlow(),100)
>         
>         
>     }
> 
> }
> ---------------------------
> 
> 
> The problem appears to be that the linker cannot find the executable module to resolve the relevant symbols.
> 
> I would appreciate suggestions on what I am missing in the setup.
> 
> 
> Thanks
> 
> _______________________________________________
> swift-build-dev mailing list
> swift-build-dev at swift.org
> https://lists.swift.org/mailman/listinfo/swift-build-dev



More information about the swift-build-dev mailing list