undefined reference error compiling demo program

Discussion in 'C Programming' started by vfunc@talktalk.net, Jun 1, 2006.

  1. Guest

    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>
    , Jun 1, 2006
    #1
    1. Advertising

  2. Vladimir Oka Guest

    wrote:
    > 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
    Vladimir Oka, Jun 1, 2006
    #2
    1. Advertising

  3. Guest

    Vladimir Oka wrote:
    > wrote:
    > > 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


    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 */
    , Jun 1, 2006
    #3
  4. santosh Guest

    wrote:
    > Vladimir Oka wrote:
    > > wrote:
    > > > 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

    >
    > 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?
    santosh, Jun 1, 2006
    #4
  5. Guest

    santosh wrote:
    >
    > 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 ?
    , Jun 1, 2006
    #5
  6. In article <>,
    <> wrote:

    >santosh wrote:


    >> 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 ?


    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>
    --
    "law -- it's a commodity"
    -- Andrew Ryan (The Globe and Mail, 2005/11/26)
    Walter Roberson, Jun 1, 2006
    #6
  7. Guest

    Walter Roberson wrote:

    > 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.
    , Jun 1, 2006
    #7
  8. Guest

    wrote:
    > Walter Roberson wrote:
    >
    > > 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.


    OK, I did find a linux dev group.
    , Jun 1, 2006
    #8
  9. On 1 Jun 2006 10:53:21 -0700, wrote:

    >
    >Vladimir Oka wrote:
    >> wrote:
    >> > 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

    >
    >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
    Barry Schwarz, Jun 2, 2006
    #9
    1. Advertising

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

It takes just 2 minutes to sign up (and it's free!). Just click the sign up button to choose a username and then you can ask your own questions on the forum.
Similar Threads
  1. F. GEIGER
    Replies:
    9
    Views:
    1,217
    F. GEIGER
    May 3, 2004
  2. Andy Leszczynski

    wxPython demo /Process does not open new demo

    Andy Leszczynski, Feb 18, 2005, in forum: Python
    Replies:
    1
    Views:
    637
    Andy Leszczynski
    Feb 18, 2005
  3. rhzehr
    Replies:
    4
    Views:
    1,132
    Mark McIntyre
    Apr 25, 2005
  4. Replies:
    6
    Views:
    860
    Robert
    Mar 8, 2006
  5. PS
    Replies:
    0
    Views:
    874
Loading...

Share This Page