使用Clang,libc ++和c ++ 11创建SFML2应用程序。未定义对SFML库的引用 [英] Making a SFML2 Applcation with Clang, libc++ and c++11. Undefined Reference to SFML Library

查看:340
本文介绍了使用Clang,libc ++和c ++ 11创建SFML2应用程序。未定义对SFML库的引用的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我有一个奇怪的问题,使SFML2应用程序。我使用Clang ++从存储库以及libc ++(两个更新今天)。 SFML2也从SVN仓库更新。我使用的是最新版本的Kubuntu。我也有同样的问题,当我上次尝试大约一个月前与当时最新的存储库。

I'm having a weird problem with making an SFML2 application. I'm using Clang++ from the Repositories as well as libc++ (both updated today). SFML2 was also updated from the SVN repo. I'm using the latest version of Kubuntu. I also had the same problem when I last tried about a month ago with the then up-to-date repositories.

我传递给编译器的参数c ++ 11和stdlib是:-std = c + + 11 -stdlib = libc ++

The parameters I'm passing through to the compiler for c++11 and stdlib are: -std=c++11 -stdlib=libc++

这是我调用的完整版本:

Here's the full version of what I'm calling:

clang++ -std=c++11 -stdlib=libc++ main2.cpp -o main -L/home/jonathan/OpenSource/sfml/SFML-Build/lib/ -I/home/jonathan/OpenSource/sfml/SFML/include/ -lsfml-system -lsfml-window -lsfml-graphics -v

当我尝试编译应用程序时,我从Clang得到一个链接错误:

When I try to compile the application, I get a linking error from Clang :

/tmp/main2-stOJMp.o: In function `main':
main2.cpp:(.text+0x108): undefined reference to `sf::Window::create(sf::VideoMode, std::__1::basic_string<char, std::__1::char_traits<char>, std::__1::allocator<char> > const&, unsigned int, sf::ContextSettings const&)'

所有应用程序(当前)都创建一个RenderWindow。它只是一个测试应用程序,但对于我使用的大多数SFML2函数,将有一些链接问题,像这样。如果我不使用libc ++,程序编译完全正常。

All the application does (currently) is create a RenderWindow. It's just a test application, but for most SFML2 functions I use, there will be some linking problem like this. If I don't use libc++, the program compiles perfectly fine.

从我可以告诉,如果我包括-stdlib = libc ++,它不搜索SFML2库文件夹,用于SFML2库正确链接。

From what I can tell, if I include the -stdlib=libc++, it doesn't search the SFML2 lib folder for the SFML2 libraries to correctly link with.

当我使用-v命令调用Clang时,这里是ld调用:

When I use the -v command for the invocation with Clang, here is the ld call:

"/usr/bin/ld" -z relro --hash-style=gnu --build-id --eh-frame-hdr -m elf_x86_64 -dynamic-linker /lib64/ld-linux-x86-64.so.2 -o main /usr/lib/gcc/x86_64-linux-gnu/4.6/../../../x86_64-linux-gnu/crt1.o /usr/lib/gcc/x86_64-linux-gnu/4.6/../../../x86_64-linux-gnu/crti.o /usr/lib/gcc/x86_64-linux-gnu/4.6/crtbegin.o -L/home/jonathan/OpenSource/sfml/SFML-Build/lib/ -L/usr/lib/gcc/x86_64-linux-gnu/4.6 -L/usr/lib/gcc/x86_64-linux-gnu/4.6/../../../x86_64-linux-gnu -L/lib/x86_64-linux-gnu -L/lib/../lib64 -L/usr/lib/x86_64-linux-gnu -L/usr/lib/gcc/x86_64-linux-gnu/4.6/../../.. -L/lib -L/usr/lib /tmp/main2-kOZbfN.o -lsfml-system -lsfml-window -lsfml-graphics -lc++ -lm -lgcc_s -lgcc -lc -lgcc_s -lgcc /usr/lib/gcc/x86_64-linux-gnu/4.6/crtend.o /usr/lib/gcc/x86_64-linux-gnu/4.6/../../../x86_64-linux-gnu/crtn.o

如果我不使用-stdlib = libc ++ ...

And if I don't use -stdlib=libc++...

"/usr/bin/ld" -z relro --hash-style=gnu --build-id --eh-frame-hdr -m elf_x86_64 -dynamic-linker /lib64/ld-linux-x86-64.so.2 -o main /usr/lib/gcc/x86_64-linux-gnu/4.6/../../../x86_64-linux-gnu/crt1.o /usr/lib/gcc/x86_64-linux-gnu/4.6/../../../x86_64-linux-gnu/crti.o /usr/lib/gcc/x86_64-linux-gnu/4.6/crtbegin.o -L/home/jonathan/OpenSource/sfml/SFML-Build/lib/ -L/usr/lib/gcc/x86_64-linux-gnu/4.6 -L/usr/lib/gcc/x86_64-linux-gnu/4.6/../../../x86_64-linux-gnu -L/lib/x86_64-linux-gnu -L/lib/../lib64 -L/usr/lib/x86_64-linux-gnu -L/usr/lib/gcc/x86_64-linux-gnu/4.6/../../.. -L/lib -L/usr/lib /tmp/main2-2IOIxv.o -lsfml-system -lsfml-window -lsfml-graphics -lstdc++ -lm -lgcc_s -lgcc -lc -lgcc_s -lgcc /usr/lib/gcc/x86_64-linux-gnu/4.6/crtend.o /usr/lib/gcc/x86_64-linux-gnu/4.6/../../../x86_64-linux-gnu/crtn.o

所以,如果我混淆了人:如果我使用libc ++与Clang,我从第一次ld调用得到上述错误。如果我不使用它,第二个ld调用完全正常,应用程序运行成功。

So, In case I've confused people: if I use libc++ with Clang, I get the above error from the first ld call. If I don't use it, the second ld call goes through perfectly fine and the application runs successfully.

我使用libc ++的原因是因为我想使用从C ++线程11。没有它,我从我的电脑拥有的GNU C ++标准库中得到了大量的错误。我不会为此发布错误列表,因为它是巨大的,与这个问题不相关。

The reason I'm using libc++ is because I want to use the Threading from C++11. Without it, I get a ton of errors from the GNU C++ standard library my computer has. I won't post the error list for this, as it's huge and not relevant to this problem.

有人有任何线索,如何我可以解决SFML2问题?我不想使用pthreads库,如果我不必。

Does anyone have any clue as to how I might be able solve the SFML2 problem? I'd rather not use the pthreads library if I don't have to.

推荐答案

SFML2库已经编译了一些C ++库而不是libc ++(也许libstdc ++?)。要纠正,请使用-stdlib = libc ++重新编译SFML2,并确保链接器在将SFML2链接到应用程序时看到-stdlib = libc ++。

The SFML2 library has been compiled against some C++ library other than libc++ (perhaps libstdc++?). To correct, recompile SFML2 with -stdlib=libc++, and be sure the linker sees -stdlib=libc++ when linking SFML2 to your application.

链接器正在寻找 sf :: Window :: create std :: __ 1 符号。而libc ++用 std :: __ 1 来处理。但是其他std :: libs只需要 std 即可。这是一个安全功能,可以防止意外混合来自两个不同的std :: libs的 std :: string ,并结束运行时错误,而不是链接时错误。

The key to debugging this is noting that the linker is looking for sf::Window::create with std::__1 symbols. And libc++ mangles things with std::__1. But other std::libs mangle things with just std. This is a safety feature to keep you from accidentally mixing std::string from two different std::libs and ending up with a run time error instead of a link time error.

这篇关于使用Clang,libc ++和c ++ 11创建SFML2应用程序。未定义对SFML库的引用的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