12

How can I fix these OpenSSL / TLS issues I'm getting with Vapor 2? They are preventing me from compiling my project on the command line and in Xcode.

During SPM build:

note: you may be able to install ctls using your system-packager:

    brew install ctls

note: you may be able to install ctls using your system-packager:

    brew install openssl

Upon failure of SPM build:

Linking ./.build/debug/Run
ld: library not found for -lcrypto for architecture x86_64
<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): /Library/Developer/Toolchains/swift-3.1-DEVELOPMENT-SNAPSHOT-2017-03-07-a.xctoolchain/usr/bin/swift-build-tool -f /Users/tanner/Desktop/PackageConfig/.build/debug.yaml

Also in SPM:

<module-includes>:1:9: note: in file included from <module-includes>:1:
#import "shim.h"
        ^
/Users/tanner/Desktop/PackageConfigTwo/.build/checkouts/ctls.git-9210868160426949823/shim.h:4:10: error: 'openssl/conf.h' file not found
#include <openssl/conf.h>
         ^
/Users/tanner/Desktop/PackageConfigTwo/.build/checkouts/crypto.git-7980259129511365902/Sources/Crypto/Cipher/Cipher+Method.swift:1:8: error: could not build Objective-C module 'CTLS'
import CTLS
       ^

In Xcode:

/Users/tanner/PackageConfig/.build/checkouts/ctls.git-9210868160426949823/shim.h:4:10: 'openssl/conf.h' file not found

/Users/tanner/PackageConfig/.build/checkouts/crypto.git-7980259129511365902/Sources/Crypto/Cipher/Cipher+Method.swift:1:8: Could not build Objective-C module 'CTLS'

ld: library not found for -lssl

Xcode Failing with CTLS issues

tanner0101
  • 4,005
  • 19
  • 33

2 Answers2

16

This error means OpenSSL is either not installed or not being properly linked. There are three solutions to this problem.

Option 1: Use Vapor Toolbox (Recommended)

Install the latest version of the Vapor toolbox.

If you have already installed the toolbox, try uninstalling it first:

which vapor
rm -rf /path/to/vapor

1.1 Install (macOS)

Add Vapor's Homebrew Tap

brew tap vapor/homebrew-tap

Update Homebrew and install the toolbox.

brew update
brew install vapor

1.2 Install (Ubuntu)

Add Vapor's APT repo.

Quick Script

eval "$(curl -sL https://apt.vapor.sh)"

Manual

wget -q https://repo.vapor.codes/apt/keyring.gpg -O- | sudo apt-key add -
echo "deb https://repo.vapor.codes/apt $(lsb_release -sc) main" | sudo tee /etc/apt/sources.list.d/vapor.list

Install

sudo apt-get update
sudo apt-get install vapor

1.3 Done

You should now have access to the vapor program and all required dependencies should be installed.

vapor build
vapor xcode

swift build and related commands should now also work normally.

swift build
swift package generate-xcodeproj

Option 2: Install Vapor's CTLS Package

2.1 Install (macOS)

Add Vapor's Homebrew Tap

brew tap vapor/homebrew-tap

Update Homebrew and install CTLS

brew update
brew install ctls

Restart your terminal, re-generate your Xcode project (if using Xcode), and try again.

2.2 Install (Ubuntu)

Add Vapor's APT repo.

Quick Script

eval "$(curl -sL https://apt.vapor.sh)"

Manual

wget -q https://repo.vapor.codes/apt/keyring.gpg -O- | sudo apt-key add -
echo "deb https://repo.vapor.codes/apt $(lsb_release -sc) main" | sudo tee /etc/apt/sources.list.d/vapor.list

Update APT and install CTLS.

sudo apt-get update
sudo apt-get install ctls

2.3 Done

swift build and other commands should now work normally.

Option 3: Manually Install and Link OpenSSL or Equivalent

3.1 Install (macOS)

Install OpenSSL (or any other similar SSL library)

brew install openssl
brew install libressl

3.2 Install (Ubuntu)

Install OpenSSL (or any other similar SSL library)

sudo apt-get install libssl-dev

3.3 Finding Linker Flags

You can use pkg-config (available on brew and apt) to find linker flags or most packages.

pkg-config <package-name> --cflags
pkg-config <package-name> --libs

However, OpenSSL installed through Homebrew cannot be linked and thus does not work with pkg-config. These flags should work:

include: /usr/local/opt/openssl/include
libs: /usr/local/opt/openssl/lib

Note, some libraries will be installed into /usr/include and /usr/lib which does not require explicit linker flags. OpenSSL through APT is installed this way.

3.4 Using Linker Flags

Linker flags can be added during swift build

swift build -Xswiftc -I/path/to/include -Xlinker -L/path/to/lib

They can also be added during Xcode project generation.

swift package -Xswiftc -I/path/to/include -Xlinker -L/path/to/lib generate-xcodeproj
Community
  • 1
  • 1
tanner0101
  • 4,005
  • 19
  • 33
  • 2
    Since you brought HomeBrew into it... Also see [Homebrew refusing to link OpenSSL](http://stackoverflow.com/q/38670295), [Update OpenSSL on OS X with Homebrew](http://stackoverflow.com/q/15185661), [How to install latest version of openssl Mac OS X El Capitan](http://stackoverflow.com/q/35129977), [How to upgrade OpenSSL in OS X?](http://apple.stackexchange.com/q/126830), [Openssl installation using HomeBrew fails](http://superuser.com/q/486389), etc. – jww Mar 29 '17 at 21:01
0

@tanner0101 your suggestions here https://github.com/vapor/vapor/issues/937 have not resolved the issue for me. I get the CTLS is missing error not only on High Sierra but also on Ubuntu inside a Docker container.

The project is manually executable but MySQL does not work. I think that this https://github.com/vapor/vapor/issues/954 and this https://github.com/uchicago-cloud/mpcs51033-2017-spring-forum/issues/54 are not just deployment on Heroku issues.

Lindemann
  • 3,336
  • 3
  • 29
  • 27