Errors in application building

[Date Prev][Date Next][Thread Prev][Thread Next][Date Index][Thread Index]

 



Hello all:

I am working on my first bit of application code for ALSA and am not sure
how to properly compile it against the libs. I have to cross compile the
application on my host machine i686 PC for use on a ARM development board. I
copied the alsa include directory into my staging include directory (this is
where the cross-compiler works from), which allowed the program to find
alsa/asoundlib.h However, I am still getting some errors that indicate to me
it cannot find everything it needs.

I am getting the following errors:

grhuser@pcL7:$ arm-linux-gcc -Wall -o grh_audio grh_audio.c
grh_audio.c: In function 'grh_capture':
grh_audio.c:113: warning: pointer targets in passing argument 3 of
'snd_pcm_hw_params_set_rate_near' differ in signedness
grh_audio.c: In function 'grh_playback':
grh_audio.c:208: warning: pointer targets in passing argument 3 of
'snd_pcm_hw_params_set_rate_near' differ in signedness
/tmp/ccMn48zN.o: In function `grh_capture':
grh_audio.c:(.text+0x16c): undefined reference to `snd_pcm_open'
grh_audio.c:(.text+0x198): undefined reference to `snd_strerror'
grh_audio.c:(.text+0x1c0): undefined reference to `snd_pcm_hw_params_malloc'
grh_audio.c:(.text+0x1e4): undefined reference to `snd_strerror'
grh_audio.c:(.text+0x214): undefined reference to `snd_pcm_hw_params_any'
grh_audio.c:(.text+0x238): undefined reference to `snd_strerror'
grh_audio.c:(.text+0x26c): undefined reference to
`snd_pcm_hw_params_set_access'
grh_audio.c:(.text+0x290): undefined reference to `snd_strerror'
grh_audio.c:(.text+0x2c4): undefined reference to
`snd_pcm_hw_params_set_format'
grh_audio.c:(.text+0x2e8): undefined reference to `snd_strerror'
grh_audio.c:(.text+0x324): undefined reference to
`snd_pcm_hw_params_set_rate_near'
grh_audio.c:(.text+0x348): undefined reference to `snd_strerror'
grh_audio.c:(.text+0x380): undefined reference to
`snd_pcm_hw_params_set_channels'
grh_audio.c:(.text+0x3a4): undefined reference to `snd_strerror'
grh_audio.c:(.text+0x3d4): undefined reference to `snd_pcm_hw_params'
grh_audio.c:(.text+0x3f8): undefined reference to `snd_strerror'
grh_audio.c:(.text+0x420): undefined reference to `snd_pcm_hw_params_free'
grh_audio.c:(.text+0x42c): undefined reference to `snd_pcm_prepare'
grh_audio.c:(.text+0x450): undefined reference to `snd_strerror'
grh_audio.c:(.text+0x494): undefined reference to `snd_pcm_readi'
grh_audio.c:(.text+0x4c0): undefined reference to `snd_strerror'
grh_audio.c:(.text+0x500): undefined reference to `snd_pcm_close'
/tmp/ccMn48zN.o: In function `grh_playback':
grh_audio.c:(.text+0x5b8): undefined reference to `snd_pcm_open'
grh_audio.c:(.text+0x5e4): undefined reference to `snd_strerror'
grh_audio.c:(.text+0x60c): undefined reference to `snd_pcm_hw_params_malloc'
grh_audio.c:(.text+0x630): undefined reference to `snd_strerror'
grh_audio.c:(.text+0x660): undefined reference to `snd_pcm_hw_params_any'
grh_audio.c:(.text+0x684): undefined reference to `snd_strerror'
grh_audio.c:(.text+0x6b8): undefined reference to
`snd_pcm_hw_params_set_access'
grh_audio.c:(.text+0x6dc): undefined reference to `snd_strerror'
grh_audio.c:(.text+0x710): undefined reference to
`snd_pcm_hw_params_set_format'
grh_audio.c:(.text+0x734): undefined reference to `snd_strerror'
grh_audio.c:(.text+0x770): undefined reference to
`snd_pcm_hw_params_set_rate_near'
grh_audio.c:(.text+0x794): undefined reference to `snd_strerror'
grh_audio.c:(.text+0x7cc): undefined reference to
`snd_pcm_hw_params_set_channels'
grh_audio.c:(.text+0x7f0): undefined reference to `snd_strerror'
grh_audio.c:(.text+0x820): undefined reference to `snd_pcm_hw_params'
grh_audio.c:(.text+0x844): undefined reference to `snd_strerror'
grh_audio.c:(.text+0x86c): undefined reference to `snd_pcm_hw_params_free'
grh_audio.c:(.text+0x878): undefined reference to `snd_pcm_prepare'
grh_audio.c:(.text+0x89c): undefined reference to `snd_strerror'
grh_audio.c:(.text+0x8e0): undefined reference to `snd_pcm_writei'
grh_audio.c:(.text+0x90c): undefined reference to `snd_strerror'
grh_audio.c:(.text+0x94c): undefined reference to `snd_pcm_close'
collect2: ld returned 1 exit status

