Results 1 to 3 of 3

Thread: C code problem with ALSA

  1. #1
    Join Date
    Apr 2013
    Beans
    2

    Question C code problem with ALSA

    I wrote a program for simply use of ALSA on Kubuntu 13.04beta2 (raring) system. The code is:
    Code:
    #include <stdio.h>
    #include <alsa/asoundlib.h>
    
    
    int main() {
      int val;
    
    
      printf("ALSA library version: %s\n",
              SND_LIB_VERSION_STR);
    
    
      printf("\nPCM stream types:\n");
      for (val = 0; val <= SND_PCM_STREAM_LAST; val++)
        printf("  %s\n",
          snd_pcm_stream_name((snd_pcm_stream_t)val));
    
    
      printf("\nPCM access types:\n");
      for (val = 0; val <= SND_PCM_ACCESS_LAST; val++)
        printf("  %s\n",
          snd_pcm_access_name((snd_pcm_access_t)val));
    
    
      printf("\nPCM formats:\n");
      for (val = 0; val <= SND_PCM_FORMAT_LAST; val++)
        if (snd_pcm_format_name((snd_pcm_format_t)val)
          != NULL)
          printf("  %s (%s)\n",
            snd_pcm_format_name((snd_pcm_format_t)val),
            snd_pcm_format_description(
                               (snd_pcm_format_t)val));
    
    
      printf("\nPCM subformats:\n");
      for (val = 0; val <= SND_PCM_SUBFORMAT_LAST;
           val++)
        printf("  %s (%s)\n",
          snd_pcm_subformat_name((
            snd_pcm_subformat_t)val),
          snd_pcm_subformat_description((
            snd_pcm_subformat_t)val));
    
    
      printf("\nPCM states:\n");
      for (val = 0; val <= SND_PCM_STATE_LAST; val++)
        printf("  %s\n",
               snd_pcm_state_name((snd_pcm_state_t)val));
    
    
      return 0;
    }
    Very simple.. Like examples in doc. But i can't be able to compile this program. I also added -lasound flag to gcc.
    gcc output:
    Code:
    fatih@fatih-KUBUNTU:~$ gcc -lasound -o tune tune.c
    /tmp/ccd2xSUq.o: In function `main':
    tune.c:(.text+0x36): undefined reference to `snd_pcm_stream_name'
    tune.c:(.text+0x6f): undefined reference to `snd_pcm_access_name'
    tune.c:(.text+0xa8): undefined reference to `snd_pcm_format_name'
    tune.c:(.text+0xb7): undefined reference to `snd_pcm_format_description'
    tune.c:(.text+0xc4): undefined reference to `snd_pcm_format_name'
    tune.c:(.text+0x100): undefined reference to `snd_pcm_subformat_description'
    tune.c:(.text+0x10d): undefined reference to `snd_pcm_subformat_name'
    tune.c:(.text+0x149): undefined reference to `snd_pcm_state_name'
    collect2: hata: ld çıkış durumu 1 ile döndü
    Problem is at the linker section. What's the problem? How can i compile with ALSA?
    (sorry for bad english)

  2. #2
    Join Date
    Apr 2012
    Beans
    6,042

    Re: C code problem with ALSA

    the resolve order is important - try

    Code:
    gcc -o tune tune.c -lasound

  3. #3
    Join Date
    Apr 2013
    Beans
    2

    Thumbs up [SOLVED] C code problem with ALSA

    Thank you @steeldriver. Problem solved...Thread can be closed...

Tags for this Thread

Bookmarks

Posting Permissions

  • You may not post new threads
  • You may not post replies
  • You may not post attachments
  • You may not edit your posts
  •