Comments (5)
Hi @orkfire,
If you are using C code, then unless it's already compatible with C++, it will need to be compiled as C. Your compiler is likely treating the C input as C++, so you may have to specify the language for your input files. For example, simple programs compiled with g++
can have language specified with -x
:
g++ *.cpp -x c *.c
Or, you could compile your C and C++ code separately and then use a C++ linker, e.g.
gcc -c *.c
g++ -c *.cpp
g++ *.o
Additionally, the C code will need extern "C" {}
guards to avoid the C++ compiler mangling names when calling C functions from C++. The FreeRTOS kernel header files already include this, but some library files may not, so you should use the format
extern "C" {
#include "some_c_header.h"
}
when including C header files that don't already have those guards.
from freertos.
Hi @orkfire,
If you are using C code, then unless it's already compatible with C++, it will need to be compiled as C. Your compiler is likely treating the C input as C++, so you may have to specify the language for your input files. For example, simple programs compiled with
g++
can have language specified with-x
:g++ *.cpp -x c *.cOr, you could compile your C and C++ code separately and then use a C++ linker, e.g.
gcc -c *.c g++ -c *.cpp g++ *.oAdditionally, the C code will need
extern "C" {}
guards to avoid the C++ compiler mangling names when calling C functions from C++. The FreeRTOS kernel header files already include this, but some library files may not, so you should use the formatextern "C" { #include "some_c_header.h" }when including C header files that don't already have those guards.
I tried using the extern "c" method, but it doesn't help, now I have a method to deal with it, First I using IAR build a static library using the c compiler, and then link it using c++ complier, it can work. but I don't think it is a good method when building a large project.
from freertos.
Hi @orkfire,
Adding extern "C"
doesn't automatically tell a compiler to compile specific code as C, it only tells a C++ compiler to not mangle certain C functions in C++ code so that compiled C code can be properly linked. You will still have to tell your compiler to compile C code with a C compiler and C++ with a C++ compiler. In the screenshot you posted, have you tried using the language setting "Auto (extension-based)"?
Additionally, have you taken a look at IAR's notes on mixing C and C++? One recommendation there is
If you want to use C code from your C++ application, consider building the C code in a separate (library) project. You can place the C (library) project in the same workspace as your C++ project for fast access.
from freertos.
Hi @orkfire,
Adding
extern "C"
doesn't automatically tell a compiler to compile specific code as C, it only tells a C++ compiler to not mangle certain C functions in C++ code so that compiled C code can be properly linked. You will still have to tell your compiler to compile C code with a C compiler and C++ with a C++ compiler. In the screenshot you posted, have you tried using the language setting "Auto (extension-based)"?Additionally, have you taken a look at IAR's notes on mixing C and C++? One recommendation there is
If you want to use C code from your C++ application, consider building the C code in a separate (library) project. You can place the C (library) project in the same workspace as your C++ project for fast access.
I tried the auto option, it doesn't work, if I using cmake or makefile, it may be very easy to organize the c and c++ file with a different compiler, but the IDE(IAR) is not that flexible. Maybe I should try using none IDE method to organize my project, os it will be very convenient.
from freertos.
Hi @orkfire,
Do you have any further questions on this, or can we close this issue?
Thanks
from freertos.
Related Issues (20)
- [BUG] Posix_GCC demo emits stack warnings HOT 5
- [BUG] HOT 4
- [BUG] Posix Gcc Demo Create Task Failed using cmake HOT 2
- [BUG] va_arg process error HOT 4
- [BUG] FULL_DEMO of CORTEX_M3_MPS2_QEMU_GCC doesn't work sometimes HOT 4
- Task suspending itself can remove itself from termination list HOT 6
- [DOC] Missing dependencies on Posix/Linux Simulator Demo for FreeRTOS HOT 2
- [Feature Request] Ability to Query Task Notification Status (pending or not) HOT 7
- FreeRTOS CLI - parameter with spaces HOT 2
- [BUG] Cellular demo doesn't build on windows HOT 7
- [BUG] Incorrect use of memset() in demo code HOT 2
- [Feature Request] Interruptible Blocking Statements HOT 4
- [DOC]
- [DOC] Where are the best practices? HOT 3
- FreeRTOS & Sparc V8 HOT 1
- [DOC] Documentation of non-obvious behaviour of mutex priority dis-inheritance HOT 8
- [BUG] Segment fault error caused by pxTopOfStack HOT 15
- [BUG] When vApplicationTickHook is in use, Cortex R5 UltraScale should save FPU context in tick handler HOT 11
- [BUG] Out of date text file HOT 1
- [BUG] Preprocessor sequence prevents plain text connections
Recommend Projects
-
React
A declarative, efficient, and flexible JavaScript library for building user interfaces.
-
Vue.js
🖖 Vue.js is a progressive, incrementally-adoptable JavaScript framework for building UI on the web.
-
Typescript
TypeScript is a superset of JavaScript that compiles to clean JavaScript output.
-
TensorFlow
An Open Source Machine Learning Framework for Everyone
-
Django
The Web framework for perfectionists with deadlines.
-
Laravel
A PHP framework for web artisans
-
D3
Bring data to life with SVG, Canvas and HTML. 📊📈🎉
-
Recommend Topics
-
javascript
JavaScript (JS) is a lightweight interpreted programming language with first-class functions.
-
web
Some thing interesting about web. New door for the world.
-
server
A server is a program made to process requests and deliver data to clients.
-
Machine learning
Machine learning is a way of modeling and interpreting data that allows a piece of software to respond intelligently.
-
Visualization
Some thing interesting about visualization, use data art
-
Game
Some thing interesting about game, make everyone happy.
Recommend Org
-
Facebook
We are working to build community through open source technology. NB: members must have two-factor auth.
-
Microsoft
Open source projects and samples from Microsoft.
-
Google
Google ❤️ Open Source for everyone.
-
Alibaba
Alibaba Open Source for everyone
-
D3
Data-Driven Documents codes.
-
Tencent
China tencent open source team.
from freertos.