How to enable C++11/C++0x support in Eclipse CDT?

后端 未结 17 1784
说谎
说谎 2020-11-22 00:13

Eclipse 3.7.1 CDT 1.4.1 GCC 4.6.2

This is an example of a piece of C++11 code:

auto text = std::unique_ptr(new char[len]);
17条回答
  •  暖寄归人
    2020-11-22 00:21

    I had several issues too (Ubuntu 13.04 64-bit, g++-4.8, eclipse Juno 3.8.1, CDT 6.0.0). A lot of things are mentioned above, sorry to repeat those, but additionally I had problems utilizing

    std::thread
    

    as part of c++11 (adding -pthread for the linker solves that issue). Anyway, finally these settings worked fine:

    Project -> Properties -> C/C++ Build -> Settings -> Miscellaneous. Add the

    -std=c++11
    

    flag for the GCC and G++ compilers. Click Apply.

    For the linker, same window, Miscellaneous, Linker flags, added the

    -pthread
    

    flag. Shared library settings, Shared object name, add the

    -Wl,--no-as-needed
    

    flag too. Click Apply.

    C/C++ General -> Paths and symbols -> Symbols TAB, GNU C++ selected, Add the

    __GXX_EXPERIMENTAL_CXX0X__
    

    (no value)

    flag. Click Apply.

    C/C++ General -> Preprocessor Include paths.. -> Providers tab : check

    CDT GCC built-in Compiler Settings

    and for "Command to get compiler specs", add the

    -std=c++11
    

    flag. Uncheck Share. Click Apply.

    CDT Managages Build Setting Entries, check this too. Uncheck the two others. Click Apply.

    Going back to the Entries tab, GNU C++ CDT Managages Build Setting Entries, you should now see your added

    __GXX_EXPERIMENTAL_CXX0X__
    

    entry.

    That's it. When coding, typing

    std::
    

    can now auto-complete the thread class for instance, builds should work fine and there should be no

    std::system_error'what(): Enable multithreading to use std::thread: Operation not permitted
    

    at runtime.

提交回复
热议问题