Difference between revisions of "How to compile other software using Macports libraries"
(New page: TODO: How to compile other software using Macports libraries Audience: Beginner Introduction This document will attempt to illustrate how to use Macports to fulfill library dependencies ...) |
|||
| Line 1: | Line 1: | ||
| − | + | =How to compile other software using Macports libraries= | |
| − | Audience: Beginner | + | Audience: Beginner / Intermediate |
| − | Introduction | + | ==Introduction== |
This document will attempt to illustrate how to use Macports to fulfill library dependencies of other software that has not been incorporated into Macports. Two examples will be covered here, representing two of the most common way that software is compiled. The first example will demonstrate how to compile a single C source file using gcc directly, linking and including the Macports libraries via the -L and -I gcc command line options. The second example will demonstrate how to link against Macports libraries when compiling software that uses the GNU autoconf system, in which case you do not run gcc directly, but instead pass arguments to the 'configure' script. | This document will attempt to illustrate how to use Macports to fulfill library dependencies of other software that has not been incorporated into Macports. Two examples will be covered here, representing two of the most common way that software is compiled. The first example will demonstrate how to compile a single C source file using gcc directly, linking and including the Macports libraries via the -L and -I gcc command line options. The second example will demonstrate how to link against Macports libraries when compiling software that uses the GNU autoconf system, in which case you do not run gcc directly, but instead pass arguments to the 'configure' script. | ||
| + | ==Executive Summary and Cheat Sheet== | ||
| − | + | When using gcc, usually you want to add the following to the list of gcc command line arguments: | |
| + | -I/opt/local/include -L/opt/local/lib | ||
| − | + | When using autoconf, you usually have a couple options: | |
| + | |||
| + | 1) populate the following environment variables with Macports paths, e.g. | ||
| + | |||
| + | export LDFLAGS='-L/opt/local/lib' | ||
| + | export CPPFLAGS='-I/opt/local/include' | ||
| + | export LD_LIBRARY_PATH=/opt/local/lib | ||
| + | export LD_INCLUDE_PATH=/opt/local/include | ||
| + | |||
| + | 2) Pass the required paths as arguments to the configure script. Most configure scripts have specific options for defining the location of dependent libraries; run ./configure --help to see a list of the available options. | ||
| + | |||
| + | ==Using Macports libraries with gcc== | ||
| + | |||
| + | In this first example, we will be compiling a simple program that exercises some basic functions of the GMP library, available here: http://gmplib.org/. Since gmp is available via Macports, begin by installing gmp: | ||
| + | |||
| + | sudo port install gmp | ||
| + | |||
| + | Next, we'll make a working directory and download the C source file we'll be compiling, located at http://silassewell.googlecode.com/svn/trunk/2008/10/18/gmp_hello_world/gmp_hello_world.c | ||
| + | |||
| + | mkdir ~/gmp-test | ||
| + | curl -O | ||
| + | |||
| + | Copy the code | ||
Configuration | Configuration | ||
Latest revision as of 16:05, 16 July 2009
Contents
How to compile other software using Macports libraries
Audience: Beginner / Intermediate
Introduction
This document will attempt to illustrate how to use Macports to fulfill library dependencies of other software that has not been incorporated into Macports. Two examples will be covered here, representing two of the most common way that software is compiled. The first example will demonstrate how to compile a single C source file using gcc directly, linking and including the Macports libraries via the -L and -I gcc command line options. The second example will demonstrate how to link against Macports libraries when compiling software that uses the GNU autoconf system, in which case you do not run gcc directly, but instead pass arguments to the 'configure' script.
Executive Summary and Cheat Sheet
When using gcc, usually you want to add the following to the list of gcc command line arguments:
-I/opt/local/include -L/opt/local/lib
When using autoconf, you usually have a couple options:
1) populate the following environment variables with Macports paths, e.g.
export LDFLAGS='-L/opt/local/lib' export CPPFLAGS='-I/opt/local/include' export LD_LIBRARY_PATH=/opt/local/lib export LD_INCLUDE_PATH=/opt/local/include
2) Pass the required paths as arguments to the configure script. Most configure scripts have specific options for defining the location of dependent libraries; run ./configure --help to see a list of the available options.
Using Macports libraries with gcc
In this first example, we will be compiling a simple program that exercises some basic functions of the GMP library, available here: http://gmplib.org/. Since gmp is available via Macports, begin by installing gmp:
sudo port install gmp
Next, we'll make a working directory and download the C source file we'll be compiling, located at http://silassewell.googlecode.com/svn/trunk/2008/10/18/gmp_hello_world/gmp_hello_world.c
mkdir ~/gmp-test curl -O
Copy the code
Configuration
TODO
Optional Parts
TODO: What else can be done?