Error Compiling CMake Project
-
Hi I am trying to compile Cutelyst SimpleMail on Windows in Qt Creator. The developer doesn't know much about Windows only Linux so I probably won't be able to get much help there. Thus I am posting here.
This project is a CMake project and to open it I opened the CMakeLists.txt file using Qt Creator. All the headers and source files are present. I am getting errors like this when trying to build the project:
C:\Users\Josh\Documents\program stuff\SimpleMail\sender.h:21: error: C1083: Cannot open include file: 'QObject': No such file or directory
This error arises from an include statement. Other include statement errors include QByteArray, QFile, QTCore/QSharedDataPointer, and QtCore/QList.
It looks like include works fine with QString, QtCore/QtGlobal, QPointer, QtNetwork/QHostInfo, QtCore/QMetaType, and QtNetwork/QSslSocket since I don't get any compile errors from those guys.
I suspect I need to include QtCore or another Qt component. Is this correct? If so how do I do so without a Qt Project file? Is something else going on?
Also are there any other ways of sending email from a Qt program that might be easier?
Thanks
-
@Crag_Hack said in Error Compiling CMake Project:
Is something else going on?
Probably. If the C++ compiler can find the QByteArray include it most definitely should be finding the QObject include. There could be something odd being passed to the compiler by the CMake generated makefile.
I can confirm it compiles cleanly in a Linux environment with Qt 5.15.2
Things to try:
- Try putting the source and build folder in location that does not have space in the path.
- Try adding
set(CMAKE_VERBOSE_MAKEFILE ON)
after the find_package calls in CMakeLists.txt and rebuilding. You should get more verbose output from make.
If it still will not fly then you should tell us exactly what version of CMake, Qt, and tool chain (compiler etc.) that you are using. Along with that include the compiler command line (Qt Creator "Compile Output" tab) and compilation output leading up to the error message like this:
[ 97%] Building CXX object demos/async1/CMakeFiles/async1.dir/async1.cpp.o cd /tmp/build-simple-mail-master-Desktop_Qt_5_15_2_GCC_64bit-Debug/demos/async1 && /usr/bin/g++ -DLOCALSTATEDIR=\"\" -DQT_CORE_LIB -DQT_DISABLE_DEPRECATED_BEFORE=0x050f00 -DQT_NETWORK_LIB -DQT_NO_CAST_FROM_ASCII -DQT_NO_CAST_FROM_BYTEARRAY -DQT_NO_CAST_TO_ASCII -DQT_NO_KEYWORDS -DQT_NO_SIGNALS_SLOTS_KEYWORDS -DQT_NO_URL_CAST_FROM_STRING -DQT_STRICT_ITERATORS -DQT_USE_FAST_OPERATOR_PLUS -DQT_USE_QSTRINGBUILDER -I/tmp/build-simple-mail-master-Desktop_Qt_5_15_2_GCC_64bit-Debug/demos/async1 -I/tmp/simple-mail-master/demos/async1 -I/tmp/build-simple-mail-master-Desktop_Qt_5_15_2_GCC_64bit-Debug/demos/async1/async1_autogen/include -I/tmp/simple-mail-master/SimpleMail -I/tmp/simple-mail-master/src -isystem /home/chrisw/Qt/5.15.2/gcc_64/include -isystem /home/chrisw/Qt/5.15.2/gcc_64/include/QtCore -isystem /home/chrisw/Qt/5.15.2/gcc_64/./mkspecs/linux-g++ -isystem /home/chrisw/Qt/5.15.2/gcc_64/include/QtNetwork -g -fvisibility=hidden -fvisibility-inlines-hidden -fPIC -std=c++11 -o CMakeFiles/async1.dir/async1.cpp.o -c /tmp/simple-mail-master/demos/async1/async1.cpp ...
Also are there any other ways of sending email from a Qt program that might be easier?
None that immediately spring to mind.
-
@ChrisW67 I didn't clone the whole project, instead I copied the src folder to my computer and tried to use the CMakeLists.txt in there instead... I suspect this is the source of the issues, sorry about that. I'm not super familiar with cloning git projects.
-
So I was able to build the SimpleMail project successfully after cloning but now I have another problem. The same problem as here. I was getting unresolved external symbol errors when trying to build my main program after including the SimpleMail header file. So I added the code below to my project file for the program that needs to support email.
**added to project file** CONFIG += link_pkgconfig PKGCONFIG += simplemail2-qt5
Then I tried throwing the cutelyst SimpleMail dll in the main program debug build directory and no luck. I get
**error upon building my program** simplemail2-qt5 development package not found
I'll keep trying but if anybody knows an obvious answer please let me know. I always have the hardest problems building projects, coding them is so easy!
We have the following files in the src subdirectory of the SimpleMail build directory which must be the ones to include for the main program project the question is how to assuming I'm right about this... donno why the author couldn't just include detailed instructions, maybe this thread can serve as that. Is it the wrong package name? Should there be no - in it?**files in src subdirectory of SimpleMail build directory** SimpleMail2Qt5.dll SimpleMail2Qt5.dll.manifest SimpleMail2Qt5.exp SimpleMail2Qt5.lib SimpleMail2Qt5.pc
-
The "unresolved external symbol" errors come from the link phase of compilation.
At link time the linker will look for named libraries in standard and additional locations. The project file needs to provide information to allow the linker to find the relevant libraries. One way to do this is to use pkgconfig, which is usually a Linux/UNIX tool but also exists in a MingW environment. You are using the Microsoft tool chain to build your project, so pkgconfig is a non-starter. Remove those modifications.
QMake uses the
LIBS
variable to provide link-time information to the linker. There are two parts to this information:- Optionally, non-standard paths to be searched for the library files.
- The name or names of libraries to link. These are the base name of the library. In the Microsoft tool chain this maps to the file
libraryname.lib
.
For your project something like:
LIBS += -LC:/some/path/to/simplemaillibs -lSimpleMail2Qt5
(The options are upper and lower case L)
donno why the author couldn't just include detailed instructions,
Primarily because in the Linux environment the pattern is generally predictable and consistent. To build the library:
./configure # or an equivalent make make test # sometimes make install
(This library uses CMake instead of configure) . Install is generally into a default location that will be found by default. When pkgconfig data is provided as part of the project then the options you need in the LIBS variable are available by running:
$ pkg-config --libs Qt5Core -lQt5Core
(something similar for the INCLUDE variable).
This is what the options you added were causing to happen. -
@ChrisW67 Awesome thanks, got things working easy I was able to build my project with SimpleMail integrated into it. One more question for now I can think of - when I build the Qt static exe do I have to plop the dll in the working directory? Anything else I need to do?
-
Assuming you have Qt from the online installer then you have a setup for dynamically linked executables.
In this case, yes, you would deploy theSimpleMail2Qt5.dll
(only) alongside your executable (and typically the relevant Qt DLLs) so it is found by default at run time.In a static executable the code drawn from libraries is compiled into your executable removing the need for the dynamically loaded library (DLL) at run time. To build a static Qt executable is a substantial undertaking involving building Qt itself from source code so that you have libraries suitable for static linking. You are probably not compiling a static executable for your application.