#350 Flac breaks asserts in code

1.3.0
closed-fixed
Erik
libFLAC (57)
5
2014-03-21
2009-05-26
Dirk
No

The following very simple example does not compile with: g++ flac.cpp -o flac `pkg-config --cflags flac++`

#include <cassert>
#include <FLAC++/decoder.h>

int main (int argc, char** argv)
{
assert(true);
return 0;
}

Compiler output: flac.cpp:6: error: ‘assert’ was not declared in this scope.
Now I know I can also compile this sample with g++ flac.cpp -o flac but this can break things if a distribution decides to put the headers in a nonstandard place.

Please rename assert.h in the FLAC include dir to flacassert.h or something.

Best regards,
Dirk

Discussion

  • I had the same problem. The problem is the pkg-config spec files (flac.pc and flac++.pc). They have:

    Cflags: -I${includedir}/FLAC

    and

    Cflags: -I${includedir}/FLAC++

    This add -I/usr/include/FLAC and -I/usr/include/FLAC++ to your compiler flags... and causes the collision with <assert.h> (compiler may resolve it to /usr/include/assert.h or, in your case, /usr/include/FLAC/assert.h). However, all FLAC includes should be things like <FLAC/foo.h>.

    The solution is to remove "/FLAC" and "/FLAC++" from Cflags -- and this appears to be fixed in the latest CVS.

     
  • If using pkg-config in a configure.ac script, the following workaround was suggested by Erik de Castro Lopo and works well:

    AC_PROG_SED

    PKG_CHECK_MODULES([FLAC], [flac])
    FLAC_CFLAGS=`echo $FLAC_CFLAGS | $SED "s/FLAC$//"`

    It would be cool if a new release could fix this as it's a bit confusing when assert() first stops compiling!

     
  • Erik
    Erik
    2014-03-21

    • status: open --> closed-fixed
    • assigned_to: Erik
    • Group: --> 1.3.0
     
  • Erik
    Erik
    2014-03-21

    This was fixed for the flac 1.3.0 release.