How to force compile C source by C++ compiler?
-
wrote on 14 Nov 2016, 04:16 last edited by
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! -
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!@fsb4000 If you have a C++ compiler then you should have C compiler as well. Which compiler do you have? What file name extension do you use for your source code files (you should use .c for C)?
-
wrote on 14 Nov 2016, 07:44 last edited by fsb4000
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++.
wrote on 14 Nov 2016, 08:01 last edited by@fsb4000 said in How to force compile C source by C++ compiler?:
But I want this to work at least with these three compilers: g++, clang, MSVC, not only g++.
IIRC MSVC does not have any more a pure C compiler.
-
wrote on 14 Nov 2016, 10:05 last edited by fsb4000
I figured out.
Solution::contains(CPP, 1):{ QMAKE_CC = $$QMAKE_CXX QMAKE_CFLAGS = $$QMAKE_CXXFLAGS } else { CONFIG += use_c_linker }
Thank you all for for your time!
1/6