2

This is my first post. I need to manipulate audios for my project so I decided to use libsnfile. I already installed it but when I try to compile any .c program with gcc somefile.c or gcc `pkg-config sndfile` somefile.c it gives me "undefined" error

/tmp/ccGTKZdy.o: En la función `convert_to_text': sndfile-to-text.c:(.text+0x193): referencia a `sf_readf_float' sin definir /tmp/ccGTKZdy.o: En la función `main': sndfile-to-text.c:(.text+0x37a): referencia a `sf_open' sin definir sndfile-to-text.c:(.text+0x3a7): referencia a `sf_strerror' sin definir sndfile-to-text.c:(.text+0x3e1): referencia a `sf_strerror' sin definir sndfile-to-text.c:(.text+0x45f): referencia a `sf_close' sin definir

Any "sf_..." function is not defined. I've read that i may have to link to the library but idk how. Help.

Mario
  • 21
  • 3

1 Answers1

1

Calling just pkg-config sndfile is not enough. It should be:

gcc somefile.c "$(pkg-config --libs --cflags sndfile)" 

And $() is recommended over backticks in command substitution these days: https://github.com/koalaman/shellcheck/wiki/SC2006.

Also remember about including libsndfile header in your program:

#include <sndfile.h>

and add -Wall -Wextra -pedantic option to make compiler report all kinds of warnings - fix your code until there are no warnings:

gcc -Wall -Wextra -pedantic somefile.c "$(pkg-config --libs --cflags sndfile)" 
Arkadiusz Drabczyk
  • 11,227
  • 2
  • 25
  • 38
  • Thank for answer but it didn't work. Still giving the same error. What else can I do? – Mario Apr 26 '20 at 20:14
  • Are you sure you have sndfile installed at all? What does `pkg-config --libs --cflags sndfile` say? – Arkadiusz Drabczyk Apr 26 '20 at 20:17
  • Im not sure if it is completed installed. That command returns this: -I/usr/local/include -L/usr/local/lib -lsndfile – Mario Apr 26 '20 at 20:19
  • ok, so it should work. Post all exact steps you do and an error message you get. BTW, change your locale to English. – Arkadiusz Drabczyk Apr 26 '20 at 20:23
  • Ok. I just changed locale to english. What i do is. 1. Enter to the examples folder that came inside the libsndfile 2. Open terminal and type export PKG_CONFIG_PATH=/usr/local/lib/pkgconfig 3. Try to compile any .c inside with gcc "$(pkg-config --libs --cflags sndfile)" -Wall -Wextra -pedantic generate.c – Mario Apr 26 '20 at 20:32
  • Then I get the following error message: /tmp/ccsxPgxv.o: In function `encode_file': generate.c:(.text+0x23b): undefined reference to `sf_open' generate.c:(.text+0x268): undefined reference to `sf_strerror' generate.c:(.text+0x28c): undefined reference to `sf_format_check' generate.c:(.text+0x29c): undefined reference to `sf_close' generate.c:(.text+0x2c2): undefined reference to `sf_open' generate.c:(.text+0x2ef): undefined reference to `sf_strerror' generate.c:(.text+0x31a): undefined re (...) collect2: error: ld returned 1 exit status – Mario Apr 26 '20 at 20:32
  • Hmm, what does `file $(readlink -e /usr/lib64/libsndfile.so)` say? – Arkadiusz Drabczyk Apr 26 '20 at 20:38
  • Let us [continue this discussion in chat](https://chat.stackoverflow.com/rooms/212576/discussion-between-mario-and-arkadiusz-drabczyk). – Mario Apr 26 '20 at 20:39