c++ - 在 linux 上链接 FMOD 库时 undefined reference

标签 c++ linux reference undefined fmod

我正在使用 C++ 在 Linux 上创建一个简单的游戏,并使用 FMOD 来制作声音。我最近下载了最新的 FMOD API,但是当我尝试使用它时,出现 undefined reference 错误。从我看到的其他相关问题来看,它通常与编译时 -lfmod 标记的位置有关,但是无论我将该标记放在哪里,我仍然会遇到问题。

我按照 Debian 说明下载了 FMOD api 和库。
https://wiki.debian.org/FMOD
但是,当 -I/usr/local/include -L/usr/local/lib 不起作用时,我将所有库和头文件移动到本地文件夹并进行相应调整。
如果有帮助的话,我正在 x86_64 架构上使用 Debian。

我在这里也遵循了这些说明
https://www.fmod.com/docs/api/content/generated/platform_linux/basics.html
使用 ldconfig 我能够验证我确实在/usr/lib/x86_64-linux-gnu/中下载了 libasound.so.2

我知道这个答案
C++:Undefined reference to 'FMOD:: X'
但是因为我是使用 G++ 编译的,而 FMOD linux 库是使用 GCC 编译的,所以我认为应该没有问题。

这是我在编译时遇到的错误。

g++ -c audioEngine.cpp
g++ driver.o game.o uiInteract.o uiDraw.o audioEngine.o point.o velocity.o flyingObject.o ship.o bullet.o rocks.o pause.o keyBind.o asteroid.o -I/usr/local/include -L/usr/local/lib -lfmod -lglut -lGLU -lGL
audioEngine.o: In function `Implementation::Implementation()':
audioEngine.cpp:(.text+0x67): undefined reference to `FMOD::Studio::System::create(FMOD::Studio::System**, unsigned int)'
audioEngine.cpp:(.text+0x92): undefined reference to `FMOD::Studio::System::initialize(int, unsigned int, unsigned int, void*)'
audioEngine.cpp:(.text+0xbf): undefined reference to `FMOD::Studio::System::getLowLevelSystem(FMOD::System**) const'
audioEngine.o: In function `Implementation::~Implementation()':
audioEngine.cpp:(.text+0x13b): undefined reference to `FMOD::Studio::System::unloadAll()'
audioEngine.cpp:(.text+0x151): undefined reference to `FMOD::Studio::System::release()'
audioEngine.o: In function `Implementation::advance()':
audioEngine.cpp:(.text+0x2cf): undefined reference to `FMOD::Studio::System::update()'
collect2: error: ld returned 1 exit status
makefile:21: recipe for target 'a.out' failed
make: *** [a.out] Error 1

这是 audioEngine.cpp 中的问题区域
在头文件中包含“fmod.hpp”和“fmod_studio.hpp”。

Implementation::Implementation()
{
  mpStudioSystem = NULL;
  AudioEngine::ErrorCheck(FMOD::Studio::System::create(&mpStudioSystem));
  AudioEngine::ErrorCheck(mpStudioSystem->initialize(32, FMOD_STUDIO_INIT_LIVEUPDATE, FMOD_INIT_PROFILE_ENABLE, NULL));

  mpSystem = NULL;
  AudioEngine::ErrorCheck(mpStudioSystem->getLowLevelSystem(&mpSystem));
}

Implementation::~Implementation()
{
  AudioEngine::ErrorCheck(mpStudioSystem->unloadAll());
  AudioEngine::ErrorCheck(mpStudioSystem->release());
}

void Implementation::advance()
{
  vector<ChannelMap::iterator> pStoppedChannels;
  for (auto it = mChannels.begin(), itEnd = mChannels.end(); it != itEnd; ++it)
  {
    bool bIsPlaying = false;
    it->second->isPlaying(&bIsPlaying);
    if (!bIsPlaying)
    {
      pStoppedChannels.push_back(it);
    }
  }
  for (auto& it : pStoppedChannels)
  {
    mChannels.erase(it);
  }
  AudioEngine::ErrorCheck(mpStudioSystem->update());
}

这里是makefile的相关部分

LFLAGS = -I./include -L./lib -lfmod -lglut -lGLU -lGL

###############################################################
# Build the main game
###############################################################
a.out: driver.o game.o uiInteract.o uiDraw.o audioEngine.o point.o velocity.o flyingObject.o ship.o bullet.o rocks.o pause.o keyBind.o asteroid.o
    g++ driver.o game.o uiInteract.o uiDraw.o audioEngine.o point.o velocity.o flyingObject.o ship.o bullet.o rocks.o pause.o keyBind.o asteroid.o $(LFLAGS)

.so 库文件位于 makefile 所在项目文件夹的“lib”文件夹中,.h 和 .hpp 文件位于同一位置的“include”文件夹中。

最佳答案

我在发布之前意识到了这个问题的答案,但我花了足够的时间试图弄清楚如果其他人遵循 Debian 说明并想知道为什么他们得到一个 undefined reference ,我无论如何都会冒充以供将来引用。

如果您包含“fmod_studio.hpp”文件,您还需要包含 fmod studio 库。在 -lfmod 之后添加 -lfmodstudio 并且如果您的其他一切都正确,它现在将在没有 undefined reference 的情况下编译。

解决方案非常明显,我觉得自己像个白痴。当然,如果我想要 fmodstudio,我需要包含 fmodstudio 库!这就像我在没有发动机的情况下踩下 throttle 然后检查机油。

关于c++ - 在 linux 上链接 FMOD 库时 undefined reference ,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/51300865/

相关文章:

linux - 第一次执行后自行删除的脚本

linux - 使用perl cgi在网页上显示命令输出

linux - 如何在 CentOS 6 上升级到 CouchDB 1.3.0+?

rust - 为什么不能在同一结构中存储值和对该值的引用?

asp.net-mvc-3 - Asp.net MVC3 从 Razor View 访问内部类

java - Java 中的引用是如何工作的?

c++ - 在模板类中声明一个结构,未为成员函数定义

c++ - 如何使用 std::bind?

python - 从 C++ 调用 Python 函数

c++ - 使用 tr2::direct_bases 获取结果的第 n 个元素