0

i have tried to follow this method of reading an audio file into a variable. But i get the following errors:

/tmp/ccvlnwCI.o: In function `main':
debug_snd.cpp:(.text+0x7b): undefined reference to `sf_open'
debug_snd.cpp:(.text+0xc0): undefined reference to `sf_close'
debug_snd.cpp:(.text+0xec): undefined reference to `sf_open'
debug_snd.cpp:(.text+0x140): undefined reference to `sf_close'
debug_snd.cpp:(.text+0x16b): undefined reference to `sf_read_double'
debug_snd.cpp:(.text+0x1ee): undefined reference to `sf_write_double'
debug_snd.cpp:(.text+0x202): undefined reference to `sf_close'
debug_snd.cpp:(.text+0x211): undefined reference to `sf_close'
collect2: error: ld returned 1 exit status

What i have tried so far to resolve this:

$ sudo apt-get install -y libsndfile-dev
Reading package lists... Done
Building dependency tree
Reading state information... Done
Note, selecting 'libsndfile1-dev' instead of 'libsndfile-dev'
libsndfile1-dev is already the newest version (1.0.25-10ubuntu0.16.04.2).
0 upgraded, 0 newly installed, 0 to remove and 409 not upgraded.

$ sudo apt-get install -y libsndfile1-dev
Reading package lists... Done
Building dependency tree
Reading state information... Done
libsndfile1-dev is already the newest version (1.0.25-10ubuntu0.16.04.2).
0 upgraded, 0 newly installed, 0 to remove and 409 not upgraded.

$ sudo apt-get install -y libsndfile1
Reading package lists... Done
Building dependency tree
Reading state information... Done
libsndfile1 is already the newest version (1.0.25-10ubuntu0.16.04.2).
0 upgraded, 0 newly installed, 0 to remove and 409 not upgraded.

$ sudo apt-get install -y libsndfile
Reading package lists... Done
Building dependency tree
Reading state information... Done
E: Unable to locate package libsndfile

I also tried this: But it is mainly trying to write them into a file, not store as a variable

This is on windows, using a GUI, but i am running in a linux terminal, so i can't work with that.

leonardltk1
  • 257
  • 1
  • 4
  • 18
  • 2
    How do you link your program? You should pass ``pkg-config --libs sndfile`` when linking and ``pkg-config --cflags sndfile`` when compiling. – Erlkoenig Jul 14 '20 at 08:54
  • Having installed the right libraries on your system is not enough. - You also have to link the libraries to your application. Please, provide the compile/link commands you use to compile your code. – Scheff's Cat Jul 14 '20 at 08:55
  • FYI: [SO: What is an undefined reference/unresolved external symbol error and how do I fix it?](https://stackoverflow.com/q/12573816/7478597) ;-) – Scheff's Cat Jul 14 '20 at 08:56
  • @Erlkoenig so i just run these two commands on the terminal ? – leonardltk1 Jul 14 '20 at 09:58
  • 1
    No. You have to pass their output to the compiler command line, so you'd put them into the Makefile. See [here](https://en.wikipedia.org/wiki/Pkg-config). Add `$(pkg-config --libs sndfile)` to the linking command line and `$(pkg-config --cflags sndfile)` to the compiling command line. – Erlkoenig Jul 14 '20 at 10:01
  • Does this answer your question? [What is an undefined reference/unresolved external symbol error and how do I fix it?](https://stackoverflow.com/questions/12573816/what-is-an-undefined-reference-unresolved-external-symbol-error-and-how-do-i-fix) – Botje Jul 14 '20 at 14:11

1 Answers1

0

as @Erlkoenig mentioned, i just needed to add in $(pkg-config --libs sndfile).

g++ -std=c++11 "./ReadWavFile.cpp" $(pkg-config --libs --cflags sndfile)
leonardltk1
  • 257
  • 1
  • 4
  • 18