Compiling .c files using C++ and QT
i have a full application running and would to know if and how i open a new project (What type) and how to import the files in (.h, .c and make files)
finally how to set the compiler to a C compiler or the files to C++.
im new with QT.
Thanks in advance
Re: Compiling .c files using C++ and QT
In Qt everything is based on a .pro file. This is the project file as well as the basis for the make file. You can type one yourself. Or have a look at qmake to generate one for you based on your files.
Another, more practical, option is to download and install Qt Creator (Use "Qt4 SDK"). Start a new project, and add your files. All the Qt-specific stuff will be setup automatically and you needn't care about the C/C++ compiler settings either. That will all be taken care of automatically. It even comes with a gcc compiler ;)
(but to reply to the title: if you want to *force* C++, you could compile with "g++" instead of with "gcc". Just replace the one with the other, and it will be strictly C++ from that point forward. But in Qt projects it is best to let Qt Creator or qmake take care of that for you instead.)
Re: Compiling .c files using C++ and QT
@koder: Qt SDK does not install g++ for you (except the Windows one which comes with MingW) on other platforms you need to install g++ and make.
And on-topic, g++ (or mingw) got to compile C code not only C++, off course if your code is standard C. (most C code is also C++)
So i suggest you try to create a project, you can start with a "Empty project" and add your files (.c and .h) to that project and see if you will have any issues.
After you start, if you run into troubles you can post again, and depending on what you are trying to achieve we may be able to give you better advices.
NOTE: C++ compilers have the C header files from C standard library, but there are without .h extension and have 'c' prefix: like in place of "#include <stdio.h>" you will write "#include <cstdio>" and so on...
Re: Compiling .c files using C++ and QT
Quote:
Originally Posted by
Zlatomir
@koder: Qt SDK does not install g++ for you (except the Windows one which comes with MingW) on other platforms you need to install g++ and make.
Right, but on most other systems, gcc/g++ is already available. What I meant to say was: Even the compiler tool chain is taken care of automatically.
Quote:
Originally Posted by
Zlatomir
NOTE: C++ compilers have the C header files from C standard library, but there are without .h extension and have 'c' prefix: like in place of "#include <stdio.h>" you will write "#include <cstdio>" and so on...
Yes. But be careful. They are not always exactly the same as there C counterparts. And you'd need to put "std::" in front of the functions. So you either use <stdio.h> and printf *OR* you use <cstdio> and std::printf.
You can also solve this by putting "using namespace std;" at the global scope. This is not advised behavior. But since you are trying to get C code compiled in C++, it is an option.
Also, if you're using C functionality that is differs from C++, you can put an "extern" around it:
Code:
// C++ code
extern "C"
{
// C code
}
// C++ code
This may even be required when creating shared libraries for other C-only applications.