# Compiling and Installing OpenSC

This page has all the details on compiling and installing OpenSC. First some general instructions for Linux (and all unix operating systems not mentioned), and then the special cases for Solaris, Mac OS X and Windows.

First a small warning: do not use gcc 4.0.1/2, opensc will segfault. The backtraces we have show some stack corruption, and we haven't been able to isolate the issue yet. So in the meantime we can only ask you to use gcc 3.3 or 3.4, they work well, and we are not aware of any issue. Exception: the apple gcc 4.0 on Mac OS X is fine, so far no problem reports.

To compile OpenSC you need to have installed: pkg-config, openssl (runtime and development), openct and/or pcsc-lite (runtime and development), libltdl (runtime and development) and if you want the signer part: libassuan (runtime and development) and x libraries (runtime and development).

OpenSC tries to auto-detect all libraries using the pkg-config system. Most big software projects like KDE or Gnome use it already for a long time, so most users will have it installed.

Note: if you don't have libassuan installed, the signer won't be built. Most users and developers neither use nor need it. Also note the configure script does currently not properly check for x11 libraries and development files, it simply tries to build the signer if libassuan is found, and possibly fails, if x11 libs and development files are missing.

If you don't have pkg-config installed, and don't want to, you can use environment variables to tell configure, how to link with some library:

- OPENCT_CFLAGS and OPENCT_LIBS for OpenCT
- PCSC_CFLAGS and PCSC_LIBS for PC/SC-Lite
- OPENSSL_CFLAGS and OPENSSL_LIBS for OpenSSL
- ASSUAN_CFLAGS and ASSUAN_LIBS for Assuan

But most of the time it is easier to let pkg-config handle the automatic detection. If some libraries are not installed in typical locations, you need to tell pkg-config where to find the *.pc files. You can do this with the PKG_CONFIG_PATH environment variable, for example:

    export PKG_CONFIG_PATH=/usr/lib/pkgconfig:/usr/local/lib/pkgconfig:/opt/mystuff/liv/pkgconfig

## Typical Installation

But most users use whatever their linux distributions or other operating systems provide, and thus don't need any of this. We suggest to install OpenSC into /usr and to put the configfile into /etc. The default however would be /usr/local and /usr/local/etcc, so you might want to change those. We suggest to compile OpenSC like this:

    tar xfvz opensc-a.b.c.tar.gz
    cd opensc-a.b.c
    ./configure --prefix=/usr --sysconfdir=/etc
    make
    make install
    cp etc/opensc.conf /etc/

### OpenCT

By default configure script tries to locate openct automatically, this can be disabled by --disable-openct option.

### PC/SC-Lite

Most distributions will include pcsc-lite version 1.2.0. However if you want to use pinpad readers, at least those that support the new PC/SC v2 Part 10 standard for pinpad readers, then you need to have pcsc-lite 1.2.9-beta8 or later.

By default configure script tries to locate pcsc-lite automatically, this can be disabled by --disable-pcsc-lite option.

The configure script will tell you about this:

    checking for PCSC_CFLAGS... -I/usr/include/PCSC
    checking for PCSC_LIBS... -lpcsclite
    checking for reader.h... no
    configure: WARNING: reader.h not found, install pcsc-lite 1.2.9-beta8 or later, or use PCSC_CFLAGS=... ./configure

In this example pcsc-lite was found, but only an older version without support for the new PCSC v2 part 10 standard. This is fine, except for suport of modern pinpad readers.

## Mac OS X

Apple did not include pkg-config in Mac OS X, changed the pcsc-lite header files and includes a version of pcsc-lite that does not support the new PCSC v2 part 10 pinpad reader standard.

To compile OpenSC on Mac OS X we suggest:

    export OPENSSL_CFLAGS="-I/usr/include"
    export OPENSSL_LIBS="-L/usr/lib -lcrypto"
    tar xfvz opensc-a.b.c.tar.gz
    cd opensc-a.b.c
    ./configure --prefix=/usr --sysconfdir=/etc
    make
    make install
    cp etc/opensc.conf /etc/

## Microsoft Windows

if you have Visual Studio .NET installed already you need not download either of these.

- Download, install and use once Visual Studio Express.
- Download and install Microsoft Platform SDK.
- Download and install Active State Perl
- Download and install (runtime and development) LibTool libltdl3

To compile OpenSC:

1) Unpack the opensc-a.b.c.tar.gz

2) You need to edit the file `win32/Make.rules.mak` - Point the variable LIBLTDL_INCL = %LIBLTDL_HOME%\include - Point the variable LIBLTDL_LIB = %LIBLTDL_HOME%\lib\libltdl.lib Where LIBLTDL_HOME is where you installed LibTool?.

3) Set the variable OPENSSL_DEF = /DHAVE_OPENSSL -- if you wish to use OpenSSL (suggested) you can get it here - if you opted yes to use OpenSSL

-- Set OPENSSL_INCL_DIR=/I%OPENSSL_HOME\include\

-- Set OPENSSL_LIB=%OPENSSL_HOME\lib\VC\libeay32MD.lib

-- Set PROGRAMS_OPENSSL=pkcs15-init.exe cryptoflex-tool.exe netkey-tool.exe

- Alternatively, if your compiler seems to think that the above variables are actually input file arguments, you can comment them out and install them as environment variables. If someone knows why this might happen, please clear up this point.

4) In some versions of Visual Studio .NET you MAY have to make a change to \opensc-a.b.b\src\include\opensc\log.h to solve a minor compiling error. You need to replace `__FUNCTION__` by `__SCFUNCTION__`. In 7.1 (.NET 2003) this was NOT necessary

5) Unconfirmed is if you are using Mircrosoft Visual Sudio .NET development environment, you need to copy three files from Visual Studio .NET, namely afxres.h, winres.h and afsxres.rx, to \opensc-a.b.b\src\include sub-directory before compiling. This is unverified but being left incase you have wierd issues

6) Compiling OpenSC is done with

- The Visual Studio Command Prompt or

-- Alternatively with the regular command prompt (cmd). But, you MUST runs vcvars32.bat. This should already be in your path. If not, check your Platform SDK or .NET bin directory

    cd opensc-a.b.c
    nmake /f Makefile.mak

Configuration instructions for building inside of the IDE directly are coming.

### Attachments

- Make.rules.mak (1.6 KB) - added by wiredland@… 4 years ago. Sample of `opensc-0.10.0\win32\Make.rules.mak`