How to force compile C source by C++ compiler?
-
I am writing an application in C subset of C ++ and use Qt Creator as an IDE. I would like to know how to make Qt Creator to compile C code with a C ++ compiler.
Thanks in advance for answers!@fsb4000
AFAIK most compilers do that automatically when the file has a.c
extension?
Otherwise you would need to specify the corresponding flag for your compiler. Unfortunately this can't be done straight forward using qmake. -
I am writing an application in C subset of C ++ and use Qt Creator as an IDE. I would like to know how to make Qt Creator to compile C code with a C ++ compiler.
Thanks in advance for answers! -
Sorry for bad english, I think I do not accurately express.
- I am writing an application in C subset of C ++ and use Qt Creator as an IDE.
- Now it works like this:
gcc -c <some flags> main.o main.c gcc -o <app_name> main.o ....
- I want to test that my code works with C++ compiler. So I can test both C and C++ support. So I want similar to this:
contains(CPP, 1):{ QMAKE_CC = QMAKE_CXX QMAKE_CFLAGS = QMAKE_CXXFLAGS } else { CONFIG += use_c_linker }
It does not work, but it works like this:
contains(CPP, 1):{ QMAKE_CC = g++ QMAKE_CFLAGS = -std=c++14 <other flags> } else { CONFIG += use_c_linker }
But I want this to work at least with these three compilers: g++, clang, MSVC, not only g++.
-
Sorry for bad english, I think I do not accurately express.
- I am writing an application in C subset of C ++ and use Qt Creator as an IDE.
- Now it works like this:
gcc -c <some flags> main.o main.c gcc -o <app_name> main.o ....
- I want to test that my code works with C++ compiler. So I can test both C and C++ support. So I want similar to this:
contains(CPP, 1):{ QMAKE_CC = QMAKE_CXX QMAKE_CFLAGS = QMAKE_CXXFLAGS } else { CONFIG += use_c_linker }
It does not work, but it works like this:
contains(CPP, 1):{ QMAKE_CC = g++ QMAKE_CFLAGS = -std=c++14 <other flags> } else { CONFIG += use_c_linker }
But I want this to work at least with these three compilers: g++, clang, MSVC, not only g++.