This thread has been locked.

If you have a related question, please click the "Ask a related question" button in the top right corner. The newly created question will be automatically linked to this question.

CLANG doesn't recognize #include <string> and std::string my_string;

Other Parts Discussed in Thread: AM2432

Hi,

I'm using examples the AM2432 with mcu_plus_sdk_243x , as a base to my code.

If I use the hello world cpp example - I can  add    #include <string> then use std::string my_string;

If I use the tcpserver example - #include <string> is not recognized 

How can I make CLANG  recognize <string>   and std::string  ?

Thanks,

Eli

  • Hi Eli,

    By default, the TI CLANG assumes standard C syntax. If you want to use the C++ syntax, you will need to add the "-x c++" into the CFLAGS. 

    Take an example of the hello world cpp example, it appends the CFLAGS_cpp_common into the CFLAGS in its makefile:

    CPPFLAGS := $(CFLAGS_common) $(CFLAGS_$(PROFILE)) $(CFLAGS_cpp_common) where the CFLAGS_cpp_common is defined as:

    CFLAGS_cpp_common := \
    -Wno-c99-designator \
    -Wno-extern-c-compat \
    -Wno-c++11-narrowing \
    -Wno-reorder-init-list \
    -Wno-deprecated-register \
    -Wno-writable-strings \
    -Wno-enum-compare \
    -Wno-reserved-user-defined-literal \
    -Wno-unused-const-variable \
    -x c++ \

    Best regards,

    Ming

  • Hi Ming,

    I've opened the Hello_world_cpp example's  makefile and I don't know how to look for -x C++. (It does not appear in the text).

    It  says Automatically-generated file. Do not edit!

    Can you please tell me  how to add the -x C++  via CSS properties , or maybe there's some other way ?

    Thanks,

    Eli 

  • Hi Ming,

    I tried adding the "-x c++" to the compiler options - it still doesn't   accept "using....."

    I noticed that if I rename the main.c to main.cpp - it then accepts "using namespace std;"

    The problem is  that now on I have to put "extern C " in all function main.cpp   calls 

    Is there any #pragma or other way around renaming files ?

    Thanks,

    Eli

  • Hi Eli, 

    I am not aware of the existence of such #pragma. It makes sense that if you want the compiler to recognize the C++ syntax, then you have to tell the compiler that you are feeding a C++ file (*.cpp). What is the reason you want to have mixed C++ and C syntax in one file?

    The hello world example provides a way for you to mix the C file and C++ files in one CCS project, but not mix the C++ and C syntax in one file. 

    Why don't you put all the C++ related code in *.cpp files and all C related code in *.c files?

    Best regards,

    Ming

  • Hi Ming,

    It's a very good suggestion , I would use it for a new project.

    Unfortunately I have a very large already written in a certain way project.

    I'm just trying to add LwIP to it.

    Thanks,

    Eli