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"
    
  • vinc17

    vinc17 Correct answer

    6 years ago

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

    Thanks for your answer. Is gcc installed by default in the base system of OpenBSD 5.5? If it isn't I'm not going to install a third-party package as it may contain bugs or security vulnerabilities.

    @user66229 if you did a default install then yes, `gcc-4.2.1` (unless you're on really old machines like vaxen) is in `comp55.tgz`. There are packages for `gcc-4.8` and `4.9`, and also `llvm/clang 3.0`. The former aren't included mainly for licensing reasons (GPLv2 vs GPLv3), the latter isn't used because it doesn't support all the platforms that OpenBSD currently supports.

    @user66229 I've edited my answer. This is just an example, there may be other ways to do it, and you might already have some settings. Check first with `echo $CPATH` and so on.

    Thanks for the "but this may not work with all configure scripts" comment - I just ran into a case, where after several dependencies compiled with CFLAGS, the last dependency crashes when CFLAGS is specifies (and indeed, `grep CFLAGS configure` returns blank from that configure script).

    I would be very careful with `LD_LIBRARY_PATH`: http://xahlee.info/UnixResource_dir/_/ldpath.html.

    Setting the environment variables did not work for me. I had to set the flags on the command line. In my case, I was building Python 3.6.9 on macOS. Use this syntax to set many paths: `./configure CFLAGS="-I/usr/local/include -I/usr/local/include2" LDFLAGS="-L/usr/local/lib -L/usr/local/lib2"`

License under CC-BY-SA with attribution


Content dated before 6/26/2020 9:53 AM