What is the correct syntax to add CFLAGS and LDFLAGS to “configure”?

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"

Answers:

Thank you for visiting the Q&A section on Magenaut. Please note that all the answers may not help you solve the issue immediately. So please treat them as advisements. If you found the post helpful (or not), leave a comment & I’ll get back to you as soon as possible.

Method 1

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).

Method 2

The first syntax is correct.

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

However, it is strongly recommended to either use binary packages(7) or, if for whatever reason you absolutely need to build from source, make use of the ports(7) infrastructure, as explained by the FAQ section 15.

Set up the ports tree as detailed in the FAQ. Then look for an openvpn port:

cd /usr/ports
make search key=openvpn

This will output a number of ports containing the term openvpn. One of them is openvpn-2.3.2 with path net/openvpn.

cd net/openvpn
sudo make install clean

This will have the benefit that the dependencies (here only lzo2) will be properly installed without clobbering your system and you will get additional instructions on how to use openvpn on OpenBSD.

Method 3

It completely depends on the configure script. If the configure script was generated by autoconf, then the “correct” way to ensure that /usr/local/lib and /usr/local/include are used in the build is to use CONFIG_SITE. That is, either make it global for all you configure invocations by defining CONFIG_SITE in your shell startup files and doing:

cat > $CONFIG_SITE << EOF
CFLAGS="-I/usr/local/include $CFLAGS"
LDFLAGS="-L/usr/local/lib $LDFLAGS"
EOF

or set it only for those configure invocations that use /usr/local as their prefix by adding the above content to /usr/local/etc/config.site. Any invocation of configure that uses --prefix=/usr/local will read /usr/local/etc/config.site (or /usr/local/share/config.site, if you prefer to use that path). Since the default prefix is /usr/local, creating /usr/local/etc/config.site will cause the assignment to be made for any invocation of configure that does not otherwise define a prefix.

Again, note that this is only if the configure script was generated by autoconf.

Method 4

./configure CFLAGS="-I/usr/include/libxml2/"

doesn’t work for my configure

In the source tree i have seen a Config

Added CFLAGS there, as

./configure
echo "CFLAGS=${PKG_CFLAGS}" >> Config
make

worked

Method 5

If you have a “./configure” to run previously to make you can do:
./configure CFLAGS="-I/usr/include/libxml2/"


All methods was sourced from stackoverflow.com or stackexchange.com, is licensed under cc by-sa 2.5, cc by-sa 3.0 and cc by-sa 4.0

0 0 votes
Article Rating
Subscribe
Notify of
guest

0 Comments
Oldest
Newest Most Voted
Inline Feedbacks
View all comments
0
Would love your thoughts, please comment.x
()
x