gpt4 book ai didi

c++ - 编译 SFML 时链接 'static libraries' 的顺序是什么?

转载 作者:行者123 更新时间:2023-11-30 02:21:57 28 4
gpt4 key购买 nike

我是 SFML 库的新手。我正在尝试编译示例程序。

我从 SFML 官方文档中得到了以下示例代码:

#include <SFML/Audio.hpp>
#include <SFML/Graphics.hpp>

int main()
{
// Create the main window
sf::RenderWindow window(sf::VideoMode(800, 600), "SFML window");
// Load a sprite to display
sf::Texture texture;
if (!texture.loadFromFile("cute_image.jpg"))
return EXIT_FAILURE;
sf::Sprite sprite(texture);
// Create a graphical text to display
sf::Font font;
if (!font.loadFromFile("arial.ttf"))
return EXIT_FAILURE;
sf::Text text("Hello SFML", font, 50);
// Load a music to play
sf::Music music;
if (!music.openFromFile("nice_music.ogg"))
return EXIT_FAILURE;
// Play the music
music.play();
// Start the game loop
while (window.isOpen())
{
// Process events
sf::Event event;
while (window.pollEvent(event))
{
// Close window: exit
if (event.type == sf::Event::Closed)
window.close();
}
// Clear screen
window.clear();
// Draw the sprite
window.draw(sprite);
// Draw the string
window.draw(text);
// Update the window
window.display();
}
return EXIT_SUCCESS;
}

我试着用下面的命令编译它:

g++.exe code.cpp -s -lsfml-main -lsfml-audio-s -lflac \
-lvorbisenc -lvorbisfile -lvorbis -logg -lsfml-network-s \
-lws2_32 -lsfml-graphics-s -lfreetype -lglew32 -ljpeg \
-lsfml-window-s -lopengl32 -lgdi32 -lsfml-system-s -lwinmm \
-lgdi32 -luser32 -lkernel32 -lcomctl32 -lmingw32 \
-luser32 -lgdi32 -ldxguid -mwindows \
-std=c++11 -o code.exe

但是我遇到了这些链接器错误(路径缩短):

