undefined reference error compiling demo program

V

vfunc

I get compile error:
undefined reference to snd_pcm_format_width.
I included the library directory with -I flag on gcc.

#include <stdio.h>
#include <stdlib.h>
#include <string.h>
#include <sched.h>
#include <errno.h>
#include <getopt.h>
#include "../include/asoundlib.h"
#include <sys/time.h>
#include <math.h>
 
V

Vladimir Oka

I get compile error:
undefined reference to snd_pcm_format_width.
I included the library directory with -I flag on gcc.

#include <stdio.h>
#include <stdlib.h>
#include <string.h>
#include <sched.h>
#include <errno.h>
#include <getopt.h>
#include "../include/asoundlib.h"
#include <sys/time.h>
#include <math.h>

A few problems you have here:

- there's a lot of non-standard stuff here, so it's off topic
- there's no program here at all, just some `#include`s
- there's a memory (and oil) leak on lines 42, and 57
 
V

vfunc

Vladimir said:
A few problems you have here:

- there's a lot of non-standard stuff here, so it's off topic
- there's no program here at all, just some `#include`s
- there's a memory (and oil) leak on lines 42, and 57

Sorry, I was a bit sloppy, the "../include/" is different. I only
pasted the header as that is where it looks for its references right ?
Here is the full code upto the error.


/*
* This small demo sends a simple sinusoidal wave to your speakers.
*/

#include <stdio.h>
#include <stdlib.h>
#include <string.h>
#include <sched.h>
#include <errno.h>
#include <getopt.h>
#include "../include/asoundlib.h"
#include <sys/time.h>
#include <math.h>

static char *device = "plughw:0,0"; /* playback
device */
static snd_pcm_format_t format = SND_PCM_FORMAT_S16; /* sample
format */
static unsigned int rate = 44100; /* stream rate
*/
static unsigned int channels = 1; /* count of
channels */
static unsigned int buffer_time = 500000; /* ring buffer
length in us */
static unsigned int period_time = 100000; /* period time
in us */
static double freq = 440; /* sinusoidal
wave frequency in Hz */
static int verbose = 0; /* verbose flag */
static int resample = 1; /* enable
alsa-lib resampling */

static snd_pcm_sframes_t buffer_size;
static snd_pcm_sframes_t period_size;
static snd_output_t *output = NULL;

static void generate_sine(const snd_pcm_channel_area_t *areas,
snd_pcm_uframes_t offset,
int count, double *_phase)
{
static double max_phase = 2. * M_PI;
double phase = *_phase;
double step = max_phase*freq/(double)rate;
double res;
unsigned char *samples[channels], *tmp;
int steps[channels];
unsigned int chn, byte;
int ires;
unsigned int maxval = (1 << (snd_pcm_format_width(format) - 1))
- 1;
int bps = snd_pcm_format_width(format) / 8; /* bytes per
sample */

/* verify and prepare the contents of areas */
 
S

santosh

Sorry, I was a bit sloppy, the "../include/" is different. I only
pasted the header as that is where it looks for its references right ?
Here is the full code upto the error.
.... snip code ...

As the error says, none of your code modules contain the identifier
concerned. Why don't you try using nm to dump the symbols in the
library to which your link to?
 
V

vfunc

santosh said:
As the error says, none of your code modules contain the identifier
concerned. Why don't you try using nm to dump the symbols in the
library to which your link to?

OK, I used nm on the link directory and it did not recognise the files,
where do I find the files for nm ? It likes to check .o files, right ?
 
W

Walter Roberson

santosh wrote:
OK, I used nm on the link directory and it did not recognise the files,
where do I find the files for nm ? It likes to check .o files, right ?

Wrong newsgroup -- you are asking a Linux-specific question.

<OT warning="The below is unverified">
- nm usually checks libraries as well as .o files.
- http://glide.stanford.edu/lxr/ident?v=linux-2.6.5;i=snd_pcm_format_width
- http://glide.stanford.edu/lxr/source/Documentation/sound/oss/Introduction?v=linux-2.6.5
</OT>
 
V

vfunc

Walter said:
Wrong newsgroup -- you are asking a Linux-specific question.

phhu, there is no comp.lang.c.linux group, nothing matching that with
much activity at least not that i found quickly.
 
B

Barry Schwarz

Sorry, I was a bit sloppy, the "../include/" is different. I only
pasted the header as that is where it looks for its references right ?
Here is the full code upto the error.
No. The undefined reference error is a linker error. Headers are
used by the compiler, not the linker.

On many common systems, references are resolved by searching
libraries. Libraries and headers are completely different.


Remove del for email
 

Ask a Question

Want to reply to this thread or ask your own question?

You'll need to choose a username for the site, which only take a couple of moments. After that, you can post your question and our members will help you out.

Ask a Question

Members online

Forum statistics

Threads
473,766
Messages
2,569,569
Members
45,042
Latest member
icassiem

Latest Threads

Top