LinuxQuestions.org
Did you know LQ has a Linux Hardware Compatibility List?
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

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

Rep: Reputation: Disabled
main.cpp:16: undefined reference to `snd_card_next'


Hello,
I want to write an application to play sound from a buffer using alsa

first I try to make a test. I find following code 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 this code I get following Error:

main.cpp:16: 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: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 use #include <alsa/Contols.h> but it does not help.

thanks for ur help.

Martin
 
Old 11-07-2011, 03:30 PM   #2
colucix
Moderator
 
Registered: Sep 2003
Location: Bologna
Distribution: CentOS 6.5 OpenSuSE 12.3
Posts: 10,498

Rep: Reputation: 1956Reputation: 1956Reputation: 1956Reputation: 1956Reputation: 1956Reputation: 1956Reputation: 1956Reputation: 1956Reputation: 1956Reputation: 1956Reputation: 1956
Please post your thread in only one forum. Posting a single thread in the most relevant forum will make it easier for members to help you and will keep the discussion in one place. This thread is being closed because it is a duplicate of http://www.linuxquestions.org/questi...terror-912312/
 
  


Closed Thread


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
Undefined reference to 'main' Astrodude Programming 4 06-22-2010 08:27 PM
undefined reference to `main' otacon 14112 Programming 4 03-18-2008 04:23 PM
Undefined reference to 'main' myhanguk Programming 5 07-05-2007 03:32 AM
undefined reference to main () ?. rameshs Linux - Newbie 3 01-11-2007 06:29 PM
undefined reference to main cjbrockwell Programming 3 09-06-2006 05:09 PM


All times are GMT -5. The time now is 08:50 PM.

Main Menu
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
identi.ca: @linuxquestions
Facebook: linuxquestions Google+: linuxquestions
Open Source Consulting | Domain Registration