Compilation QT Creator project using classic terminal and gcc/g++ - c++

I'm tired searching in internet.
I created a klient-serwer program, which shut down computer just by their IP's on specific port.I made whole thing in C, everything works perfectly, i'm compiling my project using gcc with -Wall option and I've got a clear results.
But I had to create GUI so i decided to use QT Creator IDE, I transfered code from C into C++ and i made GUI. Program works but I have to compile this using g++ with -Wall option.
Thing is, I cannot compile anything.
g++ my_project.cpp -o mypro -Wall
ERROR: fatal error: QMainWindow: directory don't exist (in my native language)
compilation terminated
(same with other source files)
Any ideas?
It's propably very easy, but believe me, I want to compile this and go to sleep. Cheers

Why don't you use qmake? First, you can edit your *.pro file and add any compiler flags you wish (see Mitch's comment). Then, if you execute qmake and then make, it will show you a sequence of compilation commands with proper flags, linker and include paths and so on. After that you can just reproduce that commands manually if your teacher wants so.

The error shows that the compiler is trying to open QMainWindow as if it was a directory (if the translation is correct) or at least failing to locate where the include files for Qt are. You probably need to provide some -I option to hint the compiler as to where the Qt headers are, and make sure that the #include directives are correct in your code.

Related

How do you keep track of warnings generated while compiling many different source files

I am using GNU g++ to compile an older c++ project with many source files. I am trying to get the project to compile without warnings using -Wall for version c++ versions 11 up to 17.
If I delete the entire build directory and remake everything from scratch, a large list of warnings appears. After fixing warnings generated by a specific file and recompiling, only warnings from that specific file are displayed, since the makefile detects that all other objects are up to date and the .cpp/.h files aren't modified.
Since doing the build from scratch is time consuming. My solution is digging into directories and deleting the objects, so I can recompile and see the warnings. This is okay, but somewhat tedious.
Is there any other solution. Is there a way to force the compiler to exit on a warning as if it was an error? I'm using GNU g++.
I am using -Werror and editing the makefile to add options for compiling only a few source files at a time. I think this is the best way. Thanks everyone.

qmake auto-generated Makefile compiler set incorrectly

We are doing a C++ project for our uni and its final phase is passing the whole thing into a graphical interface using Qt.
We use Qt5.4 and g++-5. These values have been set in the QtCreator project configuration by selecting the appropriate compiler, g++-5, and also adding options in the *.pro file such as -std=c++14 and so on.
Nevertheless we are being stumped by an important issue. No matter what we try, when running qmake so as to auto-generate the precompiled files, in any Makefile generated by it, the compiler is ALWAYS set to g++ and not g++-5. We are at the moment obliged to after using qmake having to change by hand the compiler in the Makefile on our own, even though we have told it EVERYWHERE that we are using g++-5 and not the normal g++.
We have tried solutions like in this question: Using c++14
And also changing the compiler in the mkspecs of the Qt SDK.
Both have been to no avail and we still can't get the auto-generated Makefile to use g++-5 unless we change it by hand.
Is this a Qt issue or are we doing a step incorrectly?
Thanks in advance.
Sorry for all the bother.
It is solved now, I had linked my g++ compiler to g++-5 when I installed it ages ago but had forgotten (both g++ and g++-5 work on my pc, but they are the same) so it wasn't being an error, just my pc configuration getting in the way, thanks for the help though.

Location of mpi.h

I have a code on my computer uses Petsc which depends on mpi. On my computer it works well. I put it on cluster, exported paths of gcc, Petsc and openmpi (although I was using mpich on my computer I hope openmpi will also work) to LD_LIBRARY_PATH and PATH. I also changed paths in makefile. Petsc, gcc, openmpi were all available on cluster so I did not configure anything. When I did make, compiler gave error:
fatal error: mpi.h: No such file or directory
I know I did not give complete information but I can tell more if needed. How can I make the Petsc to know where is mpi.h?
Typically, you should use mpicc (or mpicxx for C++) to compile instead of gcc (or g++ for C++). These commands are simple wrappers around gcc and g++ that simply add in the appropriate -I/path/to/mpi/includes and -L/path/to/mpi/libs automatically and should be included with your openmpi install. In the absence of that, simply add -I/path/to/mpi/includes in your command to compile the appropriate files. This tells the compiler where to look for the appropriate header files.
To answer the question. To prevent a C/C++ editor from showing errors as you tyoe in the "special code" just use:
#include </usr/include/mpi/mpi.h>
which seems to be a link -- but doing that turns off the errors in Netbeans editor so I can code without distraction.
Note: Using Ubuntu 18.04 Desktop as editing machine -- and testing run machine -- but I compile manually using mpic as noted previously.
sudo mpicc c_pi.c -o c_pi
and then...
mpiexec ./c_pi
hth

Compile SDL in Cygwin using g++

So for school I made a simple game using the SDL graphics library, and did it in Visual Studios C++. However, I must turn in the source code so that it will compile through Cygwin. I have tried so very hard to figure out the proper way to link everything, but just cannot do it.
Normally I would compile a normal .cpp file through Cygwin something like this:
g++ -W -Wall -pedantic -o test test.cpp
So my questions are:
What is the proper command line command in order to compile (with g++) SDL source code.
Also, how should I folder all the files so that when my instructor gets it, he can run the exact same command as I do?
Should I have the entire SDL library inside with the source code folder? I would like everything grouped so that all he has to do is run the proper command.
The simpler the better :)

Using GCC through Xcode to compile basic programs

So, I'm a brand new CS student, on a Mac, and I'm learning C++ for one of my classes. And I have a dumb question about how to compile my super basic C++ program.
I installed Xcode, and I'm looking through the documentation to try and figure out how to use it (and I highly suspect it's extremely overpowered for what I'm doing right now) and eventually end up going into Terminal and going "gcc [filename]". And I've got a screen full of text that starts with "Undefined Symbols", and goes on about trying to reference things, so I'm wondering if I didn't hook up something somewhere, especially as when I'm actually in Xcode with a C++ program open, most of the menu items are greyed out.
So. In really really basic terms. What did I miss doing, and how do I fix it? Is there a basic guide to Xcode? Most of the documentation is aimed at real developers, and I'm totally missing a lot of what is being assumed.
If XCode is installed then everything is set up correctly.
If you typed gcc on the command line then you invoked the 'C' compiler (not the C++ compiler). Usually this does not matter as GCC compensates by looking at the file extension. But what does matter is that it does not invoke the linker with the correct C++ flags.
What you should do (from the command line) is use g++
g++ <fileName>.cpp
By default the output file is a.out and placed in the same directory.
g++ has a flag to specify a different output name -o
g++ -o <outputName> <fileName>.cpp