OSX GCC如何指定sfml库源? [英] OSX GCC how to specify sfml library source?
问题描述
我正在尝试编译一个使用 sfml 的项目
sfml 2.1
通过 homebrew
如下所示
unknown542696d2a12b:keeperrl kevzettler $ brew list sfml
/ usr / local / Cellar / sfml / 2.1 / Frameworks / freetype.framework /(3个文件)
/usr/local/Cellar/sfml/2.1/Frameworks/sndfile.framework/(3个文件)
/ usr / local / Cellar / sfml / 2.1 / include / SFML /(87个文件)
/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个其他文件)
/usr/local/Cellar/sfml/2.1/share/SFML/(3个文件)
项目编译好,但是当我尝试运行它时,我得到一个错误:
未知542696d2a12b:keeperrl kevzettler $ ./keeper
dyld:未加载库:@executable_path /../ Frameworks / freetype.framework / Versions / A / freetype
引用自:/ usr / local / lib / libsfml -graphics.2.dylib
原因:未找到图片
跟踪/ BPT陷阱:5
$ b b
看起来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 / 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 / smallest_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
flags指向 2.1
库
-I / usr / local / Cellar / sfml /2.1/include/SFML/ -I / usr / local / Cellar / sfml / 2.1 / lib / -L / usr / local / Cellar
SFML是为了使用freetype和libsndfile框架而开发的。 code> / Library / Frameworks 或从 Frameworks /library/mac/documentation/corefoundation/conceptual/cfbundles/BundleTypes/BundleTypes.htmlrel =nofollow>应用程序包。
您可以找到更多技术详情这里和 。
如何在Mac上轻松使用SFML?
很容易:按照1:1 官方指南: SFML和Xcode(Mac OS X)(是的,你可以使用Xcode外的SFML!)
真的想使用brew公式。如何解决?
首先,请仔细阅读此问题。
特别对于当前问题,您需要使用 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。如果您使用官方安装程序并不是这样,使用Xcode模板创建一个SFML应用程序。
I'm trying to compile a project that uses sfml
I installed sfml 2.1
through homebrew
like below
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)
The project compiles ok however when I try to run it I get an error:
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
It looks like dyld is trying to load a different version of sfml
. Than the one installed from homebrew
I suspect this is some system default from OSX.
The compile command looks like:
/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've tried specifying -I
and -L
flags to point at the 2.1
library
-I/usr/local/Cellar/sfml/2.1/include/SFML/ -I/usr/local/Cellar/sfml/2.1/lib/ -L/usr/local/Cellar
Why doesn't SFML formula work out of the box?
SFML was built to use freetype and libsndfile frameworks from /Library/Frameworks
or from the Frameworks
folder in your application bundle.
You can find more technical details here and there.
How can I use SFML on Mac easily?
It's really easy: follow 1:1 the official guide: SFML and Xcode (Mac OS X) (And yes, you can use SFML outside Xcode!)
I really want to use brew formula. How can I fix it?
First, take a good look at this issue. That would give you an overview of the problems with the current naïve formula.
Specifically to you current issue, you will need to use install_name_tool
to fix your binaries.
Here is how you can do it for freetype. It's similar for 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
However, this means your app will look for freetype in /usr/local/lib
. Hence, you would have to install freetype there on your clients' computers too. This is not the case if you use the official installation procedure and use Xcode templates to create a SFML app.
这篇关于OSX GCC如何指定sfml库源?的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!