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

G J fishpesce at gmail.com
Tue May 24 12:56:01 CDT 2016


Hi Daniel

I just found the bug report [SR-1503] on the new issue I reported
('multiple definition of main').   I'll follow the progress on that.  But
otherwise the directory structure fix seems to have worked.

Thanks
Greg

On Tue, May 24, 2016 at 1:28 PM, G J <fishpesce at gmail.com> wrote:

> Hi Daniel
>
> Thanks for filing the bug.  I fixed the directory structure per your
> comments.
>
> Package.swift (with module name WindFarmIRR)
> Sources
> Sources/main.swift
> Sources/.....
> Tests
> Tests/LinuxMain.swift
> Tests/WindFarmIRR
> Tests/WIndFarmIRR/WindFarmIRRTests.swift
>
> in LinuxMain I have "@testable import WindFarmIRRTestSuite"
> in WindFarmIRRTests.swift I have "@testable import WindFarmIRR"
>
> but now I get an error referring to multiple definitions of 'main':
> ---------
> Linking .build/debug/WindFarmIRRTests.xctest
> /home/greg/Dropbox/common_files/Programming/Swift/commercial/WindFutureLLC/WindFarmIRR/linux/WindFarmIRR-SwiftPM/.build/debug/WindFarmIRR.build/main.swift.o:
> In function `main':
> /home/greg/Dropbox/common_files/Programming/Swift/commercial/WindFutureLLC/WindFarmIRR/linux/WindFarmIRR-SwiftPM/Sources/main.swift:(.text+0x0):
> multiple definition of `main'
> /tmp/LinuxMain-4748b9.o:/home/greg/Dropbox/common_files/Programming/Swift/commercial/WindFutureLLC/WindFarmIRR/linux/WindFarmIRR-SwiftPM/Tests/LinuxMain.swift:(.text+0x0):
> first defined here
> clang-3.8: error: linker command failed with exit code 1 (use -v to see
> invocation)
> ----------
>
> so as best I can piece this together, the executable WindFarmIRR module is
> now being found and its 'main' is in conflict with the entry point in
> LinuxMain.swift.  I suspect I still have something not quite right with the
> naming conventions and directory layout.
>
> I am on an up-to-date archlinux system, with packages clang-3.8.0-1 and
> swift-development-DEVELOPMENT.SNAPSHOT.2016.05.09.a-2 (from AUR)
>
>
>
> On Tue, May 24, 2016 at 11:47 AM, Daniel Dunbar <daniel_dunbar at apple.com>
> wrote:
>
>> 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
>>
>>
>
-------------- next part --------------
An HTML attachment was scrubbed...
URL: <https://lists.swift.org/pipermail/swift-build-dev/attachments/20160524/53cdfc61/attachment.html>


More information about the swift-build-dev mailing list