2014-11-09 15 views
6

Làm cách nào để có được thiết lập C++ 11 dựa trên GCC trên FreeBSD 10? Dường như thư viện chuẩn đi kèm với các phiên bản GCC gần đây trên FreeBSD bị hỏng. Tôi đã cài đặt cổng gcc49 và sau đó cố gắng biên dịch này:Bắt GCC ở chế độ C++ 11 để hoạt động trên FreeBSD

#include <string> 

int main() 
{ 
    auto str = std::to_string(42); 
    str = std::to_string(42ull); 
    str = std::to_string(4.2); 
    str.clear(); 
    return 0; 
} 

này mang lại cho tôi một lỗi:

g++49 -v -std=c++11 foo.cc 
Using built-in specs. 
COLLECT_GCC=g++49 
COLLECT_LTO_WRAPPER=/usr/local/libexec/gcc49/gcc/x86_64-portbld-freebsd10.0/4.9.2/lto-wrapper 
Target: x86_64-portbld-freebsd10.0 
Configured with: ./../gcc-4.9-20141022/configure --disable-nls --enable-gnu-indirect-function --libdir=/usr/local/lib/gcc49 --libexecdir=/usr/local/libexec/gcc49 --program-suffix=49 --with-as=/usr/local/bin/as --with-gmp=/usr/local --with-gxx-include-dir=/usr/local/lib/gc 
c49/include/c++/ --with-ld=/usr/local/bin/ld --with-pkgversion='FreeBSD Ports Collection' --with-system-zlib --with-ecj-jar=/usr/local/share/java/ecj-4.5.jar --enable-languages=c,c++,objc,fortran,java --prefix=/usr/local --mandir=/usr/local/man --infodir=/usr/local/info/gcc49 --build=x86_64-portbld-freebsd10.0 
Thread model: posix 
gcc version 4.9.2 20141022 (prerelease) (FreeBSD Ports Collection) 
COLLECT_GCC_OPTIONS='-v' '-std=c++11' '-shared-libgcc' '-mtune=generic' '-march=x86-64' 
/usr/local/libexec/gcc49/gcc/x86_64-portbld-freebsd10.0/4.9.2/cc1plus -quiet -v foo.cc -quiet -dumpbase foo.cc -mtune=generic -march=x86-64 -auxbase foo -std=c++11 -version -o /tmp//ccbNFhtI.s 
GNU C++ (FreeBSD Ports Collection) version 4.9.2 20141022 (prerelease) (x86_64-portbld-freebsd10.0) 
     compiled by GNU C version 4.9.2 20141022 (prerelease), GMP version 5.1.3, MPFR version 3.1.2, MPC version 1.0.2 
GGC heuristics: --param ggc-min-expand=100 --param ggc-min-heapsize=131072 
ignoring nonexistent directory "/usr/local/lib/gcc49/gcc/x86_64-portbld-freebsd10.0/4.9.2/../../../../../x86_64-portbld-freebsd10.0/include" 
#include "..." search starts here: 
#include <...> search starts here: 
/usr/local/lib/gcc49/include/c++/ 
/usr/local/lib/gcc49/include/c++//x86_64-portbld-freebsd10.0 
/usr/local/lib/gcc49/include/c++//backward 
/usr/local/lib/gcc49/gcc/x86_64-portbld-freebsd10.0/4.9.2/include 
/usr/local/include 
/usr/local/lib/gcc49/gcc/x86_64-portbld-freebsd10.0/4.9.2/include-fixed 
/usr/include 
End of search list. 
GNU C++ (FreeBSD Ports Collection) version 4.9.2 20141022 (prerelease) (x86_64-portbld-freebsd10.0) 
     compiled by GNU C version 4.9.2 20141022 (prerelease), GMP version 5.1.3, MPFR version 3.1.2, MPC version 1.0.2 
GGC heuristics: --param ggc-min-expand=100 --param ggc-min-heapsize=131072 
Compiler executable checksum: 8405316ee381c37148f55a17e42da47a 
foo.cc: In function 'int main()': 
foo.cc:5:14: error: 'to_string' is not a member of 'std' 
    auto str = std::to_string(42); 
      ^
foo.cc:6:9: error: 'to_string' is not a member of 'std' 
    str = std::to_string(42ull); 
     ^
foo.cc:7:9: error: 'to_string' is not a member of 'std' 
    str = std::to_string(4.2); 
     ^

Giá trị mặc định bao gồm đường dẫn tìm kiếm là /usr/local/lib/gcc49/include/c++/, mà chứa string tiêu đề. Làm cho tinh thần, bởi vì các tàu cảng gcc49 với libstC++ tương ứng. Nhưng có vẻ như bị hỏng, theo lỗi trên.

Đây có phải là sự cố đã biết không? Có ai nhận được một thiết lập làm việc của một GCC dựa trên toolchain cho C + + 11 trên FreeBSD?

(Lưu ý:. Tôi biết rằng Clang là trình biên dịch mặc định trên FreeBSD 10. Tuy nhiên, trong trường hợp này tôi đang tìm cách cụ để hỗ trợ một toolchain GCC-based)

+0

Đây có phải là cách liên quan không? http://stackoverflow.com/questions/12975341/to-string-is-not-a-member-of-std-says-so-g – shuttle87

+0

Không freebsd có một trình theo dõi lỗi? –

+0

Trình theo dõi lỗi FreeBSD thực sự là một nơi tốt hơn cho cuộc thảo luận này. Bỏ phiếu để đóng. – mavam

Trả lời

7

Hóa ra rằng việc thêm các cờ sau để g ++ sẽ làm cho nó hoạt động:

-D_GLIBCXX_USE_C99 -D_GLIBCXX_USE_C99_MATH -D_GLIBCXX_USE_C99_MATH_TR1 
Các vấn đề liên quan