Difference between revisions of "C++ Support in Embedded Studio"
(→How to use the C++ Library) |
|||
(7 intermediate revisions by one other user not shown) | |||
Line 1: | Line 1: | ||
+ | [[Category:Embedded Studio]] |
||
+ | __TOC__ |
||
+ | |||
Embedded Studio supports application development in C and C++. |
Embedded Studio supports application development in C and C++. |
||
Its C runtime library, based on emRun, provides all fundamentals, tweaked for fastest speed or smallest size. |
Its C runtime library, based on emRun, provides all fundamentals, tweaked for fastest speed or smallest size. |
||
Line 17: | Line 20: | ||
''Note: For libcxx, Embedded Studio V5.60 or later is required.'' |
''Note: For libcxx, Embedded Studio V5.60 or later is required.'' |
||
+ | === Library installation steps (only necessary until ES V7.20) === |
||
The C++ standard library is based on the embedded C++ subset of the [https://libcxx.llvm.org "libc++" C++ Standard Library.] |
The C++ standard library is based on the embedded C++ subset of the [https://libcxx.llvm.org "libc++" C++ Standard Library.] |
||
Line 24: | Line 28: | ||
* Open the package manager under Tools -> Package Manager... |
* Open the package manager under Tools -> Package Manager... |
||
+ | ** Make sure that you have the latest package list loaded to avoid download errors. To refresh the list manually you will find a refresh button in the top right corner of the package manager. The mouse over tool tip shows "Refresh Package List". |
||
* Select the "ARM libcxx Library Package [Common]" or "RISCV libcxx Library Package [Common]" for installation. |
* Select the "ARM libcxx Library Package [Common]" or "RISCV libcxx Library Package [Common]" for installation. |
||
[[File:Cpp_Package_Manager.PNG|thumb|Package Manager|none]] |
[[File:Cpp_Package_Manager.PNG|thumb|Package Manager|none]] |
||
Line 31: | Line 36: | ||
The library is now ready to use and can be enabled in new and existing projects. |
The library is now ready to use and can be enabled in new and existing projects. |
||
+ | |||
+ | === Generic project setup steps === |
||
* Open or create a project. |
* Open or create a project. |
||
* Option the project options and go to Code -> Libraries. |
* Option the project options and go to Code -> Libraries. |
||
* In "libcxx Library" select "Yes" or "Yes (No Exceptions)". |
* In "libcxx Library" select "Yes" or "Yes (No Exceptions)". |
||
+ | ** Optional, if you select Yes and you are using std functions that could throw exceptions make sure that project option "Code > Code Generation > Enable Exception Support" is set to Yes |
||
[[File:Cpp_Project_Option.png|thumb|Project Options|none]] |
[[File:Cpp_Project_Option.png|thumb|Project Options|none]] |
||
* Press OK to save the project options. |
* Press OK to save the project options. |
||
Line 44: | Line 52: | ||
The project is now configured to use the C++ standard library. |
The project is now configured to use the C++ standard library. |
||
Include the necessary headers and start using the library functions. |
Include the necessary headers and start using the library functions. |
||
− | |||
− | == How to use the STLport Library (Legacy) == |
||
− | |||
− | Embedded Studio V5.50 and prior do not support the libcxx library. Instead STLPort is available. |
||
− | |||
− | * Open the package manager under Tools -> Package Manager... |
||
− | * Select the "STLPort Library Package" for installation. |
||
− | * Press Next to continue the download and installation. |
||
− | * Open or create a project. |
||
− | * Open the project options and go to Code -> Libraries. |
||
− | * In "STLPort Library" select "Yes". |
||
− | * Press OK ti save the project options. |
||
− | |||
− | The project is now configured to use STLPort as its C++ standard library. |
||
== Enabling Exception Support == |
== Enabling Exception Support == |
||
Line 63: | Line 57: | ||
To enable exception support in your C++ project the following must be considered: |
To enable exception support in your C++ project the following must be considered: |
||
* Make sure your library is installed as explained above. (Project option libcxx Library = Yes) |
* Make sure your library is installed as explained above. (Project option libcxx Library = Yes) |
||
− | * Set project option "Enable Exception Support" to Yes. |
+ | * Set project option "Code > Code Generation > Enable Exception Support" to Yes. |
* Make sure that sections readonly and readexec are placed in your linker script. |
* Make sure that sections readonly and readexec are placed in your linker script. |
||
Latest revision as of 13:05, 16 May 2024
Contents
Embedded Studio supports application development in C and C++. Its C runtime library, based on emRun, provides all fundamentals, tweaked for fastest speed or smallest size. In addition, the C++ library provides all required features for efficient C++ applications.
The C++ library adds:
- C++ header files to wrap up their C equivalents. e.g. cmath to math.h.
- C++-specific names and functions and mangled names for math.h. e.g. classification (isinf) and comparison (isless) functions, and cosf to cos(float) / cos to cos(double).
- C++ header files for exception, new, typeinfo.
- C++ unwinding library. Functions used for target unwinding, such as to implement exceptions.
- The C++ ABI library. Low-level support for standard C++ libraries.
- The C++ standard library.
This article describes how to enable the C++ libraries in Embedded Studio to use C++ library functions in target applications.
How to use the C++ Library
Note: For libcxx, Embedded Studio V5.60 or later is required.
Library installation steps (only necessary until ES V7.20)
The C++ standard library is based on the embedded C++ subset of the "libc++" C++ Standard Library.
To limit download and installation size of Embedded Studio, the library is supplied as additional packages for the supported target architectures. To enable the library in a project, only the common package needs to be installed. Embedded Studio takes care of downloading the specific packages if required.
- Open the package manager under Tools -> Package Manager...
- Make sure that you have the latest package list loaded to avoid download errors. To refresh the list manually you will find a refresh button in the top right corner of the package manager. The mouse over tool tip shows "Refresh Package List".
- Select the "ARM libcxx Library Package [Common]" or "RISCV libcxx Library Package [Common]" for installation.
- Optional: Select the specific libcxx Library Packages for your target architecture(s) for installation.
- 'If not done, Embedded Studio will download the specific package for your project. See next steps.'
- Press Next to continue the download and installation.
The library is now ready to use and can be enabled in new and existing projects.
Generic project setup steps
- Open or create a project.
- Option the project options and go to Code -> Libraries.
- In "libcxx Library" select "Yes" or "Yes (No Exceptions)".
- Optional, if you select Yes and you are using std functions that could throw exceptions make sure that project option "Code > Code Generation > Enable Exception Support" is set to Yes
- Press OK to save the project options.
- If the specific package for your project has not been installed, yet, Embedded Studio prompts to download and install the package now.
- Press Yes.
- Press Next to continue the download and installation.
The project is now configured to use the C++ standard library. Include the necessary headers and start using the library functions.
Enabling Exception Support
To enable exception support in your C++ project the following must be considered:
- Make sure your library is installed as explained above. (Project option libcxx Library = Yes)
- Set project option "Code > Code Generation > Enable Exception Support" to Yes.
- Make sure that sections readonly and readexec are placed in your linker script.
Changing the C++ standard
Per default C++ support is set to gnu++98. If you are using more modern features of C++ make sure to change the standard to the respective version in project options under Code->Compiler->C++ Language Standard