0

I had a segment error while running "Sample Async Playback" provided by "pulseaudio"。 but my compilation passed. enter image description here Compile the way

gcc pa-beep.c -lpulse-simple -shared -fPIC -g

Here's Contains library files

#include <stdio.h>
#include <string.h>
#include <pulse/pulseaudio.h>

static int latency = 20000; // start latency in micro seconds
static int sampleoffs = 0;
static short sampledata[300000];
static pa_buffer_attr bufattr;
static int underflows = 0;
static pa_sample_spec ss;

I added the print step inside the main function, and the result shows that the program did not execute this step.

int main(int argc, char *argv[]) {
  printf("kai shi\n");
  pa_mainloop *pa_ml;
  pa_mainloop_api *pa_mlapi;
  pa_context *pa_ctx;
  pa_stream *playstream;

I'm sorry I'm a beginner. I don't know how to solve this problem

Jabberwocky
  • 48,281
  • 17
  • 65
  • 115
龙傲天
  • 1
  • 3
  • Segment error is a run time error not compile time error. Please read https://stackoverflow.com/help/how-to-ask – betontalpfa Oct 18 '18 at 13:15
  • 1
    You forgot `#include `. Try and report back and tell us what happened. This may or may not resolve your problem. BTW: when you see a warning containing the word "implicit declaration", consider it as an error. – Jabberwocky Oct 18 '18 at 13:21
  • Thank you. It's true that segmentation errors only occur when it's running. Doesn't the program start with the main function?It turns out that printf has a segment error before it even gets executed, and I'm confused – 龙傲天 Oct 18 '18 at 13:22
  • 1
    Please [edit] your program and show a [mcve]. – Jabberwocky Oct 18 '18 at 13:22
  • 1
    This is a good time to start learning to use a debugger. https://stackoverflow.com/questions/25385173/what-is-a-debugger-and-how-can-it-help-me-diagnose-problems Try to run your program with `gdb` and see where and why it aborts. Remember to compile your program with debugging symbols (`-g`) to actually see something of your code. – hellow Oct 18 '18 at 13:23
  • 1
    Also `static short sampledata[300000];` might be a problem. Change temporarily to `static short sampledata[300];` and put `return 1;` right after `printf("kai shi\n");` and see if "kai shi" is displayed. – Jabberwocky Oct 18 '18 at 13:26
  • After the change, it is still not shown, and it is still a segmentation error – 龙傲天 Oct 18 '18 at 13:35
  • 而且我在虚拟机内运行此程序也是如此,同样第一步打印都没执行 – 龙傲天 Oct 18 '18 at 13:52
  • Then it could be a problem with your platform. Does a a simple "Hello World" program run correctly? – Jabberwocky Oct 18 '18 at 14:02
  • 应该不是平台的问问题吧,我用VMware上的Ubuntu也是这个现象,,说实话,我很痛苦 – 龙傲天 Oct 18 '18 at 14:05

0 Answers0