我想开始一个基本的C++项目,并链接SFML库。 我将SFML库解压到文件夹/Users/mulperi/cpplib/sfml中, 并将其添加到Include Search Path和Library Search Path。
我的代码很简单,我在Youtube上跟了一个教程(也尝试过不同的现成代码):
#include <iostream>
#include <SFML/Graphics.hpp>
int main() {
sf::RenderWindow window(sf::VideoMode(640, 480), "First SML Window");
while (window.isOpen())
{
sf::Event event;
while (window.pollEvent(event))
{
switch (event.type) {
case sf::Event::Closed:
window.close();
break;
default:
break;
}
}
window.clear();
window.display();
}
return 0;
}
构建成功,所以路径应该是正确的。但我并没有看到窗口,而是看到了这些输出信息: 线程1:
dyld`__abort_with_payload:
0x10003b1e0 <+0>: movl $0x2000209, %eax ; imm = 0x2000209
0x10003b1e5 <+5>: movq %rcx, %r10
0x10003b1e8 <+8>: syscall
-> 0x10003b1ea <+10>: jae 0x10003b1f4 ; <+20>
0x10003b1ec <+12>: movq %rax, %rdi
0x10003b1ef <+15>: jmp 0x10003aa48 ; cerror_nocancel
0x10003b1f4 <+20>: retq
0x10003b1f5 <+21>: nop
0x10003b1f6 <+22>: nop
0x10003b1f7 <+23>: nop
输出:
dyld: Library not loaded: @rpath/libsfml-system.2.5.dylib
Referenced from: /Users/mulperi/Library/Developer/Xcode/DerivedData/sfml_1-cgodahbmxiufqnhhglbsyfuzvdvz/Build/Products/Debug/sfml_1
Reason: image not found
(lldb)
我正在使用 High Sierra 10.13.4 上的 Xcode 9.3.1。
更新: 我还尝试将 SFML 文件夹移动到项目文件夹中,甚至尝试按照 SFML 教程将 include、libs、frameworks、extlibs 拆分到 /usr/local 中,但始终得到相同的输出。
这是我的设置图片:
![Folder structure](https://istack.dev59.com/fqMUe.webp)
![Header search path](https://istack.dev59.com/7VedE.webp)
![Library search path](https://istack.dev59.com/EdWFB.webp)
![Added frameworks too](https://istack.dev59.com/accjB.webp)
![The output](https://istack.dev59.com/fDbsH.webp)