brglng / libwave

A simple C library for reading/writing PCM wave (.wav) files
Mozilla Public License 2.0
79 stars 20 forks source link

ninja build fails #3

Closed syslogic closed 5 years ago

syslogic commented 5 years ago

When I generate build-files and build in the shell, it seems to build fine - but in the IDE (with the same settings), it fails. I'm not certain if this isn't due to the manually supplied header files there.

wav.c:239:11: warning: implicit declaration of function 'wave_eof' is invalid in C99 [-Wimplicit-function-declaration]
            wave_eof(self) ) {
            ^
wav.c:307:27: warning: implicit declaration of function 'wave_get_num_channels' is invalid in C99 [-Wimplicit-function-declaration]
      uint16_t n_channels = wave_get_num_channels(wave);
                            ^
wav.c:308:26: warning: implicit declaration of function 'wave_get_sample_size' is invalid in C99 [-Wimplicit-function-declaration]
      size_t sample_size = wave_get_sample_size(wave);
                           ^
wav.c:323:18: warning: implicit declaration of function 'wave_get_length' is invalid in C99 [-Wimplicit-function-declaration]
      len_remain = wave_get_length(wave) - (size_t)wave_tell(wave);
                   ^
wav.c:323:50: warning: implicit declaration of function 'wave_tell' is invalid in C99 [-Wimplicit-function-declaration]
      len_remain = wave_get_length(wave) - (size_t)wave_tell(wave);
                                                   ^
wav.c:383:27: warning: implicit declaration of function 'wave_get_num_channels' is invalid in C99 [-Wimplicit-function-declaration]
      uint16_t n_channels = wave_get_num_channels(wave);
                            ^
wav.c:384:26: warning: implicit declaration of function 'wave_get_sample_size' is invalid in C99 [-Wimplicit-function-declaration]
      size_t sample_size = wave_get_sample_size(wave);
                           ^
wav.c:404:5: warning: implicit declaration of function 'wave_tell' is invalid in C99 [-Wimplicit-function-declaration]
      wave_tell(wave);
      ^
wav.c:462:10: error: conflicting types for 'wave_tell'
  long int wave_tell(WaveFile* wave)
           ^
wav.c:323:50: note: previous implicit declaration is here
      len_remain = wave_get_length(wave) - (size_t)wave_tell(wave);
                                                   ^
wav.c:472:20: warning: comparison of integers of different signs: 'long' and 'size_t' (aka 'unsigned int') [-Wsign-compare]
          assert(pos >= header_size);
                 ~~~ ^  ~~~~~~~~~~~
linux-x86_64/sysroot/usr/include/assert.h:51:23: note: expanded from macro 'assert'
  #  define assert(e) ((e) ? __assert_no_op : __assert2(__FILE__, __LINE__, __PRETTY_FUNCTION__, #e))
                        ^
wav.c:481:21: warning: implicit declaration of function 'wave_get_length' is invalid in C99 [-Wimplicit-function-declaration]
      size_t length = wave_get_length(wave);
                      ^
wav.c:490:31: warning: comparison of integers of different signs: 'long' and 'size_t' (aka 'unsigned int') [-Wsign-compare]
      if (offset >= 0 && offset <= length) {
                         ~~~~~~ ^  ~~~~~~
wav.c:516:28: warning: comparison of integers of different signs: 'long' and 'unsigned int' [-Wsign-compare]
             ftell(wave->fp) == wave_get_header_size(wave) + wave->chunk.data_chunk.size;
             ~~~~~~~~~~~~~~~ ^  ~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~
wav.c:697:10: error: conflicting types for 'wave_get_num_channels'
  uint16_t wave_get_num_channels(WaveFile* self)
           ^
wav.c:307:27: note: previous implicit declaration is here
      uint16_t n_channels = wave_get_num_channels(wave);
                            ^
wav.c:716:8: error: conflicting types for 'wave_get_sample_size'
  size_t wave_get_sample_size(WaveFile* self)
         ^
wav.c:308:26: note: previous implicit declaration is here
      size_t sample_size = wave_get_sample_size(wave);
                           ^
wav.c:721:8: error: conflicting types for 'wave_get_length'
  size_t wave_get_length(WaveFile* self)
         ^
wav.c:323:18: note: previous implicit declaration is here
      len_remain = wave_get_length(wave) - (size_t)wave_tell(wave);
                   ^
  12 warnings and 4 errors generated.
  ninja: build stopped: subcommand failed.
syslogic commented 5 years ago

after some review, I've also noticed that this part of wav_priv.h also is problematic:

#if defined(__i386__) || defined(_M_I86) || defined(_X86_) || defined(__amd64__) || defined(__x86_64__) || defined(_M_X64)
#define WAVE_ENDIAN_LITTLE
#endif

#ifdef WAVE_ENDIAN_LITTLE
#define WAVE_RIFF_CHUNK_ID          'FFIR'
#define WAVE_FORMAT_CHUNK_ID        ' tmf'
#define WAVE_FACT_CHUNK_ID          'tcaf'
#define WAVE_DATA_CHUNK_ID          'atad'
#define WAVE_WAVE_ID                'EVAW'
#endif

#ifdef WAVE_ENDIAN_BIG
#define WAVE_RIFF_CHUNK_ID          'RIFF'
#define WAVE_FORMAT_CHUNK_ID        'fmt '
#define WAVE_FACT_CHUNK_ID          'fact'
#define WAVE_DATA_CHUNK_ID          'data'
#define WAVE_WAVE_ID                'WAVE'
#endif

if checking for Mac and else defaulting to WAVE_ENDIAN_LITTLE would permit easier cross-building.

brglng commented 5 years ago

I will look into the issue these days.

brglng commented 5 years ago

For the 1st issue, you need to add the proper include path in your IDE. For the 2nd issue, I have updated code. Please checkout the newest commit.