janstary / sox

resurrect SoX
Other
2 stars 1 forks source link

including opusfile header #69

Open janstary opened 3 weeks ago

janstary commented 3 weeks ago

libopusfile installs its header as opus/opusfile.h under the include dir. That means it ends up in the opus/ subdirectory along with the headers of the other opus libraries, namely libopus and libopusenc.

Now, opus/opusfile.h itself includes <opus_multistream.h>, a header file of libopus. Note the <angle> notation, as opposed to #include "opus_multistream.h" in e.g. opus/opus_projection.h of libopus itself.

The problem is that you cannot just #include <opus/opusfile.h> in your source and be done with it, because, at least with clang:

/usr/local/include/opus/opusfile.h:110:11: error: 'opus_multistream.h' file not
found with <angled> include; use "quotes" instead
# include <opus_multistream.h>
          ^~~~~~~~~~~~~~~~~~~~
          "opus_multistream.h"

For comparison, you don't have that problem with #include <opus/opus.h>, as that includes "opus_multistream.h", not <opus_multistream.h>.

A workaround is to add $INCDIR/opus to your include path (-I) and #include <opusfile.h> instead. Then <opus_multistream.h> is found, because it's in $INCDIR/opus too.

But that makes opusfile the odd one out: no other include file does that, so opusfile is the only one requiring this workaround.

/usr/local/include/opus/opus.h:#include "opus_types.h"
/usr/local/include/opus/opus.h:#include "opus_defines.h"
/usr/local/include/opus/opus_defines.h:#include "opus_types.h"
/usr/local/include/opus/opus_multistream.h:#include "opus.h"
/usr/local/include/opus/opus_projection.h:#include "opus_multistream.h"
/usr/local/include/opus/opus_types.h:#include <stdint.h>
/usr/local/include/opus/opus_types.h:#    include <_G_config.h>
/usr/local/include/opus/opus_types.h:#  include <sys/types.h>
/usr/local/include/opus/opus_types.h:#  include <sys/types.h>
/usr/local/include/opus/opus_types.h:#  include <inttypes.h>
/usr/local/include/opus/opusfile.h:# include <stdarg.h>
/usr/local/include/opus/opusfile.h:# include <stdio.h>
/usr/local/include/opus/opusfile.h:# include <ogg/ogg.h>
/usr/local/include/opus/opusfile.h:# include <opus_multistream.h>
janstary commented 3 weeks ago

Compare to what e.g. FLAC does: it also has an include subdir, but e.g. FLAC/metadata.h and all the other header files include "format.h", not <format.h>, and do the same with every other file.

So you can just #include FLAC/all.h in your source, as opposed to adding $INCDIR/FLAC to your -I path.