3 c++ c++11 osx-mavericks g++4.8
我正在使用通过MacPorts安装的gcc 4.8,旧的C++ 11代码将不再编译
如果我使用没有-std = c ++ 11标志的编译器,它可以正常使用此测试代码
#include <cctype>
int main() {
std::isalnum('c');
return 0;
}
[bash] g++48 test.cpp
Run Code Online (Sandbox Code Playgroud)
但是在小牛队升级之后我得到以下编译错误:
[bash] g++48 -std=c++11 test.cpp
Undefined symbols for architecture x86_64:
"isalnum(int)", referenced from:
_main in ccvsKeqJ.o
ld: symbol(s) not found for architecture x86_64
collect2: error: ld returned 1 exit status
Run Code Online (Sandbox Code Playgroud)
有没有人知道可能导致这个问题的原因?我感谢任何帮助
OSX Mavericks升级将消灭许多XCode安装目录.要恢复它们,您需要重新安装XCode命令行工具.
xcode-select --install
Run Code Online (Sandbox Code Playgroud)
然后同意下载提示.
如果失败,您可以尝试从这里手动安装:OSX:Xcode Downloads
这与错误安装的osx cmdline工具无关,但是,正如在这个SO问题中清楚解释的那样,10.9 SDK头中的某些内联相关宏已更改,特别是在usr/include/sys/cdefs.h中.
作为一种快速解决方法,您可以利用GCC的"固定包含"机制,并提供稍微调整的/usr/include/sys/cdefs.h版本,以防止在编译c ++代码时出现以下问题:
编辑刚刚复制的文件..../include-fixed/sys/cdefs.h以应用以下补丁:
@@ -216,7 +215,7 @@
#if __STDC_VERSION__ >= 199901L && (!defined(__GNUC__) || defined(__clang__))
# define __header_inline inline
-#elif defined(__GNUC__) && defined(__GNUC_STDC_INLINE__)
+#elif defined(__GNUC__) && defined(__GNUC_STDC_INLINE__) && !defined (__cplusplus)
# define __header_inline extern __inline __attribute__((__gnu_inline__))
#elif defined(__GNUC__)
# define __header_inline extern __inline
Run Code Online (Sandbox Code Playgroud)在编译c ++代码时,这会导致扩展
__header_inline - > extern __inline
代替
__header_inline - > extern __inline __attribute __((__ gnu_inline__))
这显然会导致GCC不能真正内联isalnum,因此会在符号上留下链接时间依赖关系,即它会尝试在某个库中找到它,从而导致链接错误.
| 归档时间: |
|
| 查看次数: |
5939 次 |
| 最近记录: |