Skip to content

Building

Joachim Metz edited this page Dec 27, 2022 · 11 revisions

Read first

GitHub will offer you the download options "Source code (zip)" and "Source code (tar.gz)". These are copies of the source, as-is, in the git repository and not suited for distribution. Instead it is highly recommend to use the provided source distribution package, which contains all the necessary dependencies.

Introduction

The libcthreads source code can be build with different compilers:

Or directly packaged with different package managers:

Getting the source

Source distribution package

To retrieve the source distribution package go to the downloads page and download the file named:

libcthreads-alpha-<version>.tar.gz

To extract the source distribution package run:

tar xfv libcthreads-alpha-<version>.tar.gz

This will create the source directory:

libcthreads-<version>

Verification

The source distribution package can be verified with the corresponding .asc file:

gpg --verify libcthreads-alpha-<version>.tar.gz.asc libcthreads-alpha-<version>.tar.gz

Where the corresponding public key can be found on keyserver.ubuntu.com

A successful verification will look similar to:

gpg: Signature made Sun 01 Jan 2017 09:28:04 AM CET using RSA key ID 7AD0177E
gpg: lookup_hashtable failed: eof
gpg: Good signature from "Joachim Metz <joachim.metz@gmail.com>"
gpg: lookup_hashtable failed: eof
gpg: WARNING: This key is not certified with a trusted signature!
gpg:          There is no indication that the signature belongs to the owner.
Primary key fingerprint: 0ED9 020D A90D 3F6E 70BD  3945 D962 5E5D 7AD0 177E

An unsuccessful verification will look similar to:

gpg: Signature made Sun 01 Jan 2017 09:28:04 AM CET using RSA key ID 7AD0177E
gpg: lookup_hashtable failed: eof
gpg: BAD signature from "Joachim Metz <joachim.metz@gmail.com>"

Git

Note that the git repository holds the development version of the source code.

If you are not developing it is recommended that you download a source distribution package instead.

To retrieve the source from the git repository make sure to install:

  • git
  • aclocal
  • autoconf
  • automake
  • autopoint or gettextize
  • libtoolize
  • pkg-config

To download and prepare the source for building run:

git clone https://github.com/libyal/libcthreads.git
cd libcthreads/
./synclibs.sh
./autogen.sh

The source from the git repository will not work without synchronizing the library dependencies "./synclibs.sh" and having the autotools generate the necessary files "./autogen.sh".

Debian/Ubuntu

On Debian based Linux distributions such as Ubuntu install the following packages:

sudo apt install git autoconf automake autopoint libtool pkg-config

Fedora

On Fedora based Linux distributions install the following packages:

sudo dnf install git autoconf automake gettext-devel libtool pkg-config

macOS

On macOS the XCode command line tools no longer provide the autotools you can obtain them e.g. via MacPorts. Install the following packages:

sudo port install git autoconf automake gettext libtool pkgconfig

Microsoft Visual Studio

Since Microsoft Visual Studio does not come with a Unix shell or equivalent you'll need to use the Windows PowerShell scripts instead:

git clone https://github.com/libyal/libcthreads.git
cd libcthreads\
.\synclibs.ps1
.\autogen.ps1

Using GNU Compiler Collection (GCC)

Before you build the libcthreads source code using the GNU Compiler Collection (GCC) you'll need to have compilation and build tools installed.

  • On a Linux system make sure you have build-essential (Debian-based) or the Development Tools (RedHat-based) packages installed.
  • On a macOS system make sure you have XCode (with command line tools) or MacPorts (or equivalent) installed.

To build the libcthreads source code change into the source directory and run the following commands:

./configure
make

You can install the binaries that were build by running:

sudo make install

By default this will install the binaries in /usr/local. If you want to change this to e.g. /usr, add the configuration option --prefix=/usr, e.g.

./configure --prefix=/usr

On Linux make sure libcthreads.so is in the library cache. Normally it suffices to run:

sudo ldconfig

Static library

To make a static library add --enable-shared=no to configure, .e.g:

./configure --enable-shared=no

Cygwin

If you want to use Cygwin to build libcthreads make sure to have the following packages installed:

  • autoconf
  • automake
  • binutils
  • gcc-core
  • gcc-g++
  • gettext-devel
  • libiconv
  • libtool
  • make
  • pkg-config

After following the GNU Compiler Collection (GCC) build instructions you should end up with the following DLL:

libcthreads/.libs/cygcthreads-0.dll

Using the DLL

Make sure you use define LIBCTHREADS_DLL_IMPORT before including <libcthreads.h>.

To be able to use the DLL on other systems than the build system you'll also need to provide:

  • cygwin1.dll

macOS

libtoolize

If you find that libtoolize is missing use glibtoolize instead.

Sun Solaris

To build libcthreads on Sun Solaris make sure that /usr/ccs/bin and /usr/sfw/bin are defined in the PATH environment variable.

Using Minimalist GNU for Windows (MinGW)

To compile libcthreads using MinGW you'll need:

  • MinGW

To build use:

mingw32-configure --prefix=/opt/local/i386-mingw32 --enable-winapi=yes
mingw32-make

It is recommended that you use WINAPI support but it is possible to compile libcthreads without it (--enable-winapi=no). The default behavior is that configure will try to auto-detect MinGW and enable WINAPI support.

If mingw32-configure and mingw32-make are not available you can build it with:

./configure --host=i386-mingw32 --prefix=/opt/local/i386-mingw32 --enable-winapi=yes
make

If this does not work try a script similar to the following:

#!/bin/sh
CC=/opt/local/bin/i386-mingw32-gcc
CXX=/opt/local/bin/i386-mingw32-g++
AR=/opt/local/bin/i386-mingw32-ar
OBJDUMP=/opt/local/bin/i386-mingw32-objdump
RANLIB=/opt/local/bin/i386-mingw32-ranlib
STRIP=/opt/local/bin/i386-mingw32-strip
MINGWFLAGS="-mwin32 -mconsole -march=i586 "
CFLAGS="$MINGWFLAGS"
CXXFLAGS="$MINGWFLAGS"

CC=$CC CXX=$CXX AR=$AR OBJDUMP=$OBJDUMP RANLIB=$RANLIB STRIP=$STRIP ./configure --host=i586-mingw32msvc --prefix=/opt/local/i386-mingw32 --enable-winapi=yes
CC=$CC CXX=$CXX AR=$AR OBJDUMP=$OBJDUMP RANLIB=$RANLIB STRIP=$STRIP CFLAGS="$CFLAGS" CXXFLAGS="$CXXFLAGS" make

If you get compiler errors like:

#error WINAPI file open function for Windows 2000 or earlier NOT implemented yet

That means WINVER is not set or set to a version predating Windows XP (0x0501) and you'll have to set WINVER manually like:

CFLAGS=-DWINVER=0x0501 ./configure --host=i386-mingw32 --enable-winapi=yes

You should end up with the following DLL:

libcthreads/.libs/libcthreads-1.dll

To install libcthreads and tools in the MinGW build tree use:

sudo make install

Using the DLL

Make sure you use define LIBCTHREADS_DLL_IMPORT before including <libcthreads.h>.

To be able to use the DLL on other systems than the build system you'll also need to provide:

  • libgcc_s_dw2-1.dll (or equivalent)

Troubleshooting

While running make I get an error similar to the following:

libclocale_locale.c: In function 'libclocal_local_get_decimal_point':
libclocale_locale.c:357:2: warning implicit declaration of function 'GetLocaleInfoEx' [-Wimplicit-function-declaration]
libclocale_locale.c:358:7: error: 'LOCALE_NAME_USER_DEFAULT' undeclared (first use in this function)
libclocale_locale.c:358:7: note: each undeclared identifier is reported only once for every function it appears in

The version of MinGW does not support a WINAPI version of Vista or later (0x0600) try setting WINVER to 0x0501.

Using Microsoft Visual Studio

Before you build libcthreads using Microsoft Visual Studio you'll need to have it installed. The libcthreads packages comes with Microsoft Visual Studio files for version 2008. Version 2010 is able to convert these files into its newer versions.

The Microsoft Visual Studio express version is sufficient. Note that if you want to build 64-bit version with the express version you'll need at least 2010. Also see the section: Microsoft Visual Studio 2010 express and 64-bit compilation.

Note that if you want to build libcthreads from source checked out of git with Visual Studio make sure the autotools are able to make a distribution package of libcthreads before trying to build it. You can create distribution package by running: "make dist".

Building

Open the file:

msvscpp\libcthreads.sln

Note that the project files contain a Release and VSDebug configuration. The VSDebug builds the binaries with debug information. Note that this is not the same as debug output.

Make sure to check if your build environment defines the correct WINVER for your build. The code uses WINAPI version specific functions based on WINVER. You can define a custom WINVER in the Microsoft Visual Studio C++ project files or in common\config_winapi.h

And build the solution. The build files will be places in:

msvscpp\Release\

Using MSBuild

Another way to build libcthreads with Visual Studio is to use MSBuild via the command line. MSBuild can be installed as part of the Microsoft.NET Framework.

First set-up the Visual Studio variables:

