LinuxQuestions.org
Download your favorite Linux distribution at LQ ISO.
Go Back   LinuxQuestions.org > Forums > Linux Forums > Linux - Newbie
User Name
Password
Linux - Newbie This Linux forum is for members that are new to Linux.
Just starting out and have a question? If it is not in the man pages or the how-to's this is the place!

Notices


Reply
  Search this Thread
Old 11-07-2011, 07:09 AM   #1
Martin R
LQ Newbie
 
Registered: Nov 2011
Posts: 3

Rep: Reputation: Disabled
undefined reference to snd_pcm_open snd_sterror ...


Hello Community,
I'm newbie in Linux and want to write an application to play audiodata from a buffer.
I startes to write a Test Application using the example I found im web.
http://home.roadrunner.com/~jgglatt/tech/linuxapi.htm
Code:
#include <stdio.h>
#include <string.h>
#include <alsa/asoundlib.h>
int main(int argc, char **argv)
{
   register int  err;
   int           cardNum;
   // Start with first card
   cardNum = -1;
   for (;;){
      snd_ctl_t *cardHandle;
      if ((err = snd_card_next(&cardNum)) < 0){
         printf("Can't get the next card number: %s\n", snd_strerror(err));
         break;
      }
      if (cardNum < 0) break;
      // Open this card's control interface. We specify only the card number -- not
      // any device nor sub-device too
      {
       char   str[64];
       sprintf(str, "hw:%i", cardNum);
       if ((err = snd_ctl_open(&cardHandle, str, 0)) < 0){
         printf("Can't open card %i: %s\n", cardNum, snd_strerror(err));
         continue;
       }
      }

      {
      snd_ctl_card_info_t *cardInfo;
      // We need to get a snd_ctl_card_info_t. Just alloc it on the stack
      snd_ctl_card_info_alloca(&cardInfo);
      // Tell ALSA to fill in our snd_ctl_card_info_t with info about this card
      if ((err = snd_ctl_card_info(cardHandle, cardInfo)) < 0)
         printf("Can't get info for card %i: %s\n", cardNum, snd_strerror(err));
      else
         printf("Card %i = %s\n", cardNum, snd_ctl_card_info_get_name(cardInfo));
      }
      // Close the card's control interface after we're done with it
      snd_ctl_close(cardHandle);
   }
   // ALSA allocates some mem to load its config file when we call some of the
   // above functions. Now that we're done getting the info, let's tell ALSA
   // to unload the info and free up that mem
   snd_config_update_free_global();
}
if I compile it I get a lot of errors:

main.cpp:16: Error:undefined reference to `snd_card_next'
main.cpp:17: undefined reference to `snd_strerror'
main.cpp:26: undefined reference to `snd_ctl_open'
main.cpp:27: undefined reference to `snd_strerror'
main.cpp:36: undefined reference to `snd_ctl_card_info_sizeof'
main.cpp:39: undefined reference to `snd_ctl_card_info'
main.cpp:40: undefined reference to `snd_strerror'
main.cpp:42: undefined reference to `snd_ctl_card_info_get_name'
main.cpp:46: undefined reference to `snd_ctl_close'
main.cpp:51: undefined reference to `snd_config_update_free_global'


I also include <alsa/controls.h> . but I am not able to compile the code :-(

.

thanks for your help.

Martin

Last edited by Martin R; 11-07-2011 at 10:32 AM.
 
Old 11-07-2011, 10:33 AM   #2
Martin R
LQ Newbie
 
Registered: Nov 2011
Posts: 3

Original Poster
Rep: Reputation: Disabled
Compiler flag -lasound
 
Old 07-07-2014, 04:18 AM   #3
chuppi
LQ Newbie
 
Registered: Jan 2013
Location: bengaluru
Posts: 3

Rep: Reputation: Disabled
<alsa/controls.h>

its <alsa/control.h> and compile
 
Old 06-14-2017, 06:04 AM   #4
DimaRabadi
LQ Newbie
 
Registered: Jun 2017
Posts: 1

Rep: Reputation: Disabled
Unhappy Same problem

I am also facing the same problem regarding alsa, I added the required <alsa/control.h> file but still the same problem. Any help plz?
 
  


Reply


Thread Tools Search this Thread
Search this Thread:

Advanced Search

Posting Rules
You may not post new threads
You may not post replies
You may not post attachments
You may not edit your posts

BB code is On
Smilies are On
[IMG] code is Off
HTML code is Off



Similar Threads
Thread Thread Starter Forum Replies Last Post
Yet another undefined reference CollieJim Linux - General 2 12-18-2010 12:08 AM
undefined reference to.... crapodino Programming 1 01-13-2008 08:05 PM
undefined reference to... dimah Programming 3 12-27-2006 10:57 AM
undefined reference? Sharky01252 Programming 3 11-07-2006 12:36 PM
Undefined Reference ChemicalBurn Programming 2 02-14-2005 04:01 AM

LinuxQuestions.org > Forums > Linux Forums > Linux - Newbie

All times are GMT -5. The time now is 12:31 PM.

Main Menu
Advertisement
My LQ
Write for LQ
LinuxQuestions.org is looking for people interested in writing Editorials, Articles, Reviews, and more. If you'd like to contribute content, let us know.
Main Menu
Syndicate
RSS1  Latest Threads
RSS1  LQ News
Twitter: @linuxquestions
Facebook: linuxquestions Google+: linuxquestions
Open Source Consulting | Domain Registration