为什么当库的其余部分加载正常时此符号未定义为体系结构 x86_64?

Why is this symbol undefined for architecture x86_64 when the rest of the library loaded fine?

我正在尝试使用 open source library 来读取 C++ 中的 wav/mp3 文件,但是当我尝试对所述库使用 init 函数时无法编译它。当我 运行 cmake --build . --config Release 我得到:

Undefined symbols for architecture x86_64:
  "_drwav_init_file", referenced from:
      _main in audiotests.cpp.o
ld: symbol(s) not found for architecture x86_64

我的 运行 代码目前非常简单,只是开始尝试与这个库交互。

#include "dr_libs/dr_wav.h"
...

int main()
{
    drwav m_wavFile;
    drwav_init_file(&m_wavFile, "song.wav", NULL);
}

但我无法编译它。它每次都无法构建。我一定是遗漏了一些非常明显的东西……想法?

来自您正在使用的库的文档:

This is a single file library. To use it, do something like the following in one .c file.

#define DR_WAV_IMPLEMENTATION
#include "dr_wav.h"

看来你错过了那个。这是一种将实现捆绑在一个翻译单元中并使 header(在本例中为 dr_wav.h)与这些定义保持一致的常用技术。