D
D
Dobroe3lo2019-08-23 15:06:34
linux
Dobroe3lo, 2019-08-23 15:06:34

Error while compiling undefined reference to?

Compiling throws the following error. What could be the problem? Linux
Part of the code
in the header

#include <stdio.h>
#include <unistd.h>
#include <string.h>
#include <errno.h>
#include <fcntl.h>
#include <stdlib.h>
#include <fcntl.h>
#include <netinet/tcp.h>
#include <sys/socket.h>
#include <sys/types.h>
#include <netinet/in.h>
#include <netdb.h>
#include <pulse/simple.h>
#include <pulse/error.h>

static const pa_sample_spec ss = {
    .format = PA_SAMPLE_ULAW,
    .rate = 8000,
    .channels = 1
};

pa_simple *s_in, *s_out = NULL;
int ret = 1;
int error;


/* Create a new playback stream */
if (!(s_out = pa_simple_new(NULL, argv[0], PA_STREAM_PLAYBACK, NULL, "playback", &ss, NULL, NULL, &error))) {
    fprintf(stderr, __FILE__": pa_simple_new() failed: %s\n", strerror(errno));
    goto finish;
}

  if (!(s_in = pa_simple_new(NULL, argv[0], PA_STREAM_RECORD, NULL, "record", &ss, NULL, NULL, &error))) {
    fprintf(stderr, __FILE__": pa_simple_new() failed: %s\n", strerror(errno));
    goto finish;
}

for (;;) {
    uint8_t buf[BUFSIZE];
    ssize_t r;

    if (pa_simple_read(s_in, buf, sizeof(buf), &error) < 0) {

        fprintf(stderr, __FILE__": read() failed: %s\n", strerror(errno));
        goto finish;
    }

    if(write(fd, buf, BUFSIZE) != BUFSIZE)
            printf("\nErr\n");
    if(write(fd, audio, 7) != 7)
            printf("\nErr\n");*/
    
    if (pa_simple_write(s_out, buf, sizeof(buf), &error) < 0) {
        fprintf(stderr, __FILE__": pa_simple_write() failed: %s\n", strerror(errno));
        goto finish;
    }
}

/* Make sure that every single sample was played */
if (pa_simple_drain(s_out, &error) < 0) {
    fprintf(stderr, __FILE__": pa_simple_drain() failed: %s\n", strerror(errno));
    goto finish;
}

ret = 0;

finish:

if(fd){
    shutdown(fd, SHUT_RDWR);
    close(fd); 
}

if (s_in)
    pa_simple_free(s_in);
if (s_out)
    pa_simple_free(s_out);

return ret;
}

Mistake
cgiplay_AudioOut_HTTP.cpp:(.text+0x22b): undefined reference to `pa_simple_new'
cgiplay_AudioOut_HTTP.cpp:(.text+0x2b5): undefined reference to `pa_simple_new'
cgiplay_AudioOut_HTTP.cpp:(.text+0x325): undefined reference to `pa_simple_read'
cgiplay_AudioOut_HTTP.cpp:(.text+0x3ea): undefined reference to `pa_simple_write'
cgiplay_AudioOut_HTTP.cpp:(.text+0x463): undefined reference to `pa_simple_free'
cgiplay_AudioOut_HTTP.cpp:(.text+0x47c): undefined reference to `pa_simple_free'
collect2: error: ld returned 1 exit status

Answer the question

In order to leave comments, you need to log in

1 answer(s)
T
tsarevfs, 2019-08-23
@tsarevfs

The compiler found header files (.h) with function declarations, but then the linker wants to find implementations of these functions (.so or .a files).
How do you assemble the program?

Didn't find what you were looking for?

Ask your question

Ask a Question

731 491 924 answers to any question