compile c++ code in .c file

Tip / Sign in to post questions, reply, level up, and achieve exciting badges. Know more

cross mob
BaT_3785171
Level 2
Level 2
First like given

Project : 43xxx_Wi-Fi
IDE : WICED-Studio-6.2.1.2-IDE

I added sntp.c (WICED/network/LwIP/ver2.0.3/src/apps/sntp/sntp.c) file for compilation in LwIP.mk file
as shown below.
$(NAME)_SOURCES +=  ver$(VERSION)/src/apps/sntp/sntp.c

In this sntp.c file one header file is included to meet my project requirements.
For suppose say #include "My_File_Sntp.h"

When i try to compile, compiler is throwing error.
Reason is My_File_Sntp.h file is having C++ stuff (like class declaration,keyword bool etc...)
If i change extension of file sntp.c from .c to .cpp then compilation is successful.

I came to know from googling that
By default, gcc selects the language based on the file extension,
but you can force gcc to select a different language backend with the -x option

My question is:
What changes i have to do in makefile so that only sntp.c file
gets compiled in backend using c++ compiler without changing extension?

0 Likes
1 Solution
RaktimR_11
Moderator
Moderator
Moderator
500 replies posted 250 replies posted 100 replies posted

I did not really understand the end-case objective for you. It seems to me you are asking GCC specific settings and you want to know where in WICED you can modify the standard settings and include -x flag. Kindly provide gcc comand line statement that you want to use and I can try providing the equivalent makefile flags in WICED. On a very top level, WICED Studio uses the compiler settings as mentioned in 43xxx_Wi-Fi/tools/makefiles/wiced_toolchain_ARM_GNU.mk. For a particular application like sntp for lwIP, you have to create your own makefile where you need to add the -x flag like the implementation done in wiced_toolchain_ARM_GNU.mk/ application.mk (if you don't want the global compiler settings to change)

It should be something on the lines of  $(NAME)_CFLAGS += -xC++ in your application.mk file

View solution in original post

1 Reply
RaktimR_11
Moderator
Moderator
Moderator
500 replies posted 250 replies posted 100 replies posted

I did not really understand the end-case objective for you. It seems to me you are asking GCC specific settings and you want to know where in WICED you can modify the standard settings and include -x flag. Kindly provide gcc comand line statement that you want to use and I can try providing the equivalent makefile flags in WICED. On a very top level, WICED Studio uses the compiler settings as mentioned in 43xxx_Wi-Fi/tools/makefiles/wiced_toolchain_ARM_GNU.mk. For a particular application like sntp for lwIP, you have to create your own makefile where you need to add the -x flag like the implementation done in wiced_toolchain_ARM_GNU.mk/ application.mk (if you don't want the global compiler settings to change)

It should be something on the lines of  $(NAME)_CFLAGS += -xC++ in your application.mk file