C:\Program Files\Microsoft Visual Studio 9.0\VC\bin\vcvars32.bat

Next run MSBuild:

msbuild msvscpp\libcthreads.sln /p:Configuration=Release;Platform=Win32

Using the DLL

Make sure you use define LIBCTHREADS_DLL_IMPORT before including <libcthreads.h>.

To be able to use the DLL on other systems than the build system you'll also need to provide:

  • the Microsoft Visual C++ Run-Time DLL (part of the Visual C++ Redistributable package)

64-bit with Microsoft Visual Studio express

To build a 64-bit version of libcthreads with Microsoft Visual Studio express you'll need at least the 2010 version.

Microsoft Visual Studio express 2010 and later

First make sure to enabling 64-bit compilation support on Microsoft Visual Studio. For Visual Studio 2010 express this can be a tedious process, some relevant links:

If you have set up Visual Studio correctly the following should work:

Go to:

Configuration manager -> Active solution platform

Select "<New>"

  • Type or select the new platform: "x64"
  • Copy settings from: "Win32"
  • Create new project platforms: enabled

Additionally for every project change:

Configuration Properties -> General -> Platform Toolset

Into "Windows7.1SDK" or equivalent.

msvscpp-convert script

If you've Python installed on your Visual Studio build machine you can try running msvscpp-convert to convert the Visual Studio 2008 solution files to 2010 format and add the x64 settings for you with the option --extend-with-x64.

msvscpp-convert.py --extend-with-x64 --output-format 2010 msvscpp\libcthreads.sln

This will create a subdirectory named vs2010 which contains the Visual Studio 2010 solution files.

Using Debian package tools (DEB)

To build libcthreads using the Debian package tools make sure you have the following packages installed:

sudo apt install autotools-dev build-essential debhelper dh-autoreconf dh-python fakeroot pkg-config 

If you downloaded the source using git make sure to run ./configure at least once to generate the dpkg packaging files.

To build the Debian packages change into the source directory and run:

cp -rf dpkg debian
dpkg-buildpackage -rfakeroot

This will create the following files in the parent directory:

libcthreads_<version>-1_<arch>.deb
libcthreads-dev_<version>-1_<arch>.deb

To install, e.g. the library:

sudo dpkg -i libcthreads_<version>-1_<arch>.deb

Troubleshooting

dpkg-source: error: can't build with source format '3.0 (quilt)': no upstream tarball' found at ../libcthreads-<version>.orig.tar.{bz2,gz,lzma,xz}

This means dpkg-buildpackage cannot find the source distribution package. Make sure it is provided as:

../libcthreads-<version>.orig.tar.gz

Using RedHat package tools (RPM)

To build libcthreads using the RedHat package tools make sure you have the following packages installed:

dnf install rpm-build 

To build:

mv libcthreads-alpha-<version>.tar.gz libcthreads-<version>.tar.gz
rpmbuild -ta libcthreads-<version>.tar.gz

This will create the following files in the rpmbuild directory:

~/rpmbuild/RPMS/<arch>/libcthreads-<version>-1.<arch>.rpm
~/rpmbuild/RPMS/<arch>/libcthreads-devel-<version>-1.<arch>.rpm
~/rpmbuild/SRPMS/libcthreads-<version>-1.src.rpm

To install, e.g. the library:

sudo rpm -ivh libcthreads-<version>-1.<arch>.rpm

Using macOS pkgbuild

pkgbuild can be used to create a macOS package.

The following instructions show how to build libcthreads.pkg and libcthreads.dmg from the command line.

First build libcthreads:

./configure --prefix=/usr/local
make

For System Integrity Protection "/usr/local" is used instead of "/usr".

Next install the build files using DESTDIR

make install DESTDIR=$PWD/tmp

This will make sure that library paths in the dylib file is set correctly for distribution. This is not the case when you use:

./configure --prefix=$PWD/tmp

You can check the library paths in the dylib by running:

otool -LT tmp/usr/lib/libcthreads.1.dylib

After running "make install" the binaries are installed in:

$PWD/tmp/

If you are planning to distribute libcthreads.pkg make sure it contains a copy of LGPL license:

mkdir -p $PWD/tmp/usr/share/doc/libcthreads
cp AUTHORS COPYING COPYING.LESSER NEWS README $PWD/tmp/usr/share/doc/libcthreads

To create the package (directory):

pkgbuild --root $PWD/tmp --identifier com.github.libyal.libcthreads --version <version> --ownership recommended ../libcthreads-<version>.pkg

To create a distributable disk image:

hdiutil create ../libcthreads-<version>.dmg -srcfolder ../libcthreads-<version>.pkg -fs HFS+