LinuxQuestions.org

LinuxQuestions.org (/questions/)
-   Programming (https://www.linuxquestions.org/questions/programming-9/)
-   -   vorbisfile - segmentation fault (https://www.linuxquestions.org/questions/programming-9/vorbisfile-segmentation-fault-703949/)

Jordan&&&& 02-11-2009 01:35 PM

vorbisfile - segmentation fault
 
I am trying to write a simple program that uses vorbisfile shared library. But I get a segmentation error when I execute my program. My code is:

Code:

#include <iostream>
using namespace std;

#include <ogg/ogg.h>
#include <vorbis/codec.h>
#include <vorbis/vorbisenc.h>
#include <vorbis/vorbisfile.h>

int main() {
   
    OggVorbis_File * song;
    vorbis_info * songInfo;

    int result = ov_fopen("./song.ogg", song);
    if (result!=0){
            cout<<"failed";
            return 1;
    }

    ...
   
    return 0;
}

I am compiling the program with the following line:

g++ -lvorbisfile ogg.cpp

and I receive a Segmentation fault error if the song exists when the application is run. Can you help me with this?

fantas 02-12-2009 08:48 AM

The error is that you pass an uninitialized pointer to an 'OggVorbis_File' object, while the function expects an already existing object of this kind.
The following should get you closer to what you want:

Code:

OggVorbis_File song;

int result = ov_fopen("./song.ogg", &song);

// ...



All times are GMT -5. The time now is 11:24 PM.