My application code is attached. If anyone could give me some pointers as to
why these errors are occurring, I would appreciate it greatly.

Thanks.

Paul


--
***************************************
Paul David Kavan
Project Engineer
GRH Electronics, Inc.
402-734-4900
pkavan@xxxxxxxxx
***************************************
/* GRH Audio Program
 *
 * Author: Paul Kavan, Project Engineer
 * Date: July 3, 2007
 */

#include <stdio.h>
#include <stdlib.h>
#include <alsa/asoundlib.h>


/*************************************
 * Variable and Function Declarations 
 *************************************/
int             audio_type;                     //0 = sleep; 1 = capture; 2 = playback
int             nchannels = 1;
int             buffer_size = 512;
int             sample_rate = 8000;
int             bits = 8;
char           *snd_device_in  = "hw:0,0";
char           *snd_device_out = "hw:0,0";

void grh_capture(void);
void grh_playback(void);


/*************************************
 * Main Program Section
 *************************************/
int main(void)
{
  //Testing routine
  printf("Press enter to begin recording\n");
  getchar();
  grh_capture();
  printf("Audio Captured. Press enter to playback\n");
  getchar();

    
  /************************************
   * Decide between playback or capture
   ************************************/
  //TODO Determine best way to receive interrupts/mgs to parse
  //     between playback and capture


  /************************************
   * Call the appropriate function for
   * either playback or capture
   ************************************/
  /*if(audio_type==1)
    grh_capture();
  if(audio_type==2)
    grh_playback();*/

  return 0;
}



/*************************************************
 * Capture Function:
 * This fuction should capture audio from the PCM 
 * and store it in a buffer for transmission
 *************************************************/
void grh_capture(void)
{
  int i;
  int err;
  short buf[buffer_size];
  snd_pcm_t *capture_handle;
  snd_pcm_hw_params_t *hw_params;

  /************************************
   * Open the pcm interface
   ************************************/
  if ((err = snd_pcm_open(&capture_handle, snd_device_in, SND_PCM_STREAM_CAPTURE, 0)) < 0)
  {
    fprintf(stderr, "Failed to open input audio device %s: %s\n", snd_device_out, snd_strerror(err));
    exit(1);
  }

  /************************************
   * Configure the devices
   ************************************/
  if ((err = snd_pcm_hw_params_malloc (&hw_params)) < 0) 
  {
    fprintf (stderr, "cannot allocate hardware parameter structure (%s)\n",
        snd_strerror (err));
    exit (1);
  }

  if ((err = snd_pcm_hw_params_any (capture_handle, hw_params)) < 0) 
  {
    fprintf (stderr, "cannot initialize hardware parameter structure (%s)\n",
        snd_strerror (err));
    exit (1);
  }
	
  if ((err = snd_pcm_hw_params_set_access (capture_handle, hw_params, SND_PCM_ACCESS_RW_INTERLEAVED)) < 0) 
  {
    fprintf (stderr, "cannot set access type (%s)\n",
        snd_strerror (err));
    exit (1);
  }

  if ((err = snd_pcm_hw_params_set_format (capture_handle, hw_params, SND_PCM_FORMAT_S8)) < 0) {
    fprintf (stderr, "cannot set sample format (%s)\n",
        snd_strerror (err));
    exit (1);
  }

  if ((err = snd_pcm_hw_params_set_rate_near (capture_handle, hw_params, &sample_rate, 0)) < 0) 
  {
    fprintf (stderr, "cannot set sample rate (%s)\n",
        snd_strerror (err));
    exit (1);
  }
	
  if ((err = snd_pcm_hw_params_set_channels (capture_handle, hw_params, nchannels)) < 0) 
  {
    fprintf (stderr, "cannot set channel count (%s)\n",
        snd_strerror (err));
    exit (1);
  }

  if ((err = snd_pcm_hw_params (capture_handle, hw_params)) < 0) {
    fprintf (stderr, "cannot set parameters (%s)\n",
        snd_strerror (err));
    exit (1);
  }

  snd_pcm_hw_params_free (hw_params);

  if ((err = snd_pcm_prepare (capture_handle)) < 0) {
    fprintf (stderr, "cannot prepare audio interface for use (%s)\n",
        snd_strerror (err));
    exit (1);
  }

  /******************************************
   * Perform capture and store to buffer
   ******************************************/
  for (i = 0; i < 10; ++i) {
    if ((err = snd_pcm_readi (capture_handle, buf, buffer_size)) != buffer_size) {
      fprintf (stderr, "read from audio interface failed (%s)\n",
          snd_strerror (err));
      exit (1);
    }
  }

  /*******************************************
   * Close PCM interface and exit
   *******************************************/
  snd_pcm_close (capture_handle);
  exit (0);
}

