无法链接我自己的静态库
Unable to link my own static libraries
我正试图在windows中为GLFW/ONGL项目添加一个声音库。我已经将声音项目设置为输出静态库(.lib)。它编译得很好。
在我的主要项目中,我添加了对Sound的引用和对Sound的依赖(以更改构建顺序)。我在我的main.cpp中包含了"..\Sound\Sound.h",Intellisense对一切都很满意。所有的编译都很好。然而,链接器很生气:
1>Link:
1> LINK : ###ProjectsDeathRaceDebugDeathRace.exe not found or not built by the last incremental link; performing full link
1>Sound.lib(sound.obj) : error LNK2038: mismatch detected for '_ITERATOR_DEBUG_LEVEL': value '2' doesn't match value '0' in base_objects.obj
1>LINK : warning LNK4098: defaultlib 'MSVCRTD' conflicts with use of other libs; use /NODEFAULTLIB:library
1>Sound.lib(sound.obj) : error LNK2019: unresolved external symbol __imp__alListenerfv referenced in function "public: bool __thiscall SoundAPI::Startup(void)" (?Startup@SoundAPI@@QAE_NXZ)
1>Sound.lib(sound.obj) : error LNK2019: unresolved external symbol __imp__alListener3f referenced in function "public: bool __thiscall SoundAPI::Startup(void)" (?Startup@SoundAPI@@QAE_NXZ)
1>Sound.lib(sound.obj) : error LNK2019: unresolved external symbol __imp__alGetError referenced in function "public: bool __thiscall SoundAPI::Startup(void)" (?Startup@SoundAPI@@QAE_NXZ)
1>Sound.lib(sound.obj) : error LNK2019: unresolved external symbol __imp__alutGetError referenced in function "public: bool __thiscall SoundAPI::Startup(void)" (?Startup@SoundAPI@@QAE_NXZ)
1>Sound.lib(sound.obj) : error LNK2019: unresolved external symbol __imp__alutInit referenced in function "public: bool __thiscall SoundAPI::Startup(void)" (?Startup@SoundAPI@@QAE_NXZ)
1>Sound.lib(sound.obj) : error LNK2019: unresolved external symbol __imp__alutExit referenced in function "public: bool __thiscall SoundAPI::Shutdown(void)" (?Shutdown@SoundAPI@@QAE_NXZ)
1>Sound.lib(sound.obj) : error LNK2019: unresolved external symbol __imp__alDeleteBuffers referenced in function "public: bool __thiscall SoundAPI::Shutdown(void)" (?Shutdown@SoundAPI@@QAE_NXZ)
1>Sound.lib(sound.obj) : error LNK2019: unresolved external symbol __imp__alDeleteSources referenced in function "public: bool __thiscall SoundAPI::Shutdown(void)" (?Shutdown@SoundAPI@@QAE_NXZ)
1>Sound.lib(sound.obj) : error LNK2019: unresolved external symbol __imp__alutCreateBufferFromFile referenced in function "public: unsigned int * __thiscall SoundAPI::LoadSound(class std::basic_string<char,struct std::char_traits<char>,class std::allocator<char> >)" (?LoadSound@SoundAPI@@QAEPAIV?$basic_string@DU?$char_traits@D@std@@V?$allocator@D@2@@std@@@Z)
1>Sound.lib(sound.obj) : error LNK2019: unresolved external symbol __imp__alSourcei referenced in function "public: unsigned int * __thiscall SoundAPI::CreateSource(void)" (?CreateSource@SoundAPI@@QAEPAIXZ)
1>Sound.lib(sound.obj) : error LNK2019: unresolved external symbol __imp__alSource3f referenced in function "public: unsigned int * __thiscall SoundAPI::CreateSource(void)" (?CreateSource@SoundAPI@@QAEPAIXZ)
1>Sound.lib(sound.obj) : error LNK2019: unresolved external symbol __imp__alSourcef referenced in function "public: unsigned int * __thiscall SoundAPI::CreateSource(void)" (?CreateSource@SoundAPI@@QAEPAIXZ)
1>Sound.lib(sound.obj) : error LNK2019: unresolved external symbol __imp__alGenSources referenced in function "public: unsigned int * __thiscall SoundAPI::CreateSource(void)" (?CreateSource@SoundAPI@@QAEPAIXZ)
1>Sound.lib(sound.obj) : error LNK2019: unresolved external symbol __imp__alSourceQueueBuffers referenced in function "public: bool __thiscall SoundAPI::Queue(unsigned int *,unsigned int *)" (?Queue@SoundAPI@@QAE_NPAI0@Z)
1>Sound.lib(sound.obj) : error LNK2019: unresolved external symbol __imp__alSourcePlay referenced in function "public: bool __thiscall SoundAPI::Play(unsigned int *)" (?Play@SoundAPI@@QAE_NPAI@Z)
1>Sound.lib(sound.obj) : error LNK2019: unresolved external symbol __imp__alSourcePause referenced in function "public: bool __thiscall SoundAPI::Pause(unsigned int *)" (?Pause@SoundAPI@@QAE_NPAI@Z)
1>Sound.lib(sound.obj) : error LNK2019: unresolved external symbol __imp__alSourceStop referenced in function "public: bool __thiscall SoundAPI::Stop(unsigned int *)" (?Stop@SoundAPI@@QAE_NPAI@Z)
1>###ProjectsDeathRaceDebugDeathRace.exe : fatal error LNK1120: 17 unresolved externals
我不知道该怎么办。Lnk2038应该意味着调试和发布之间的问题,但一切都处于调试模式。lnk2019对Sound.lib应该没问题吗?
非常感谢!
您的库一切正常(除了混合调试和发布运行时)。在调试模式下生成程序时,必须链接调试生成。发布版本也是如此。这是针对错误LNK2038
和警告LNK4098
的。
其他错误是由一个简单的事实引起的,即您不能将静态库与静态库(此处:OpenAL)链接,因为如果两个静态库引用同一静态代码(本质上导致多个定义),这将变得格外复杂。
要解决这些错误,您需要做的很简单:将生成的可执行文件链接到您自己的Sound.lib
以及正确的OpenAL库文件,一切都会好起来。
相关文章:
- C++从另一个类访问公共静态向量的正确方法是什么
- 没有为自己的结构调用列表推回方法
- 类无法访问自己的私有静态 constexpr 方法 - Clang bug?
- 创建自己的owner_ptr类;在传递堆栈或静态分配的地址时如何避免UB?
- 访问另一个类(系统)的非静态字段,就好像它是我自己的字段一样 - 优雅地
- 如何在每个共享库中使用自己的静态库副本
- 链接器没有链接我自己的静态库
- javascript中的静态私有变量用于自己的库
- 如何将 DirectX 库包含在我自己的静态库(独立库)中
- 一个类不能有自己的静态 constexpr 成员实例吗?
- 在您自己的Qt应用程序中使用您自己的静态库
- 在元素自己的析构函数中擦除指向静态向量中元素的指针
- 类自己的类型的静态类成员
- 由于忘记了源文件,在链接我自己的静态库时检测未解析的符号
- 无法链接我自己的静态库
- Linker正在寻找链接到我自己的静态库的静态库
- 链接我自己的静态库时,无法解析的外部符号
- 静态库-使用自己的Qt .so文件的静态库
- 每个文件都有自己的静态变量副本吗?
- 在我自己的操作系统内核上的c++静态构造函数