Home > Software engineering >  how to compile cpp file using cmd with Qt creator compiler
how to compile cpp file using cmd with Qt creator compiler

Time:11-03

I am using Qt creator and its compiler minGW, I want to compile .cpp (//which is created not using Qt)file using this Qt creator compiler in CMD

need compiling information in cmd using Qt creator

c:>c:>c:\Qt\Qt6.2.6\Tools\mingw1120_64\bin gcc -o c:\Users\chandresh.bs\Desktop\CplusApp\Hello.cpp Hello Access is denied.

c:>c:>c:\Qt\Qt6.2.6\Tools\mingw1120_64\bin g -o c:\Users\chandresh.bs\Desktop\CplusApp\Hello.cpp Hello Access is denied.

CodePudding user response:

About compiler

Firstly, you have to understand mingw-g compiler flags. The most simplest example of compiling using g is

g   hello.cpp -o hello.exe

In this example, hello.cpp is your file, flag -o tells to compiler that after this flag you provide name of executable. You are using Qt, so this example will not be able to compile your project. You need to link your project against Qt libraries. There's a lot of libraries and it will be quite difficult to do using only compiler.

How to do it correctly?

Any project with big amount of libraries and files uses some build system.You write configuration file for your build system, after that you generate Makefile or something like this, and using make you can compile it. It's pretty simple to use, because you don't need to remember flags, write long commands to compile something. Also, build system helps you to make your code cross-platform, because it can be used on any OS. For this purposes, Qt uses qmake, that do all necessary things and let you compile project with one click in Qt Creator. You can simply use qmake generated in Qt Creator:

  • Create folder build in your project folder
  • open cmd and change command-line directory using cd your-project-folder
  • Call qmake referencing the .pro file using qmake project_name.pro
  • Call make to compile your project using configuration files by make

It's simpler than linking anything for every file you have. Hope it will help you!

  • Related