/************************************************
 * Playback Function:
 * This function should retrieve audio from a 
 * buffer and send it to the PCM for playback
 ************************************************/
void grh_playback(void)
{
  int i;
  int err;
  short buf[buffer_size];
  snd_pcm_t *playback_handle;
  snd_pcm_hw_params_t *hw_params;

  /************************************
   * Open the pcm interface
   ************************************/
  if ((err = snd_pcm_open(&playback_handle, snd_device_out, SND_PCM_STREAM_PLAYBACK, 0)) < 0) 
  {
    fprintf(stderr, "Failed to open output audio device %s: %s\n", snd_device_in, snd_strerror(err));
    exit(1);
  }

  /************************************
   * Configure the devices
   ************************************/
  if ((err = snd_pcm_hw_params_malloc (&hw_params)) < 0) {
    fprintf (stderr, "cannot allocate hardware parameter structure (%s)\n",
        snd_strerror (err));
    exit (1);
  }
				 
  if ((err = snd_pcm_hw_params_any (playback_handle, hw_params)) < 0) {
    fprintf (stderr, "cannot initialize hardware parameter structure (%s)\n",
        snd_strerror (err));
    exit (1);
  }
	
  if ((err = snd_pcm_hw_params_set_access (playback_handle, hw_params, SND_PCM_ACCESS_RW_INTERLEAVED)) < 0) {
    fprintf (stderr, "cannot set access type (%s)\n",
        snd_strerror (err));
    exit (1);
  }
	
  if ((err = snd_pcm_hw_params_set_format (playback_handle, hw_params, SND_PCM_FORMAT_S8)) < 0) {
    fprintf (stderr, "cannot set sample format (%s)\n",
        snd_strerror (err));
    exit (1);
  }
	
  if ((err = snd_pcm_hw_params_set_rate_near (playback_handle, hw_params, &sample_rate, 0)) < 0) {
    fprintf (stderr, "cannot set sample rate (%s)\n",
        snd_strerror (err));
    exit (1);
  }
	
  if ((err = snd_pcm_hw_params_set_channels (playback_handle, hw_params, nchannels)) < 0) {
    fprintf (stderr, "cannot set channel count (%s)\n",
        snd_strerror (err));
    exit (1);
  }

  if ((err = snd_pcm_hw_params (playback_handle, hw_params)) < 0) {
    fprintf (stderr, "cannot set parameters (%s)\n",
        snd_strerror (err));
    exit (1);
  }
	
  snd_pcm_hw_params_free (hw_params);

  if ((err = snd_pcm_prepare (playback_handle)) < 0) {
    fprintf (stderr, "cannot prepare audio interface for use (%s)\n",
        snd_strerror (err));
    exit (1);
  }

  /******************************************
   * Playback from buffer
   ******************************************/
  for (i = 0; i < 10; ++i) {
    if ((err = snd_pcm_writei (playback_handle, buf, buffer_size)) != buffer_size) {
      fprintf (stderr, "write to audio interface failed (%s)\n",
          snd_strerror (err));
      exit (1);
    }
  }

  /*******************************************
   * Close PCM interface and exit
   *******************************************/
  snd_pcm_close (playback_handle);
  exit (0);
}
_______________________________________________
Alsa-devel mailing list
Alsa-devel@xxxxxxxxxxxxxxxx
http://mailman.alsa-project.org/mailman/listinfo/alsa-devel

[Index of Archives]     [ALSA User]     [Linux Audio Users]     [Kernel Archive]     [Asterisk PBX]     [Photo Sharing]     [Linux Sound]     [Video 4 Linux]     [Gimp]     [Yosemite News]

  Powered by Linux