../lib32/libsfml-audio-s.a(SoundStream.cpp.obj):SoundStream.cpp:(.text+0x6de): undefined reference to `_imp__alSourcePlay'
../lib32/libsfml-audio-s.a(SoundStream.cpp.obj):SoundStream.cpp:(.text+0x7c8): undefined reference to `_imp__alSourcePause'
../lib32/libsfml-audio-s.a(SoundStream.cpp.obj):SoundStream.cpp:(.text+0xa66): undefined reference to `_imp__alGetSourcef'
../lib32/libsfml-audio-s.a(SoundStream.cpp.obj):SoundStream.cpp:(.text+0xb7a): undefined reference to `_imp__alBufferData'
../lib32/libsfml-audio-s.a(SoundStream.cpp.obj):SoundStream.cpp:(.text+0xb96): undefined reference to `_imp__alSourceQueueBuffers'
../lib32/libsfml-audio-s.a(SoundStream.cpp.obj):SoundStream.cpp:(.text+0xc9d): undefined reference to `_imp__alBufferData'
../lib32/libsfml-audio-s.a(SoundStream.cpp.obj):SoundStream.cpp:(.text+0xcb9): undefined reference to `_imp__alSourceQueueBuffers'
../lib32/libsfml-audio-s.a(SoundStream.cpp.obj):SoundStream.cpp:(.text+0xdd8): undefined reference to `_imp__alGenBuffers'
../lib32/libsfml-audio-s.a(SoundStream.cpp.obj):SoundStream.cpp:(.text+0xdfd): undefined reference to `_imp__alSourcePlay'
../lib32/libsfml-audio-s.a(SoundStream.cpp.obj):SoundStream.cpp:(.text+0xed0): undefined reference to `_imp__alGetSourcei'
../lib32/libsfml-audio-s.a(SoundStream.cpp.obj):SoundStream.cpp:(.text+0xf0b): undefined reference to `_imp__alSourceUnqueueBuffers'
../lib32/libsfml-audio-s.a(SoundStream.cpp.obj):SoundStream.cpp:(.text+0xfed): undefined reference to `_imp__alGetBufferi'
../lib32/libsfml-audio-s.a(SoundStream.cpp.obj):SoundStream.cpp:(.text+0x100a): undefined reference to `_imp__alGetBufferi'
../lib32/libsfml-audio-s.a(SoundStream.cpp.obj):SoundStream.cpp:(.text+0x1160): undefined reference to `_imp__alSourceStop'
../lib32/libsfml-audio-s.a(SoundStream.cpp.obj):SoundStream.cpp:(.text+0x1180): undefined reference to `_imp__alGetSourcei'
../lib32/libsfml-audio-s.a(SoundStream.cpp.obj):SoundStream.cpp:(.text+0x11b8): undefined reference to `_imp__alSourceUnqueueBuffers'
../lib32/libsfml-audio-s.a(SoundStream.cpp.obj):SoundStream.cpp:(.text+0x11ef): undefined reference to `_imp__alSourcei'
../lib32/libsfml-audio-s.a(SoundStream.cpp.obj):SoundStream.cpp:(.text+0x1204): undefined reference to `_imp__alDeleteBuffers'
../lib32/libsfml-audio-s.a(SoundStream.cpp.obj):SoundStream.cpp:(.text+0x126d): undefined reference to `_imp__alSourcePause'
../lib32/libsfml-audio-s.a(SoundStream.cpp.obj):SoundStream.cpp:(.text+0x12e7): undefined reference to `_imp__alGetSourcei'
../lib32/libsfml-audio-s.a(SoundStream.cpp.obj):SoundStream.cpp:(.text+0x12f1): undefined reference to `_imp__alSourceUnqueueBuffers'
../lib32/libsfml-audio-s.a(AudioDevice.cpp.obj):AudioDevice.cpp:(.text+0xe): undefined reference to `_imp__alcOpenDevice'
../lib32/libsfml-audio-s.a(AudioDevice.cpp.obj):AudioDevice.cpp:(.text+0x2c): undefined reference to `_imp__alcCreateContext'
../lib32/libsfml-audio-s.a(AudioDevice.cpp.obj):AudioDevice.cpp:(.text+0x42): undefined reference to `_imp__alcMakeContextCurrent'
../lib32/libsfml-audio-s.a(AudioDevice.cpp.obj):AudioDevice.cpp:(.text+0x9b): undefined reference to `_imp__alListenerf'
../lib32/libsfml-audio-s.a(AudioDevice.cpp.obj):AudioDevice.cpp:(.text+0xc6): undefined reference to `_imp__alListener3f'
../lib32/libsfml-audio-s.a(AudioDevice.cpp.obj):AudioDevice.cpp:(.text+0xdb): undefined reference to `_imp__alListenerfv'
../lib32/libsfml-audio-s.a(AudioDevice.cpp.obj):AudioDevice.cpp:(.text+0x19c): undefined reference to `_imp__alcMakeContextCurrent'
../lib32/libsfml-audio-s.a(AudioDevice.cpp.obj):AudioDevice.cpp:(.text+0x1ae): undefined reference to `_imp__alcDestroyContext'
../lib32/libsfml-audio-s.a(AudioDevice.cpp.obj):AudioDevice.cpp:(.text+0x1c0): undefined reference to `_imp__alcCloseDevice'
../lib32/libsfml-audio-s.a(AudioDevice.cpp.obj):AudioDevice.cpp:(.text+0x1f9): undefined reference to `_imp__alListenerf'
../lib32/libsfml-audio-s.a(AudioDevice.cpp.obj):AudioDevice.cpp:(.text+0x24e): undefined reference to `_imp__alListener3f'
../lib32/libsfml-audio-s.a(AudioDevice.cpp.obj):AudioDevice.cpp:(.text+0x2e4): undefined reference to `_imp__alListenerfv'
../lib32/libsfml-audio-s.a(AudioDevice.cpp.obj):AudioDevice.cpp:(.text+0x384): undefined reference to `_imp__alListenerfv'
../lib32/libsfml-audio-s.a(AudioDevice.cpp.obj):AudioDevice.cpp:(.text+0x445): undefined reference to `_imp__alGetEnumValue'
../lib32/libsfml-audio-s.a(AudioDevice.cpp.obj):AudioDevice.cpp:(.text+0x47d): undefined reference to `_imp__alcMakeContextCurrent'
../lib32/libsfml-audio-s.a(AudioDevice.cpp.obj):AudioDevice.cpp:(.text+0x48f): undefined reference to `_imp__alcDestroyContext'
../lib32/libsfml-audio-s.a(AudioDevice.cpp.obj):AudioDevice.cpp:(.text+0x4a9): undefined reference to `_imp__alcCloseDevice'
../lib32/libsfml-audio-s.a(AudioDevice.cpp.obj):AudioDevice.cpp:(.text+0x501): undefined reference to `_imp__alGetEnumValue'
../lib32/libsfml-audio-s.a(AudioDevice.cpp.obj):AudioDevice.cpp:(.text+0x521): undefined reference to `_imp__alGetEnumValue'
../lib32/libsfml-audio-s.a(AudioDevice.cpp.obj):AudioDevice.cpp:(.text+0x541): undefined reference to `_imp__alGetEnumValue'
../lib32/libsfml-audio-s.a(AudioDevice.cpp.obj):AudioDevice.cpp:(.text+0x59e): undefined reference to `_imp__alcMakeContextCurrent'
../lib32/libsfml-audio-s.a(AudioDevice.cpp.obj):AudioDevice.cpp:(.text+0x5b8): undefined reference to `_imp__alcDestroyContext'
../lib32/libsfml-audio-s.a(AudioDevice.cpp.obj):AudioDevice.cpp:(.text+0x5d2): undefined reference to `_imp__alcCloseDevice'
../lib32/libsfml-audio-s.a(AudioDevice.cpp.obj):AudioDevice.cpp:(.text+0x6be): undefined reference to `_imp__alIsExtensionPresent'
../lib32/libsfml-audio-s.a(AudioDevice.cpp.obj):AudioDevice.cpp:(.text+0x6e2): undefined reference to `_imp__alcMakeContextCurrent'
../lib32/libsfml-audio-s.a(AudioDevice.cpp.obj):AudioDevice.cpp:(.text+0x6f4): undefined reference to `_imp__alcDestroyContext'
../lib32/libsfml-audio-s.a(AudioDevice.cpp.obj):AudioDevice.cpp:(.text+0x70d): undefined reference to `_imp__alcCloseDevice'
../lib32/libsfml-audio-s.a(AudioDevice.cpp.obj):AudioDevice.cpp:(.text+0x7ae): undefined reference to `_imp__alcIsExtensionPresent'
../lib32/libsfml-audio-s.a(AudioDevice.cpp.obj):AudioDevice.cpp:(.text+0x807): undefined reference to `_imp__alcMakeContextCurrent'
../lib32/libsfml-audio-s.a(AudioDevice.cpp.obj):AudioDevice.cpp:(.text+0x820): undefined reference to `_imp__alcDestroyContext'
../lib32/libsfml-audio-s.a(AudioDevice.cpp.obj):AudioDevice.cpp:(.text+0x839): undefined reference to `_imp__alcCloseDevice'
../lib32/libsfml-audio-s.a(AudioDevice.cpp.obj):AudioDevice.cpp:(.text$_ZNSt8auto_ptrIN2sf4priv11AudioDeviceEED1Ev[__ZNSt8auto_ptrIN2sf4priv11AudioDeviceEED1Ev]+0x13): undefined reference to `_imp__alcMakeContextCurrent'
../lib32/libsfml-audio-s.a(AudioDevice.cpp.obj):AudioDevice.cpp:(.text$_ZNSt8auto_ptrIN2sf4priv11AudioDeviceEED1Ev[__ZNSt8auto_ptrIN2sf4priv11AudioDeviceEED1Ev]+0x25): undefined reference to `_imp__alcDestroyContext'
../lib32/libsfml-audio-s.a(AudioDevice.cpp.obj):AudioDevice.cpp:(.text$_ZNSt8auto_ptrIN2sf4priv11AudioDeviceEED1Ev[__ZNSt8auto_ptrIN2sf4priv11AudioDeviceEED1Ev]+0x37): undefined reference to `_imp__alcCloseDevice'
../lib32/libsfml-audio-s.a(SoundSource.cpp.obj):SoundSource.cpp:(.text+0x62): undefined reference to `_imp__alSourcei'
../lib32/libsfml-audio-s.a(SoundSource.cpp.obj):SoundSource.cpp:(.text+0x7a): undefined reference to `_imp__alDeleteSources'
../lib32/libsfml-audio-s.a(SoundSource.cpp.obj):SoundSource.cpp:(.text+0x132): undefined reference to `_imp__alSourcei'
../lib32/libsfml-audio-s.a(SoundSource.cpp.obj):SoundSource.cpp:(.text+0x14a): undefined reference to `_imp__alDeleteSources'
../lib32/libsfml-audio-s.a(SoundSource.cpp.obj):SoundSource.cpp:(.text+0x21b): undefined reference to `_imp__alGenSources'
../lib32/libsfml-audio-s.a(SoundSource.cpp.obj):SoundSource.cpp:(.text+0x23b): undefined reference to `_imp__alSourcei'
../lib32/libsfml-audio-s.a(SoundSource.cpp.obj):SoundSource.cpp:(.text+0x2f1): undefined reference to `_imp__alGenSources'
../lib32/libsfml-audio-s.a(SoundSource.cpp.obj):SoundSource.cpp:(.text+0x30b): undefined reference to `_imp__alSourcei'
../lib32/libsfml-audio-s.a(SoundSource.cpp.obj):SoundSource.cpp:(.text+0x330): undefined reference to `_imp__alGetSourcef'
../lib32/libsfml-audio-s.a(SoundSource.cpp.obj):SoundSource.cpp:(.text+0x356): undefined reference to `_imp__alSourcef'
../lib32/libsfml-audio-s.a(SoundSource.cpp.obj):SoundSource.cpp:(.text+0x412): undefined reference to `_imp__alGetSource3f'
../lib32/libsfml-audio-s.a(SoundSource.cpp.obj):SoundSource.cpp:(.text+0x44b): undefined reference to `_imp__alSource3f'
../lib32/libsfml-audio-s.a(SoundSource.cpp.obj):SoundSource.cpp:(.text+0x46e): undefined reference to `_imp__alGetSourcei'
../lib32/libsfml-audio-s.a(SoundSource.cpp.obj):SoundSource.cpp:(.text+0x58b): undefined reference to `_imp__alSourcef'
../lib32/libsfml-audio-s.a(SoundSource.cpp.obj):SoundSource.cpp:(.text+0x5c1): undefined reference to `_imp__alSourcef'
../lib32/libsfml-audio-s.a(SoundSource.cpp.obj):SoundSource.cpp:(.text+0x5fb): undefined reference to `_imp__alSource3f'
../lib32/libsfml-audio-s.a(SoundSource.cpp.obj):SoundSource.cpp:(.text+0x63b): undefined reference to `_imp__alSource3f'
../lib32/libsfml-audio-s.a(SoundSource.cpp.obj):SoundSource.cpp:(.text+0x66c): undefined reference to `_imp__alSourcei'
../lib32/libsfml-audio-s.a(SoundSource.cpp.obj):SoundSource.cpp:(.text+0x69b): undefined reference to `_imp__alSourcef'
../lib32/libsfml-audio-s.a(SoundSource.cpp.obj):SoundSource.cpp:(.text+0x6cb): undefined reference to `_imp__alSourcef'
../lib32/libsfml-audio-s.a(SoundSource.cpp.obj):SoundSource.cpp:(.text+0x6fb): undefined reference to `_imp__alGetSourcef'
../lib32/libsfml-audio-s.a(SoundSource.cpp.obj):SoundSource.cpp:(.text+0x72b): undefined reference to `_imp__alGetSourcef'
../lib32/libsfml-audio-s.a(SoundSource.cpp.obj):SoundSource.cpp:(.text+0x776): undefined reference to `_imp__alGetSource3f'
../lib32/libsfml-audio-s.a(SoundSource.cpp.obj):SoundSource.cpp:(.text+0x7ab): undefined reference to `_imp__alGetSourcei'
../lib32/libsfml-audio-s.a(SoundSource.cpp.obj):SoundSource.cpp:(.text+0x7db): undefined reference to `_imp__alGetSourcef'
../lib32/libsfml-audio-s.a(SoundSource.cpp.obj):SoundSource.cpp:(.text+0x80b): undefined reference to `_imp__alGetSourcef'
../lib32/libsfml-audio-s.a(SoundSource.cpp.obj):SoundSource.cpp:(.text+0x82b): undefined reference to `_imp__alGetSourcef'
../lib32/libsfml-audio-s.a(SoundSource.cpp.obj):SoundSource.cpp:(.text+0x84f): undefined reference to `_imp__alSourcef'
../lib32/libsfml-audio-s.a(SoundSource.cpp.obj):SoundSource.cpp:(.text+0x8da): undefined reference to `_imp__alGetSource3f'
../lib32/libsfml-audio-s.a(SoundSource.cpp.obj):SoundSource.cpp:(.text+0x906): undefined reference to `_imp__alSource3f'
../lib32/libsfml-audio-s.a(SoundSource.cpp.obj):SoundSource.cpp:(.text+0x91e): undefined reference to `_imp__alGetSourcei'
../lib32/libsfml-audio-s.a(SoundSource.cpp.obj):SoundSource.cpp:(.text+0x941): undefined reference to `_imp__alSourcei'
../lib32/libsfml-audio-s.a(SoundSource.cpp.obj):SoundSource.cpp:(.text+0x9db): undefined reference to `_imp__alGetSourcei'
collect2.exe: error: ld returned 1 exit status

我认为这是由于编译命令中静态库的顺序不正确造成的。链接静态 SFML 库的正确顺序是什么?

最佳答案

您的图书馆订单没问题(只是快速浏览了一下)。您只是忘记链接 OpenAL(在 Windows 下这将是 -lOpenAL32),这是需要注意的,因为所有 undefined reference 都以 _imp__al 开头。完成后,一切都应该按预期链接和运行。

关于c++ - 编译 SFML 时链接 'static libraries' 的顺序是什么?,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/47816264/

28 4 0
Copyright 2021 - 2024 cfsdn All Rights Reserved 蜀ICP备2022000587号
广告合作:1813099741@qq.com 6ren.com