libcpp | Embedded Systems C Library Support
kandi X-RAY | libcpp Summary
kandi X-RAY | libcpp Summary
This project supplies a C++ standard library and C++ ABI library that can be used for microcontroller-based embedded systems projects. This project is based on the clang libc++ and libc++abi libraries. Alternative implementations are provided for various files to support embedded systems usage. The builds are highly configurable, allowing you to create a libc++ and libc++abi set that is tuned specifically to your system's needs.
Support
Quality
Security
License
Reuse
Top functions reviewed by kandi - BETA
Currently covering the most popular Java, JavaScript and Python libraries. See a Sample of libcpp
libcpp Key Features
libcpp Examples and Code Snippets
Community Discussions
Trending Discussions on libcpp
QUESTION
I have a C++ function which I want to run from Python. For this I use Cython. My C++ function relies heavily on Eigen matrices which I map to Python's Numpy matrices using Eigency.
I cannot get this to work for the case where I have a list of Numpy matrices.
What does works (mapping a plain Numpy matrix to an Eigen matrix):
I have a C++ function which in the header (Header.h) looks like:
...ANSWER
Answered 2021-Dec-01 at 18:34Thanks to @ead I found a solution.
FlattenedMapWithOrder
has implementation so it can be assinged to an Eigen::Matrix
.
However, std::vector
does not have such functionality and since std::vector
and std::vector
are of a different type, they cannot be assigned to one another.
More about this here.
The implementation in FlattenedMapWithOrder
mentioned above is here.
To solve this, the function in the C++ code called from Cython need to simply have as input argument the matching type: std::vector
.
To do this, the C++ code needs to know the definition of type FlattenedMapWithOrder
.
To do this, you need to #include "eigency_cpp.h"
. Unfortunately, this header is not self contained.
Therefore, (credits to @ead) I added these lines:
QUESTION
I have 1 Cython .pxd file and 1 Cython .pyx file, the pyx file contains a cdef
class:
ANSWER
Answered 2021-Nov-07 at 06:06It should be clearly described this way:
- myclass.pyx is compiled into .so file
- But there are 2 kinds of stuff in a .so file
- Python definitions: Can be imported only with 'import'
- Cython definitions: Can be imported only with 'cimport'
The problem is import myclass
in another.pxd won't import myclass
because it is cdef
(Cython definition).
In another.pxd file, to import 'myclass', it must be either:
from myclass cimport myclass
- myvar2 will be:
cdef myclass myvar2
- myvar2 will be:
cimport myclass
- myvar2 will be:
cdef myclass.myclass myvar2
- myvar2 will be:
cimport some.path.to.myclass as myclass
- myvar2 will be:
cdef myclass myvar2
- myvar2 will be:
There may be a problem with exporting too, especially using Python build tool instead of cython3
and gcc
directly:
- __pyx_capi__ is not available in the .so file
myclass
is not public and aren't seen after importing
Thus better put the myclass
under public scope in myclass.pyx:
QUESTION
I'm using latest Cython with C++17 flag (above C++11 to have closure syntax) to GCC. This C++ sort in Cython doesn't seem allowing closure:
...ANSWER
Answered 2021-Nov-05 at 01:37I've tried to search and alter the code but these are the only ways:
- Use .hpp header
- Or use 'sorted' function of Python
No C++ closure syntax in Cython as per my internet search, use struct with operator overload instead.
QUESTION
I'd like to initialize a C++ STL vector by using the
...ANSWER
Answered 2021-Oct-21 at 12:37As mentioned in the comments, your desired constructor is not available inside Cython. AFAIK, Cython doesn't support templated constructors yet. As a workaround, you could use .assign()
, i.e.:
QUESTION
Suppose I have the following simple example of C++ inheritance in file.h
:
ANSWER
Answered 2021-May-20 at 20:49I have not tried Cyton, but std::shared_ptr
has an static cast function std::static_pointer_cast
. I think this will work
QUESTION
I have a bazel-based c++ project that has uses protos with the proto_library
rule.
My .bazelrc has an android config that specifies an android config (following the example here) with
...ANSWER
Answered 2021-Mar-05 at 22:11I've resolved this problem. The issue here was not about host linkopts with protoc/protobuf, but with another library (gflags) that used -lpthread
unconditionally. Adding the same android config and select statement used by protobuf fixed this issue (PR). The red herring about using a non-existent -lnotareallibrary
was a linker error for protoc, not my target executable.
In case it's helpful to describe the debugging process, I searched the autogenerated bazel-myreponame/external
directory's BUILD
files and .bzl
files for -lpthread
. (At first, I only thought to search BUILD files, which missed this library)
QUESTION
In Cython it's really easy to create a Python extensions class of C++ vector of int
ANSWER
Answered 2021-Feb-15 at 09:36Oops... just remove new
.
Like, malloc
, C++'s new
allocates memory and returns a pointer to it. Here want actually want to reference the object directly.
QUESTION
I don't have a problem that needs solving but was very puzzled by the following:
I'm using CMake (which uses gcc internally). Not sure if this is important.
Suppose I have a project consisting of a C++ static library LibCpp and a demo C++ executable DemoCpp, which links to and uses LibCpp. The library LibCpp is compiled from both C and C++ sources. The correct way to do this is for the C++ code files of LibCpp to inlucde all C headers as extern "C" {#include "c_header.h"}
. If this is done, the static library links fine and the executable DemoCpp sucessfully links to LibCpp. Everything works.
Suppose, that I forgot to put in the extern "C"
's and just include the C headers as C++ headers. As expected, the full project fails to link. However, and this is what puzzles me, the linking fails when DemoCpp tries to link to LibCpp! I would have expected it to fail already at linking the static library. However, the static library (e.g. LibCpp.a
file) are built just fine, it just cannot be used.
This is very puzzling to me, because to link the static library (I would think) the linker has to resolve the references into the code compiled as C. This is also annoying in my opinion, since I cannot rely on a library being "linkable to" only since the library itself managed to be linked. Am I missing something?
You do not need to look at below code examples, unless you don't understand my question or don't believe what I said.
...ANSWER
Answered 2020-Dec-11 at 16:40Because C++ supports function overloading, function names are "mangled" during the compilation process so that they have unique names in the object file. Using extern "C"
prevents that mangling from happening.
If you leave out extern "C"
when compiling, then call_c_function
is expecting to call a C++ function with the name add
, in particular the mangled name would be _Z3addii
. Since add
exists in a .c file it has the unmangled name instead of the mangled name, so now _Z3addii
is considered an external function just like printf
, and like all other external functions they are expected to be resolved at link time of the executable, not compile time, and not when the static library is created.
When you create a static library, you're not actually linking. You're just grouping several object files together into a larger archive. That way, when linking actually happens, you only need to link a single file instead of multiple.
QUESTION
When I want to use .pxd and .pyx files to use my C++ code within Python, I can use vector after importing libcpp.vector within the pxd file. Is it possible to write own C++ classes and use them in pxd files like vector is used (for example use std::array)?
On the one hand, libcpp seems to contain the pxd file for vector only, while on the other hand the cython compiler seems to do some extra tricks when dealing with vectors.
...ANSWER
Answered 2020-Nov-18 at 22:34There are two parts to Cython's wrapping of types such as std:: vector
:
The .pxd files it defines for your to
cimport
(e.g. https://github.com/cython/cython/blob/master/Cython/Includes/libcpp/vector.pxd). These are provided for your convenience (to save everyone the effort of re-writing the same files). They use standard Cython syntax and you can create similar files to wrap other classes.The auto-conversion to/from Python types documented here. This is built in to Cython and you cannot apply it to other types that you wrap. This should not prevent you from creating a usable wrapping though - you may just need to copy a little more data manually at the Python/C++ interface.
Wrapping std::array
in Cython is a bit challenging since Cython cannot readily handle numeric template arguments. There are a variety of tricks to persuade it to work that you can find on Stack Overflow and elsewhere (Interfacing C++11 array with Cython, Wrapping std::array in Cython and Exposing it to memory views) but none of them are great.
QUESTION
I am trying to install the Kivy package on Pycharm and for some reason it is giving me an error. Note its not from the pip, it works for other packages and it is updated. The reason why I am asking for help is because I dont understand the interpreters commands and errors so I would love some help. Thanks, I appreciate all the help I can get :)
The commad that I am using is -> pip install kivy
This is the given error
...ANSWER
Answered 2020-Nov-14 at 15:26Here are my experience with installing kivy:
- Make sure you don't use python version 3.9
- pip install kivy - does not work
create new project using Virtualenv and using python 3.7 (of course other versions can also work except 3.9)
then simply create requirements.txt file within root of your project if not yet exist and include kivy
Pycharm automatically asks if you want to install requirements.
Finally, verify
Community Discussions, Code Snippets contain sources that include Stack Exchange Network
Vulnerabilities
No vulnerabilities reported
Install libcpp
Support
Reuse Trending Solutions
Find, review, and download reusable Libraries, Code Snippets, Cloud APIs from over 650 million Knowledge Items
Find more librariesStay Updated
Subscribe to our newsletter for trending solutions and developer bootcamps
Share this Page