Welcome to the most active Linux Forum on the web.
Go Back > Forums > Linux Forums > Linux - Newbie
User Name
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!


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

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

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.

#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));
      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));

      snd_ctl_card_info_t *cardInfo;

      // We need to get a snd_ctl_card_info_t. Just alloc it on the stack

      // 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));
         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
   // 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
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.

Old 11-07-2011, 04:30 PM   #2
Registered: Sep 2003
Location: Bologna
Distribution: CentOS 6.5 OpenSuSE 12.3
Posts: 10,509

Rep: Reputation: 1966Reputation: 1966Reputation: 1966Reputation: 1966Reputation: 1966Reputation: 1966Reputation: 1966Reputation: 1966Reputation: 1966Reputation: 1966Reputation: 1966
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

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

All times are GMT -5. The time now is 03:21 AM.

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