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

G J fishpesce at gmail.com
Tue May 24 09:05:48 CDT 2016


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
-------------- next part --------------
An HTML attachment was scrubbed...
URL: <https://lists.swift.org/pipermail/swift-build-dev/attachments/20160524/996fa30b/attachment.html>


More information about the swift-build-dev mailing list