gpt4 book ai didi

c++ - OSX GCC 如何指定 sfml 库源?

转载 作者:塔克拉玛干 更新时间:2023-11-03 02:02:30 24 4
gpt4 key购买 nike

我正在尝试编译一个使用 sfml 的项目,我通过 homebrew 安装了 sfml 2.1,如下所示

unknown542696d2a12b:keeperrl kevzettler$ brew list sfml
/usr/local/Cellar/sfml/2.1/Frameworks/freetype.framework/ (3 files)
/usr/local/Cellar/sfml/2.1/Frameworks/sndfile.framework/ (3 files)
/usr/local/Cellar/sfml/2.1/include/SFML/ (87 files)
/usr/local/Cellar/sfml/2.1/lib/libsfml-audio.2.1.dylib
/usr/local/Cellar/sfml/2.1/lib/libsfml-graphics.2.1.dylib
/usr/local/Cellar/sfml/2.1/lib/libsfml-network.2.1.dylib
/usr/local/Cellar/sfml/2.1/lib/libsfml-system.2.1.dylib
/usr/local/Cellar/sfml/2.1/lib/libsfml-window.2.1.dylib
/usr/local/Cellar/sfml/2.1/lib/ (10 other files)
/usr/local/Cellar/sfml/2.1/share/SFML/ (3 files)

项目编译正常,但是当我尝试运行它时出现错误:

unknown542696d2a12b:keeperrl kevzettler$ ./keeper
dyld: Library not loaded: @executable_path/../Frameworks/freetype.framework/Versions/A/freetype
Referenced from: /usr/local/lib/libsfml-graphics.2.dylib
Reason: image not found
Trace/BPT trap: 5

看起来 dyld 正在尝试加载不同版本的 sfml。与从 homebrew 安装的相比,我怀疑这是 OSX 的一些系统默认值。

编译命令如下:

 /usr/local/Cellar/gcc49/4.9.0/bin/gcc-4.9 -Wall -std=c++0x -lstdc++ -ftemplate-depth=1024 -Wno-sign-compare -Wno-unused-variable \
-I. -I./extern -I/usr/local/Cellar/boost/1.55.0/include/boost/ -I/usr/local/Cellar/boost/1.55.0/lib -I/usr/local/Cellar/sfml/2.1/include/SFML/ -I/usr/local/Cellar/sfml/2.1/lib/ -static-libstdc++ -g -O3 -o keeper \
obj-opt/time_queue.o obj-opt/level.o obj-opt/model.o obj-opt/square.o obj-opt/util.o obj-opt/monster.o obj-opt/square_factory.o obj-opt/view.o obj-opt/creature.o obj-opt/message_buffer.o obj-opt/item_factory.o obj-opt/item.o obj-opt/inventory.o obj-opt/debug.o obj-opt/player.o obj-opt/window_view.o obj-opt/field_of_view.o obj-opt/view_object.o obj-opt/creature_factory.o obj-opt/quest.o obj-opt/shortest_path.o obj-opt/effect.o obj-opt/equipment.o obj-opt/level_maker.o obj-opt/monster_ai.o obj-opt/attack.o obj-opt/tribe.o obj-opt/name_generator.o obj-opt/event.o obj-opt/location.o obj-opt/skill.o obj-opt/fire.o obj-opt/ranged_weapon.o obj-opt/map_layout.o obj-opt/trigger.o obj-opt/map_memory.o obj-opt/view_index.o obj-opt/pantheon.o obj-opt/enemy_check.o obj-opt/collective.o obj-opt/task.o obj-opt/markov_chain.o obj-opt/controller.o obj-opt/village_control.o obj-opt/poison_gas.o obj-opt/minion_equipment.o obj-opt/statistics.o obj-opt/options.o obj-opt/renderer.o obj-opt/tile.o obj-opt/map_gui.o obj-opt/gui_elem.o obj-opt/item_attributes.o obj-opt/creature_attributes.o obj-opt/serialization.o obj-opt/unique_entity.o obj-opt/entity_set.o obj-opt/gender.o obj-opt/main.o obj-opt/gzstream.o obj-opt/singleton.o obj-opt/technology.o obj-opt/encyclopedia.o obj-opt/creature_view.o obj-opt/input_queue.o obj-opt/user_input.o obj-opt/window_renderer.o obj-opt/texture_renderer.o obj-opt/minimap_gui.o obj-opt/music.o obj-opt/test.o obj-opt/sectors.o obj-opt/vision.o \
-lsfml-graphics -lsfml-audio -lsfml-window -lsfml-system -lboost_serialization -lz -L/usr/local/Cellar

我已经尝试指定 -I-L 标志以指向 2.1

-I/usr/local/Cellar/sfml/2.1/include/SFML/-I/usr/local/Cellar/sfml/2.1/lib/-L/usr/local/Cellar

最佳答案

为什么 SFML 公式不能开箱即用?

SFML 的构建是为了使用来自 /Library/Frameworks 或来自 application bundle 中的 Frameworks 文件夹的 freetype 和 libsndfile 框架.

您可以找到更多技术细节herethere .

如何在 Mac 上轻松使用 SFML?

这真的很简单:1:1 遵循官方指南:SFML and Xcode (Mac OS X) (是的,您可以在 Xcode 之外使用 SFML!)

我真的很想用 brew formula。我该如何解决?

首先,好好看看this issue .这将使您大致了解当前朴素公式的问题。

特别针对您当前的问题,您需要使用 install_name_tool修复您的二进制文件。

这里是如何为 freetype 做的。 libsndfile 类似。

install_name_tool -change @executable_path/../Frameworks/freetype.framework/Versions/A/freetype /usr/local/lib/libfreetype.dylib /usr/local/Cellar/sfml/2.1/lib/libsfml-graphics.2.1.dylib

但是,这意味着您的应用程序将在 /usr/local/lib 中查找 freetype。因此,您也必须在客户的计算机上安装 freetype。如果您使用 official installation procedure 则情况并非如此并使用 Xcode 模板创建 SFML 应用程序。

关于c++ - OSX GCC 如何指定 sfml 库源?,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/24090674/

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