Skip to content

Build under Windows #13

@pultar

Description

@pultar

Hi, I wanted to build the example projects under Windows 11, Swift 5.10, installation of the toolchain via WinGet following instructions on swift.org.

Swift version 5.10 (swift-5.10-RELEASE)
Target: x86_64-unknown-windows-msvc

When I want to build 3_bidirectional_cxx_interop using

cmake -S . -B build -GNinja
cmake --build build

I get:

-- The CXX compiler identification is Clang 16.0.0 with GNU-like command-line
-- The Swift compiler identification is Apple 5.10
-- Detecting CXX compiler ABI info
-- Detecting CXX compiler ABI info - done
-- Check for working CXX compiler: C:/Users/fpultar/AppData/Local/Programs/Swift/Toolchains/5.10.0+Asserts/usr/bin/clang++.exe - skipped
-- Detecting CXX compile features
-- Detecting CXX compile features - done
-- Check for working Swift compiler: C:/Users/fpultar/AppData/Local/Programs/Swift/Toolchains/5.10.0+Asserts/usr/bin/swiftc.exe
-- Check for working Swift compiler: C:/Users/fpultar/AppData/Local/Programs/Swift/Toolchains/5.10.0+Asserts/usr/bin/swiftc.exe - works
-- Configuring done (4.6s)
-- Generating done (0.0s)
-- Build files have been written to: C:/Users/fpultar/source/repos/test-fxp/swift-cmake-examples/3_bidirectional_cxx_interop/build

and

[4/6] Linking Swift static library lib\fibonacci\fibonacci.lib
FAILED: lib/fibonacci/fibonacci.lib lib/fibonacci/CMakeFiles/fibonacci.dir/fibonacci.swift.obj lib/fibonacci/SwiftFibonacci.swiftmodule
C:\Windows\system32\cmd.exe /C "cd . && C:\Users\fpultar\AppData\Local\Programs\Swift\Toolchains\5.10.0+Asserts\usr\bin\swiftc.exe -j 32 -num-threads 32 -emit-library -static -o lib\fibonacci\fibonacci.lib -module-name SwiftFibonacci -module-link-name fibonacci -emit-module -emit-module-path lib\fibonacci\SwiftFibonacci.swiftmodule -emit-dependencies  -Onone -g -incremental -libc MDd -cxx-interoperability-mode=default -output-file-map lib\fibonacci\CMakeFiles\fibonacci.dir\Debug\output-file-map.json -I C:/Users/fpultar/source/repos/test-fxp/swift-cmake-examples/3_bidirectional_cxx_interop/include -I C:/Users/fpultar/source/repos/test-fxp/swift-cmake-examples/3_bidirectional_cxx_interop/build/lib/fibonacci/include C:\Users\fpultar\source\repos\test-fxp\swift-cmake-examples\3_bidirectional_cxx_interop\lib\fibonacci\fibonacci.swift lib\fibonacci\CMakeFiles\fibonacci.dir\fibonacci.cpp.obj    && cd ."
error: unableToFind(tool: "link")
ninja: build stopped: subcommand failed.

I get similar errors for 2_executable_library.

Forcing building shared libraries (cmake -S . -B build -GNinja -DBUILD_SHARED_LIBS=TRUE) resolves the problem for 2_executable_library but 3_bidirectional_cxx_interop fails with:

[4/6] Linking Swift shared library lib\fibonacci\fibonacci.dll
FAILED: lib/fibonacci/fibonacci.dll lib/fibonacci/CMakeFiles/fibonacci.dir/fibonacci.swift.obj lib/fibonacci/SwiftFibonacci.swiftmodule lib/fibonacci/fibonacci.lib
C:\Windows\system32\cmd.exe /C "cd . && C:\Users\fpultar\AppData\Local\Programs\Swift\Toolchains\5.10.0+Asserts\usr\bin\swiftc.exe -j 32 -num-threads 32 -emit-library -o lib\fibonacci\fibonacci.dll -module-name SwiftFibonacci -module-link-name fibonacci -emit-module -emit-module-path lib\fibonacci\SwiftFibonacci.swiftmodule -emit-dependencies -Dfibonacci_EXPORTS -Onone -g -incremental -libc MDd -cxx-interoperability-mode=default -output-file-map lib\fibonacci\CMakeFiles\fibonacci.dir\Debug\output-file-map.json -I C:/Users/fpultar/source/repos/test-fxp/swift-cmake-examples/3_bidirectional_cxx_interop/include -I C:/Users/fpultar/source/repos/test-fxp/swift-cmake-examples/3_bidirectional_cxx_interop/build/lib/fibonacci/include C:\Users\fpultar\source\repos\test-fxp\swift-cmake-examples\3_bidirectional_cxx_interop\lib\fibonacci\fibonacci.swift lib\fibonacci\CMakeFiles\fibonacci.dir\fibonacci.cpp.obj C:\Users\fpultar\AppData\Local\Programs\Swift\Platforms\5.10.0\Windows.platform\Developer\SDKs\Windows.sdk\/usr/lib/swift/windows/x86_64/swiftrt.obj   -Xlinker -implib:lib\fibonacci\fibonacci.lib -L C:/Users/fpultar/AppData/Local/Programs/Swift/Toolchains/5.10.0+Asserts/usr/lib/swift/windows   -L C:/Users/fpultar/AppData/Local/Programs/Swift/Toolchains/5.10.0+Asserts/usr/lib/swift/windows/x86_64  && cd ."
error: link command failed with exit code 1319 (use -v to see invocation)
fibonacci.cpp.obj : error LNK2038: mismatch detected for '_ITERATOR_DEBUG_LEVEL': value '2' doesn't match value '0' in swiftrt.obj
fibonacci.cpp.obj : error LNK2038: mismatch detected for 'RuntimeLibrary': value 'MDd_DynamicDebug' doesn't match value 'MD_DynamicRelease' in swiftrt.obj
C:\Users\fpultar\AppData\Local\Programs\Swift\Platforms\5.10.0\Windows.platform\Developer\SDKs\Windows.sdk\\usr\lib\swift\windows\x86_64\swiftrt.obj : warning LNK4042: object specified more than once; extras ignored
   Creating library lib\fibonacci\fibonacci.lib and object lib\fibonacci\fibonacci.exp
LINK : warning LNK4098: defaultlib 'msvcrtd.lib' conflicts with use of other libs; use /NODEFAULTLIB:library
lib\fibonacci\fibonacci.dll : fatal error LNK1319: 2 mismatches detected
clang: error: linker command failed with exit code 1319 (use -v to see invocation)
error: fatalError
ninja: build stopped: subcommand failed.

Do you have any suggestions what could be the issue? I understand that these examples should all work under Windows so I am assuming something might be off with my dev setup.

Best,
Felix

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