Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

openssl / ctls trouble with vapor 2

Tags:

ssl

openssl

vapor

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

like image 778
tanner0101 Avatar asked Mar 28 '17 13:03

tanner0101


1 Answers

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
like image 93
tanner0101 Avatar answered Oct 21 '22 03:10

tanner0101