-
Notifications
You must be signed in to change notification settings - Fork 221
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
[FEATURE]I hope to release a library based on the C language. C++ libraries are very unfriendly to embedded sdk environments. #433
Comments
Hi @ueJone , i don't think there is estimation for rewriting C++ code to C. But you can use C wrapper functions to call API directly from C source code. Many embedded libraries works like that. |
Thank you for your reply. I will try this method. Thank you again |
The IDE I am using is MDK-Arm. I test other C wrapper functions and they worked properly, but there will be many compilation errors when I compile the ERPC library. It seems like we need to open C++11. so I need to switch the compiler from AC5 to AC6. In this case, I will need to spend a long time adapting the project to AC6. |
Are you sure you are compiling erpc_client_manager.cpp here with cpp compiler and not c compiler? |
The compiler is ARM Compiler integrated by MDK 5.39.(As shown in the figure).I have successfully compiled demo of C++ with the same configuration, so I think it could support compiling the code of C++. And the demo of C++ will be shown below. // robot.cpp
#include <iostream>
#include "robot.h"
void Robot::sayHi()
{
std::cout << "Hi, I am " << name_ << "!\n";
} // robot.h
#pragma once
#include <string>
class Robot
{
public:
Robot(std::string name) : name_(name) {}
void sayHi();
private:
std::string name_;
}; // robot_c_api.cpp
#include "robot_c_api.h"
#include "robot.h"
#ifdef __cplusplus
extern "C" {
#endif
void Robot_sayHi(const char *name)
{
Robot robot(name);
robot.sayHi();
}
#ifdef __cplusplus
}
#endif // robot_c_api.h
#pragma once
#ifdef __cplusplus
extern "C" {
#endif
void Robot_sayHi(const char *name);
#ifdef __cplusplus
}
#endif |
Hi @ueJone
|
After enabling cpp11, there are no more errors mentioned above. But the original SDK code will have many conflicts related to C++. Because I have few interfaces for RPC, so I plan to implement it myself using C language. |
hi @ueJone If you will implement it in c, I sure there will be lot of interest of it (as it will have much less fingerprint), so please share it. (I had a plan to do it one day, but I don't really have time for it) |
Hi @amgross I compiled erpc into a static library with the cpp switch. But the API generated by IDL files is also in C++, so I still need to open cpp to compile my code with the API. Therefore, a conflict arose. Now I have a question: Compile the API interface files into static libraries first and can I call the API in my own code without the cpp switch? It seems that the conflicting are from the standard libraryThere will also be many grammar errors at the same timeIn addition, the interface I wrote is a temporary solution. It's almost a frame of fixed format data, and the functionality is just too simple. |
Hi, as i mentioned before, you can generate C api. Only implementation is in c++. |
Is that right? First, use the C++compiler to compile ERPC and the APIs generated by generpc into static libraries, and then compile my code with the both libraries by the C compiler. |
I also using pure c code with erpc library compiled in cpp. |
@ueJone It is possible for you to export minimal project -> Publicly available sdk+init code+erpc call - without application logic. Something like minimal publicable project export so we can try to modify build to make it working? |
project path: bsp/hc32f4a0_app/project.uvprojx IDL file: /*!
* Copyright (c) 2024, Z.
*/
@output_dir("erpc_python")
program myRPC
interface Binary {
oneway sendBinary(binary a)
} SDK: |
I compiled the erpc_c and API files separately into static libraries, then add them into my project, compiled and ran them successfully. Thranks! However, the api files generated by generpc must also be compiled into a library to use, which is a bit too tedious |
Indeed the .h files that auto generated are the API and needed to be used also outside the erpc library. |
I think the limitation you are facing is because you are using old compiler type and you should switch to the newer one: But i will try in a week to use your compiler with your project. But if i member correctly in NXP when we support MDK/keil we switched to newer compiler immediatly, when it was released due to compilation issue we were facing. |
Yes, I think so. It is best if the api file that auto generated can be used with the c compiler. I want to wait a few days before closing this issue, beacuse I'm looking forward to the test results of @Hadatko |
Soryy busy week. I installed IDE so far. Next week i should have plenty of time |
I didn't have. Sorry again. Too many projects. But i think the only way would be upgrading compiler as in link above. |
Is your feature request related to a problem? Please describe
Describe the solution you'd like
Describe alternatives you've considered
Steps you didn't forgot to do
Additional context
The text was updated successfully, but these errors were encountered: