Uploaded image for project: 'Swift'
  1. Swift
  2. SR-2465

[SwiftPM] Xcode project cannot use C language target with custom module map

    Details

      Description

      Xcode 8 beta 6 with 08-23

      COpenSSL from Perfect (https://github.com/PerfectlySoft/Perfect-COpenSSL) has the following module map:

      module COpenSSL {
          header "openssl.h"
          link "COpenSSL"
      }
      

      This builds great on macOS and Linux command lines.

      But when an Xcode project is generated, I get this error:

      ld: library not found for -lCOpenSSL for architecture x86_64
      clang: error: linker command failed with exit code 1 (use -v to see invocation)
      

      This fixes Xcode:

      Under Project > Build Settings > Library Search Paths, add:
      
      $(PROJECT_DIR)/**
      

      Changing the module map to create a framework also fixes Xcode without the need for the search path hack. But this change breaks macOS and Linux command line which seem to rely on shared libs.

      module COpenSSL {
          header "openssl.h"
          link framework "COpenSSL"
      }
      

      The change is just adding `framework` to the `link "COpenSSL"` line.

      With `framework` added, here are the build errors for macOS and Linux (Xcode works)

      Ubuntu 14.04

      Compile Swift Module 'HTTPExample' (2 sources)
      Linking ./.build/debug/SMTPExample
      /usr/bin/ld.gold: fatal error: -f/--auxiliary may not be used without -shared
      clang: 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): /home/qutheory/.swiftenv/versions/DEVELOPMENT-SNAPSHOT-2016-08-23-a/usr/bin/swift-build-tool -f /home/qutheory/vapor/engine/.build/debug.yaml
      qutheory@qutheory-2:~/vapor/engine$ 
      

      macOS El Cap

      Linking ./.build/debug/HTTPExample
      ld: framework not found COpenSSL for architecture x86_64
      <unknown>:0: error: link command failed with exit code 1 (use -v to see invocation)
      ld: framework not found COpenSSL for architecture x86_64
      <unknown>:0: error: link command failed with exit code 1 (use -v to see invocation)
      <unknown>:0: error: build had 2 command failures
      error: exit(1): /Library/Developer/Toolchains/swift-DEVELOPMENT-SNAPSHOT-2016-08-23-a.xctoolchain/usr/bin/swift-build-tool -f /Users/tanner/Developer/vapor/engine/.build/debug.yaml
      Gertrude:engine tanner$ 
      

      TL;DR

      `link ...` only works for command lines.
      `link framework ...` only works for Xcode.

        Attachments

          Issue Links

            Activity

              People

              • Assignee:
                tannernelson tanner0101
                Reporter:
                tannernelson tanner0101
              • Votes:
                1 Vote for this issue
                Watchers:
                4 Start watching this issue

                Dates

                • Created:
                  Updated:
                  Resolved: