简体   繁体   English

如何在C ++ 11和新的STL中使用GSL?

[英]How can I use GSL with C++11 and the new STL?

I am setting up a new C++ project (in Xcode 4.6) and I would very much like to use the features of the new C++11 standard (lambda expressions, auto, etc.). 我正在建立一个新的C ++项目(在Xcode 4.6中),我非常想使用新的C ++ 11标准的功能(lambda表达式,auto等)。 I am trying to (statically) link the Gnu Scientific Library (GSL) into this project, using Darson's answer to this previous question. 我想(静态)的GNU科学图书馆(GSL)链接到这个项目中,使用Darson的回答这个前面的问题。 However, his answer suggests to change the compiler to LLVM GCC 4.2, which does not support the new C++11 features. 但是,他的回答建议将编译器更改为不支持新的C ++ 11功能的LLVM GCC 4.2。

When I change to the default Apple LLVM compiler 4.2, build fails and I get a long list of errors that Xcode traces back to semantic issues (undeclared identifiers, unknown type names, etc.) in the headers of the new "libc++" STL. 当我更改为默认的Apple LLVM编译器4.2时,构建失败,并且在新的“ libc ++” STL的标头中,Xcode追溯到语义问题(未声明的标识符,未知的类型名称等),列出了很多错误。

So my question is: Did anyone find a way to use GSL in the new C++11 standard? 所以我的问题是: 有没有人找到在新的C ++ 11标准中使用GSL的方法? It doesn't necessarily have to be in Xcode, I am comfortable using any (UNIX) IDE or build environment. 它不一定必须在Xcode中,我可以使用任何(UNIX)IDE​​或构建环境。

I've been able to solve my own question, and I thought I'd share it with those who might be struggling with this as well. 我已经能够解决自己的问题,并且我想与那些可能也在为此苦苦挣扎的人分享。

Like I suspected, the problem occurred because my GSL install (from macports) was build against the "old" STL (libstdc++). 就像我怀疑的那样,出现问题是因为我的GSL安装(来自macports)是针对“旧” STL(libstdc ++)构建的。 Hence, my solution was to recompile GSL against the "new" STL (libc++). 因此,我的解决方案是针对“新” STL(libc ++)重新编译GSL。 This is easily done by unpacking the sources and running 通过拆开源代码并运行,很容易做到这一点。

./configure CC=clang CFLAGS="-stdlib=libc++" LDFLAGS="-stdlib=libc++"

I also added --disable-shared to build the static library only, and --prefix=... to set the build path. 我还添加了--disable-shared仅用于构建静态库,以及--prefix=...来设置构建路径。 Then all what's left is to run make and make install . 然后剩下的就是运行makemake install

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM