[SOLVED] linking errors in Qt



  • Hi guys, i am getting the following errors in Qt:
    main.o: In function main': /home/test/Documents/Wave-build-desktop/../Wave/main.cpp:96: undefined reference toset_hwparams(_snd_pcm*, _snd_pcm_hw_params*, _snd_pcm_access)'
    /home/test/Documents/Wave-build-desktop/../Wave/main.cpp:101: undefined reference to set_swparams(_snd_pcm*, _snd_pcm_sw_params*)' /home/test/Documents/Wave-build-desktop/../Wave/main.cpp:128: undefined reference towrite_loop(_snd_pcm*, short*, _snd_pcm_channel_area*)'
    main.o:(.data+0x10): undefined reference to write_loop(_snd_pcm*, short*, _snd_pcm_channel_area*)' moc_wave.o:(.data+0x10): undefined reference towrite_loop(_snd_pcm*, short*, _snd_pcm_channel_area*)'
    collect2: ld returned 1 exit status

    The errors are saying that there is undefined reference to the above functions in my file main.cpp. They are however defined originally in wave.cpp and are being used in main.cpp with correct referencing(i'm pretty sure). I have also referenced them in my wave.h file, so I am not sure why its having a problem linking them. Any help would be greatly appreciated.

    Below are my wave.cpp, main.cpp and wave.h files:

    wave.cpp:
    @#include <QtGui>
    #include <QApplication>
    #include <qlineedit.h>
    #include "ui_wave.h"
    #include <QString>
    #include <QDebug>
    #include <stdio.h>
    #include <cstdio>
    #include <stdlib.h>
    #include <cstdlib>
    #include <string.h>
    #include <cstring>
    #include <sched.h>
    #include <errno.h>
    #include <getopt.h>
    #include <alsa/asoundlib.h>
    #include <sys/time.h>
    #include <sstream>
    #include <string>
    #include <math.h>
    #include <cmath>
    #include <iostream>
    #include "wave.h"
    using namespace std;

    static const char device = "plughw:0,0"; / playback device /
    static snd_pcm_format_t format = SND_PCM_FORMAT_S16; /
    sample format- change to 24-bit /
    static unsigned int rate = 96000; /
    stream rate /
    static unsigned int channels = 128; /
    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; /
    sinusoidal wave frequency in Hz /
    static int verbose = 0; /
    verbose flag /
    static int resample = 1; /
    enable alsa-lib resampling /
    static int period_event = 0; /
    produce poll event after each period */
    static snd_pcm_sframes_t buffer_size;
    static snd_pcm_sframes_t period_size;
    static snd_output_t *output = NULL;
    static double ampl;
    static snd_pcm_t *h;
    static bool isTrue;

    void wave::on_pushButton_clicked()
    {

         ...}
    

    static int set_hwparams(snd_pcm_t *handle,
    snd_pcm_hw_params_t *params,
    snd_pcm_access_t access)
    {

           ...
    

    }

    static int set_swparams(snd_pcm_t *handle, snd_pcm_sw_params_t *swparams)
    {
    ...
    }

       //    Transfer method - write only
    

    static int write_loop(snd_pcm_t *handle,
    signed short *samples,
    snd_pcm_channel_area_t *areas)

    {

    ...
    }@



  • home/test/Documents/Wave-build-desktop/../Wave/main.cpp:96: undefined reference to `set_hwparams(_snd_pcm*, _snd_pcm_hw_params*, _snd_pcm_access)’:
    @if ((err = set_hwparams(h, hwparams, transfer_methods[method].access)) < 0) {
    printf("Setting of hwparams failed: %s\n", snd_strerror(err));
    exit(EXIT_FAILURE);@

    home/test/Documents/Wave-build-desktop/../Wave/main.cpp:101: undefined reference to `set_swparams(_snd_pcm*, _snd_pcm_sw_params*)’
    @if ((err = set_swparams(h, swparams)) < 0) {
    printf("Setting of swparams failed: %s\n", snd_strerror(err));
    exit(EXIT_FAILURE);@

    /home/test/Documents/Wave-build-desktop/../Wave/main.cpp:128: undefined reference to `write_loop(_snd_pcm*, short*, _snd_pcm_channel_area*)’
    @err = write_loop(h, samp, area);@

    main.cpp:

    @#include <QtGui>
    #include <QApplication>
    #include <qlineedit.h>
    #include "ui_wave.h"
    #include <QString>
    #include <QDebug>
    #include <stdio.h>
    #include <cstdio>
    #include <stdlib.h>
    #include <cstdlib>
    #include <string.h>
    #include <cstring>
    #include <sched.h>
    #include <errno.h>
    #include <getopt.h>
    #include <alsa/asoundlib.h>
    #include <sys/time.h>
    #include <sstream>
    #include <string>
    #include <math.h>
    #include <cmath>
    #include <iostream>
    #include "wave.h"
    using namespace std;

    static const char device = "plughw:0,0"; / playback device /
    static snd_pcm_format_t format = SND_PCM_FORMAT_S16; /
    sample format- change to 24-bit /
    static unsigned int rate = 96000; /
    stream rate /
    static unsigned int channels = 128; /
    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; /
    sinusoidal wave frequency in Hz /
    static int verbose = 0; /
    verbose flag /
    static int resample = 1; /
    enable alsa-lib resampling /
    static int period_event = 0; /
    produce poll event after each period */
    static snd_pcm_sframes_t buffer_size;
    static snd_pcm_sframes_t period_size;
    static snd_output_t *output = NULL;
    static double ampl;
    static snd_pcm_t *h;
    static bool isTrue;

    int main(int argc, char *argv[])
    {
    struct option long_option[] =
    {
    {"help", 0, NULL, 'h'},
    {"device", 1, NULL, 'D'},
    {"rate", 1, NULL, 'r'},
    {"channels", 1, NULL, 'c'},
    {"frequency", 1, NULL, 'f'},
    {"buffer", 1, NULL, 'b'},
    {"period", 1, NULL, 'p'},
    {"method", 1, NULL, 'm'},
    {"format", 1, NULL, 'o'},
    {"verbose", 1, NULL, 'v'},
    {"noresample", 1, NULL, 'n'},
    {"pevent", 1, NULL, 'e'},
    {NULL, 0, NULL, 0},
    };

        int err, morehelp;
        snd_pcm_hw_params_t *hwparams;
        snd_pcm_sw_params_t *swparams;
        int method = 0;
        short int *samp;
        snd_pcm_t *h;
        snd_pcm_channel_area_t *area;
        snd_pcm_t *handle = (snd_pcm_t*) h;
        unsigned char *samples  = (unsigned char*) samp;
        unsigned int chn;
        snd_pcm_channel_area_t *areas = (snd_pcm_channel_area_t*) area;
    
        snd_pcm_hw_params_alloca(&hwparams);
        snd_pcm_sw_params_alloca(&swparams);
    
    
        err = snd_output_stdio_attach(&output, stdout, 0);
        if (err < 0) {
                printf("Output failed: %s\n", snd_strerror(err));
                return 0;
        }
    

    /* cout<<"Playback device is %s "<<","<< device);
    cout<<"Stream parameters are %iHz, %s, %i channels "<<","<< rate<<","<< snd_pcm_format_name(format), channels;
    cout<<"Sine wave rate is %.4fHz "<<","<< freq;
    cout<<"Using transfer method: %s "<<","<< transfer_methods[method].name; */

        if ((err = snd_pcm_open(&h, device, SND_PCM_STREAM_PLAYBACK, 0)) < 0) {
                printf("Playback open error: %s\n", snd_strerror(err));
                return 0;
        }
    
        if ((err = set_hwparams(h, hwparams, transfer_methods[method].access)) < 0) {
                printf("Setting of hwparams failed: %s\n", snd_strerror(err));
                exit(EXIT_FAILURE);
        }
    
        if ((err = set_swparams(h, swparams)) < 0) {
                printf("Setting of swparams failed: %s\n", snd_strerror(err));
                exit(EXIT_FAILURE);
        }
    
        if (verbose > 0)
                snd_pcm_dump(h, output);
    
        samp = new short int [period_size * channels * snd_pcm_format_physical_width(format)];
    
    
        if (samp == NULL) {
                printf("Not enough memory\n");
                exit(EXIT_FAILURE);
        }
    
        area = new snd_pcm_channel_area_t [channels, sizeof(snd_pcm_channel_area_t)];
        if (area == NULL) {
                printf("Not enough memory\n");
                exit(EXIT_FAILURE);
        }
        for (chn = 0; chn < channels; chn++) {
                area[chn].addr = samp;
                area[chn].first = chn * snd_pcm_format_physical_width(format);
                area[chn].step = channels * snd_pcm_format_physical_width(format);
        }
    
        err = write_loop(h, samp, area);
        if (err < 0)
                printf("Transfer failed: %s\n", snd_strerror(err));
    
        delete(area);
        delete(samp);
        snd_pcm_close(h);
        return 0;
    

    }@



  • wave.h:

    @#ifndef WAVE_H
    #define WAVE_H
    #include <alsa/asoundlib.h>
    #include <QMainWindow>

    namespace Ui {
    class wave;
    }

    class wave : public QMainWindow
    {
    Q_OBJECT

    public:
    explicit wave(QWidget *parent = 0);
    ~wave();

    private slots:
    void on_pushButton_clicked();

    void on_pushButton_2_clicked();
    

    private:
    Ui::wave *ui;
    };

    static int set_hwparams(snd_pcm_t *handle,
    snd_pcm_hw_params_t *params,
    snd_pcm_access_t access);
    static int set_swparams(snd_pcm_t *handle, snd_pcm_sw_params_t *swparams);
    static int write_loop(snd_pcm_t *handle,
    signed short *samples,
    snd_pcm_channel_area_t *areas);

    struct transfer_method {
    const char *name;
    snd_pcm_access_t access;
    int (*transfer_loop)(snd_pcm_t *handle,
    signed short *samples,
    snd_pcm_channel_area_t *areas);
    };

    static struct transfer_method transfer_methods[] = {

          { "write", SND_PCM_ACCESS_RW_INTERLEAVED, write_loop },
          { NULL, SND_PCM_ACCESS_RW_INTERLEAVED, NULL }
    

    };

    #endif // WAVE_H
    @



  • You can find some information "here":http://www.imb-jena.de/~gmueller/kurse/c_c++/c_linkag.html



  • [quote author="loladiro" date="1312316884"]You can find some information "here":http://www.imb-jena.de/~gmueller/kurse/c_c++/c_linkag.html[/quote]

    Hi loladiro, thanks for the reply. I took a look at your link and I have implemented the method explained in your link. When using write_loop in my main.cpp, i wrote: write_loop(h, samp, area);
    When using set_swparams, i wrote set_swparams(h, swparams)
    When using set_hwparams, i wrote set_hwparams(h, hwparams, transfer_methods[method].access)
    as shown in the posts above. but i am still getting the same errors. Please look at my posts above more carefully.


  • Moderators

    Is that all of your main.cpp? I'm confused as to how that is even a Qt app at all, except for your including the wave.h stuff.

    Your code is a teeny bit hard to read, and I'm not sure where the logic begins and the errors start... I don't mean that in a mean way, but only that it's a little hard to try to figure out what's supposed to be happening.

    Are you somehow trying to reimplement alsa function calls in your wave.cpp file? Inside the on_pushButton_clicked method?



  • [quote author="mlong" date="1312319298"]Is that all of your main.cpp? I'm confused as to how that is even a Qt app at all, except for your including the wave.h stuff.

    Your code is a teeny bit hard to read, and I'm not sure where the logic begins and the errors start... I don't mean that in a mean way, but only that it's a little hard to try to figure out what's supposed to be happening.

    Are you somehow trying to reimplement alsa function calls in your wave.cpp file? Inside the on_pushButton_clicked method?

    [/quote]
    Sorry if its hard to read. I am trying to show that in wave.cpp, I have 3 functions in that file i.e. write_loop, set_swparams and set_hwparams. I have code inside the on_pushButton_clicked method. I am trying to implement alsa. However, that code seems to be running fine. But when I try to use the functions write_loop, set_swparams and set_hwparams in main.cpp, I am getting the errors main.o: In function main’: /home/test/Documents/Wave-build-desktop/../Wave/main.cpp:96: undefined reference toset_hwparams(_snd_pcm*, _snd_pcm_hw_params*, _snd_pcm_access)’
    /home/test/Documents/Wave-build-desktop/../Wave/main.cpp:101: undefined reference to set_swparams(_snd_pcm*, _snd_pcm_sw_params*)’ /home/test/Documents/Wave-build-desktop/../Wave/main.cpp:128: undefined reference towrite_loop(_snd_pcm*, short*, _snd_pcm_channel_area*)’
    main.o:(.data+0×10): undefined reference to write_loop(_snd_pcm*, short*, _snd_pcm_channel_area*)’ moc_wave.o:(.data+0×10): undefined reference towrite_loop(_snd_pcm*, short*, _snd_pcm_channel_area*)’
    collect2: ld returned 1 exit status.

    I have also implemented these functions in my header file. So what I am having a problem with is implementing these three functions in main.cpp.
    I hope this is a better explanation. Sorry



  • You usually declare the methods or functions in a header file and implement it in a source file (.c or .cpp). Your problem has nothing to do with Qt (despite that the methods are called from some slot or the like).

    Are you really sure you have implemented the methods and that implementation is actually compiled?


  • Moderators

    I'm still confused as to you're redefining the functions in wave.cpp. They are already defined in the alsa library, no? It should just be a matter of calling the functions that already exist in the library, rather than creating your own versions.



  • Oh, it's alsa functions. Then it's essential to include the headers provided by alsa and link against the appropriate libraries. And it is a no-no to redeclare the functions in your own header file!


  • Moderators

    And we already discussed the linking "here.":http://developer.qt.nokia.com/forums/viewthread/8227/P15/ earier.



  • Ouch ... I didn't reach that post in my backlog reading :-)


  • Moderators

    It's ok. It took a while to drill down to exactly what the problem was, regardless. :-)



  • No problem. I'm on a huge backlog (or rather unread clicked away posts) due to some vacation.

    So this thread can be closed?


  • Moderators

    I think we've probably gotten to the problem, but I imagine it depends on if ogopa feels like his question's been answered or not.



  • [quote author="Volker" date="1312320331"]You usually declare the methods or functions in a header file and implement it in a source file (.c or .cpp). Your problem has nothing to do with Qt (despite that the methods are called from some slot or the like).

    Are you really sure you have implemented the methods and that implementation is actually compiled?[/quote]

    Sorry for my language it was wrong. I have defined the function in wave.cpp. I have declared it in the header file wave.h and I have called it in main.cpp. Isn't this the method used to call functions from my main.cpp to wave.cpp?

    [quote author="mlong" date="1312320550"]I'm still confused as to you're redefining the functions in wave.cpp. They are already defined in the alsa library, no? It should just be a matter of calling the functions that already exist in the library, rather than creating your own versions.
    [/quote]
    I have defined functions that I wrote myself as it contains content that I wrote, it is not a predefined function that already exists in the alsa library. The functions I wrote are write_loop(), set_sw_params() and set_hwparams().

    I'm really sorry for my terrible explanations so far.


  • Moderators

    Are you needing, perhaps, to put the static functions inside of your wave class, then? Then you could call them from main using wave::write_loop(), etc.? That seems like it might be a cleaner implementation than trying to deal with file scope and all kinds of C-like stuff.



  • Are you sure your wave.cpp is compiled?



  • [quote author="mlong" date="1312394247"]Are you needing, perhaps, to put the static functions inside of your wave class, then? Then you could call them from main using wave::write_loop(), etc.? That seems like it might be a cleaner implementation than trying to deal with file scope and all kinds of C-like stuff.
    [/quote]

    It doesn't allow functions to be placed inside a wave class.

    [quote author="Volker" date="1312394407"]Are you sure your wave.cpp is compiled?[/quote]
    Yes, i'm sure


  • Moderators

    [quote author="ogopa" date="1312395537"]
    It doesn't allow functions to be placed inside a wave class.
    [/quote]

    What doesn't allow functions to be placed inside a wave class?



  • Then I'm bailed out. We cannot guess, what's going on.

    I suggest, you boil down the problem to a small, yet complete and compilable test case and provide us the sources. Then we can have a look. Just add some dummy implementation for your functions.



  • [quote author="mlong" date="1312395659"]
    [quote author="ogopa" date="1312395537"]
    It doesn't allow functions to be placed inside a wave class.
    [/quote]

    What doesn't allow functions to be placed inside a wave class?
    [/quote]

    Qt Creator doesn't allow to place functions inside a wave class for example inside a class of the pushbutton i.e mine is void on_pushButton_clicked().


  • Moderators

    Qt Creator comes with a very full-featured text editor that allows all kinds of things to happen. ;-)

    I suspect that perhaps the problem lies with a lack of understanding of some basic C++ constructs. Without that common ground, there's not a lot I can help you with, either.

    Classes are much, much more than a collection of GUI elements. If including a new method in a class is a stumbling block, then there's a lot of catching up that needs to be done at a very elementary level to make your life a bit easier doing this development.



  • [quote author="mlong" date="1312396112"]Qt Creator comes with a very full-featured text editor that allows all kinds of things to happen. ;-)

    I suspect that perhaps the problem lies with a lack of understanding of some basic C++ constructs. Without that common ground, there's not a lot I can help you with, either.

    Classes are much, much more than a collection of GUI elements. If including a new method in a class is a stumbling block, then there's a lot of catching up that needs to be done at a very elementary level to make your life a bit easier doing this development.

    [/quote]

    [quote author="Volker" date="1312395756"]Then I'm bailed out. We cannot guess, what's going on.

    I suggest, you boil down the problem to a small, yet complete and compilable test case and provide us the sources. Then we can have a look. Just add some dummy implementation for your functions.[/quote]

    Thanks guys for your help, I really appreciate it. I've decided to place all the functions inside main.cpp to avoid these errors for now, so I can move on, but I would like to learn how to fix this problem so I will revisit it later.
    So now, the errors have gone, my program builds fine without any errors, but when I run it, my gui window does not pop up and I get the following message in my output pane. I'm not sure what it means. Could you take a look please. I have tracked it down to my function int main(), but I can't see what is wrong with the function. Both the output message and my main function are below:

    @Starting /home/test/Documents/Wave-build-desktop/Wave...
    *** glibc detected *** /home/test/Documents/Wave-build-desktop/Wave: double free or corruption (!prev): 0x000000000060b580 ***
    ======= Backtrace: =========
    /lib64/libc.so.6(+0x733b6)[0x7fc7656023b6]
    /lib64/libc.so.6(cfree+0x6c)[0x7fc7656072dc]
    /home/test/Documents/Wave-build-desktop/Wave[0x405359]
    /lib64/libc.so.6(__libc_start_main+0xfd)[0x7fc7655adbfd]
    /home/test/Documents/Wave-build-desktop/Wave[0x4042b9]
    ======= Memory map: ========
    00400000-00409000 r-xp 00000000 08:03 9962313 /home/test/Documents/Wave-build-desktop/Wave
    00608000-00609000 r--p 00008000 08:03 9962313 /home/test/Documents/Wave-build-desktop/Wave
    ...
    .......@

    @int main(int argc, char *argv[])
    {

        struct option long_option[] =
        {
                {"help", 0, NULL, 'h'},
                {"device", 1, NULL, 'D'},
                {"rate", 1, NULL, 'r'},
                {"channels", 1, NULL, 'c'},
                {"frequency", 1, NULL, 'f'},
                {"buffer", 1, NULL, 'b'},
                {"period", 1, NULL, 'p'},
                {"method", 1, NULL, 'm'},
                {"format", 1, NULL, 'o'},
                {"verbose", 1, NULL, 'v'},
                {"noresample", 1, NULL, 'n'},
                {"pevent", 1, NULL, 'e'},
                {NULL, 0, NULL, 0},
        };
        int err, morehelp;
        snd_pcm_hw_params_t *hwparams;
        snd_pcm_sw_params_t *swparams;
        int method = 0;
        short int *samp;
        snd_pcm_t *h;
        snd_pcm_channel_area_t *area;
        snd_pcm_t *handle = (snd_pcm_t*) h;
        unsigned char *samples  = (unsigned char*) samp;
        unsigned int chn;
        snd_pcm_channel_area_t *areas = (snd_pcm_channel_area_t*) area;
    
        snd_pcm_hw_params_alloca(&hwparams);
        snd_pcm_sw_params_alloca(&swparams);
    
    
        err = snd_output_stdio_attach(&output, stdout, 0);
        if (err < 0) {
                printf("Output failed: %s\n", snd_strerror(err));
                return 0;
        }
    

    // cout<<"Playback device is %s "<<","<< device);
    // cout<<"Stream parameters are %iHz, %s, %i channels "<<","<< rate<<","<< snd_pcm_format_name(format), channels;
    // cout<<"Sine wave rate is %.4fHz "<<","<< freq;
    // cout<<"Using transfer method: %s "<<","<< transfer_methods[method].name;

        if ((err = snd_pcm_open(&h, device, SND_PCM_STREAM_PLAYBACK, 0)) < 0) {
                printf("Playback open error: %s\n", snd_strerror(err));
                return 0;
        }
    
        if ((err = set_hwparams(h, hwparams, transfer_methods[method].access)) < 0) {
                printf("Setting of hwparams failed: %s\n", snd_strerror(err));
                exit(EXIT_FAILURE);
        }
    
        if ((err = set_swparams(h, swparams)) < 0) {
                printf("Setting of swparams failed: %s\n", snd_strerror(err));
                exit(EXIT_FAILURE);
        }
    
        if (verbose > 0)
                snd_pcm_dump(h, output);
    
        samp = new short int [period_size * channels * snd_pcm_format_physical_width(format)];
    
    
        if (samp == NULL) {
                printf("Not enough memory\n");
                exit(EXIT_FAILURE);
        }
    
        area = new snd_pcm_channel_area_t [channels, sizeof(snd_pcm_channel_area_t)];
        if (area == NULL) {
                printf("Not enough memory\n");
                exit(EXIT_FAILURE);
        }
        for (chn = 0; chn < channels; chn++) {
                area[chn].addr = samp;
                area[chn].first = chn * snd_pcm_format_physical_width(format);
                area[chn].step = channels * snd_pcm_format_physical_width(format);
        }
    
       err = write_loop(h, samp, area);
        if (err < 0)
                printf("Transfer failed: %s\n", snd_strerror(err));
    
        delete(area);
        delete(samp);
        snd_pcm_close(h);
        return 0;
    

    QApplication a(argc, argv);
    wave w;
    w.show();

    return a.exec&#40;&#41;;
    

    }@



  • Why should it show up? You terminate main() in line 90, the program never reaches your GUI stuff on line 93 and onwards.

    For your memory error: compile the application in debug mode and run it in the debugger, it then should print where the memory corruption occurs.


  • Moderators

    It looks like you're doing all of your magic in main, then cleaning things up and calling return at line 90. That exits the program. Anything after that never gets executed (including all of your QApplication stuff.)



  • [quote author="Volker" date="1312397087"]Why should it show up? You terminate main() in line 90, the program never reaches your GUI stuff on line 93 and onwards.

    For your memory error: compile the application in debug mode and run it in the debugger, it then should print where the memory corruption occurs.[/quote]

    Thanks alot



  • [quote author="mlong" date="1312397119"]It looks like you're doing all of your magic in main, then cleaning things up and calling return at line 90. That exits the program. Anything after that never gets executed (including all of your QApplication stuff.)[/quote]

    Thanks man



  • [quote author="mlong" date="1312397119"]It looks like you're doing all of your magic in main, then cleaning things up and calling return at line 90. That exits the program. Anything after that never gets executed (including all of your QApplication stuff.)[/quote]

    [quote author="Volker" date="1312397087"]Why should it show up? You terminate main() in line 90, the program never reaches your GUI stuff on line 93 and onwards.

    For your memory error: compile the application in debug mode and run it in the debugger, it then should print where the memory corruption occurs.[/quote]

    So I commented out the return statement (as below) which exited the code to see if the gui window would pop up, but i'm still getting the exact same error and the gui window still isn't popping up. The debugger still says there is a problem with the line:
    @delete[] area;@
    however i tried debugging the program manually and i found that it runs fine and the gui window does pop up when i take out the following lines (the for loop):
    @for (chn = 0; chn < channels; chn++) {
    area[chn].addr = samp;
    area[chn].first = chn * snd_pcm_format_physical_width(format);
    area[chn].step = channels * snd_pcm_format_physical_width(format);
    }@
    I'm not sure what is wrong wit these lines

    @........
    area = new snd_pcm_channel_area_t [channels, sizeof(snd_pcm_channel_area_t)];
    if (area == NULL) {
    printf("Not enough memory\n");
    exit(EXIT_FAILURE);
    }
    for (chn = 0; chn < channels; chn++) {
    area[chn].addr = samp;
    area[chn].first = chn * snd_pcm_format_physical_width(format);
    area[chn].step = channels * snd_pcm_format_physical_width(format);
    }

       err = write_loop(h, samp, area);
        if (err < 0)
                printf("Transfer failed: %s\n", snd_strerror(err));
    
        delete[] area;
        delete[] samp;
        snd_pcm_close(h);
       // return 0;
    

    QApplication a(argc, argv);
    wave w;
    w.show();

    return a.exec&#40;&#41;;
    

    }@



  • shouldn't it be
    @
    area = new snd_pcm_channel_area_t [channels];
    @



  • [quote author="loladiro" date="1312469334"]shouldn't it be
    @
    area = new snd_pcm_channel_area_t [channels];
    @[/quote]

    Yes,
    Thanks so much. It works :)



  • Oops, i forgot to add the solution to my original problem in this thread. Its as follows:
    if getting errors: undefined reference to `snd_pcm_open etc
    Solution:
    Add the following line to the .pro file:
    @LIBS += -lasound@


Log in to reply
 

Looks like your connection to Qt Forum was lost, please wait while we try to reconnect.