Compiling – Correct Syntax to Add CFLAGS and LDFLAGS to ‘configure’

compilingconfigure

I wish to install OpenVPN on OpenBSD 5.5 using OpenVPN source tarball.

According to the instructions here, I have to install lzo and

add CFLAGS="-I/usr/local/include" LDFLAGS="-L/usr/local/lib"
directives to "configure", since gcc will not find them otherwise.

I have googled extensively for guide on how to do the above on OpenBSD but there is none.

This is what I plan to do:

  1. Untar the source tarball to a freshly created directory
  2. Issue the command
    ./configure CFLAGS="-I/usr/local/include" LDFLAGS="-L/usr/local/lib"
    
  3. Issue the command make
  4. Issue the command make install

Which of the following syntax is correct?

./configure CFLAGS="-I/usr/local/include" LDFLAGS="-L/usr/local/lib"

or

./configure --CFLAGS="-I/usr/local/include" LDFLAGS="-L/usr/local/lib"

or

./configure --CFLAGS="-I/usr/local/include" --LDFLAGS="-L/usr/local/lib"

Best Answer

The correct way is:

./configure CFLAGS="-I/usr/local/include" LDFLAGS="-L/usr/local/lib"

but this may not work with all configure scripts. It's probably better to set environment variables such as CPATH and LIBRARY_PATH (see gcc man page).

An example:

export CPATH=/usr/local/include
export LIBRARY_PATH=/usr/local/lib
export LD_LIBRARY_PATH=/usr/local/lib

in your .profile, for instance. The LD_LIBRARY_PATH can be needed in case of shared libraries if a run path is not used (this depends on the OS, the build tools and the options that are used, but it shouldn't hurt).

Related Question