首页
学习
活动
专区
圈层
工具
发布
首页
学习
活动
专区
圈层
工具
MCP广场
社区首页 >问答首页 >在linux上链接FMOD库时未定义的引用

在linux上链接FMOD库时未定义的引用
EN

Stack Overflow用户
提问于 2018-07-12 08:35:07
回答 1查看 984关注 0票数 0

我正在C++中的linux上创建一个简单的游戏,并使用FMOD作为声音。我最近下载了最新的FMOD,但是当我尝试使用它时,我会得到一个未定义的引用错误。从其他相关问题中我可以看到,它通常与编译时-lfmod标记的位置有关,然而,无论我将该标记放在何处,我仍然会遇到问题。

我按照Debian指令下载FMOD和库。

https://wiki.debian.org/FMOD

但是,当-I/usr/local/include -L/usr/local/lib不能工作时,我将所有库和头文件移到本地文件夹中,并进行了相应的调整。

我正在x86_64架构上使用Debian,如果这有帮助的话。

我在这里也遵循了这些指示

linux/basics.html

使用ldconfig,我能够验证我是否在/usr/lib/x86_64-linux-gnu/中下载了libasound.so.2。

我知道这个答案

C++:Undefined reference to 'FMOD:: X'

但是因为我是用G++编译的,而FMOD linux库是用GCC编译的,所以我不认为会有问题。

以下是编译时遇到的错误。

代码语言:javascript
运行
复制
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”。

代码语言:javascript
运行
复制
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的相关部分

代码语言:javascript
运行
复制
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”文件夹中。

EN

回答 1

Stack Overflow用户

回答已采纳

发布于 2018-07-12 08:48:15

在发帖之前,我意识到了这个问题的答案,但我花了足够的时间试图弄清楚,如果其他人遵循Debian的指示,为什么他们会得到一个未定义的引用,那么我无论如何都会为将来的参考而摆姿势。

如果您正在包括"fmod_studio.hpp“文件,您还需要包括fmod工作室库。在-lfmodstudio之后添加-lfmod,如果您拥有其他所有正确的内容,那么它现在将编译而不需要一个未定义的引用。

解决办法很明显,我觉得自己像个白痴。当然,如果我想要fmodstudio,我需要包括fmodstudio库!就像我在没有引擎的情况下踩油门,然后检查油门。

票数 0
EN
页面原文内容由Stack Overflow提供。腾讯云小微IT领域专用引擎提供翻译支持
原文链接:

https://stackoverflow.com/questions/51300865

复制
相关文章

相似问题

领券
问题归档专栏文章快讯文章归档关键词归档开发者手册归档开发者手册 Section 归档