karastojko / mailio

mailio is a cross platform C++ library for MIME format and SMTP, POP3, IMAP protocols. It is based on the standard C++ 17 and Boost library.
Other
382 stars 102 forks source link

Cannot Build Project in Qt Creator on Windows 10 #106

Closed joshorenberg closed 1 year ago

joshorenberg commented 2 years ago

Hi I've tried a million things to fix this problem. I get the following error message when running CMake:

C:\Qt\Tools\CMake_64\share\cmake-3.19\Modules\FindPackageHandleStandardArgs.cmake:218: error: Could NOT find Boost (missing: Boost_INCLUDE_DIR system date_time regex) C:/Qt/Tools/CMake_64/share/cmake-3.19/Modules/FindPackageHandleStandardArgs.cmake:582 (_FPHSA_FAILURE_MESSAGE) C:/Qt/Tools/CMake_64/share/cmake-3.19/Modules/FindBoost.cmake:2193 (find_package_handle_standard_args) CMakeLists.txt:70 (find_package)

I tried setting the PATH environment variable to include both C:\boost_1_80_0\stage\lib and C:\boost_1_80_0\boost. I tried passing -DBOOST_ROOT=C:\boost_1_80_0 -DBOOST_INCLUDE_DIR=C:\boost_1_80_0\boost -DBOOST_LIBRARYDIR=C:\boost_1_80_0\stage\lib -DOPENSSL_ROOT_DIR=C:\OpenSSL-VC-64 as CMake arguments both with and without the =s. I then added the following line to CMakeLists.txt: SET(Boost_INCLUDE_DIR ${Boost_INCLUDE_DIR} "C:/boost_1_80_0"). I then got a little further but then get this error message:

C:\Qt\Tools\CMake_64\share\cmake-3.19\Modules\FindBoost.cmake:1643: error: file STRINGS file "C:/Users/Josh/Documents/program stuff/ReplicatorNew/ReplicatorNew/mailio/Boost_INCLUDE_DIR-NOTFOUND;C:/boost_1_80_0/boost/version.hpp" cannot be read. CMakeLists.txt:70 (find_package)
C:\Qt\Tools\CMake_64\share\cmake-3.19\Modules\FindPackageHandleStandardArgs.cmake:218: error: Could NOT find Boost (missing: date_time regex) (found version "0.0.0") C:/Qt/Tools/CMake_64/share/cmake-3.19/Modules/FindPackageHandleStandardArgs.cmake:582 (_FPHSA_FAILURE_MESSAGE) C:/Qt/Tools/CMake_64/share/cmake-3.19/Modules/FindBoost.cmake:2193 (find_package_handle_standard_args) CMakeLists.txt:70 (find_package)

I tried adding SET(BOOST_ROOT ${BOOST_ROOT} "C:/boost_1_80_0") to CMakeLists.txt with no luck.

I also added

#SET(CMAKE_INCLUDE_PATH ${CMAKE_INCLUDE_PATH} "C:/boost_1_80_0/boost")
#SET(CMAKE_LIBRARY_PATH ${CMAKE_LIBRARY_PATH} "C:/boost_1_80_0/stage/lib")

to CMakeLists.txt with no luck.

I'm ready to throw my computer out the window. What am I doing wrong? Also I built Boost with the PATH variable including C:\OpenSSL-VC-64\include\openssl and C:\OpenSSL-VC-64\lib. Thanks!

karastojko commented 2 years ago

Assuming that Boost and OpenSSL are correctly installed, here is the command from the Developer Command Prompt for VS which I use:

c:\mailio\build>c:\Bin\cmake-3.17.3\bin\cmake.exe -DBOOST_ROOT=c:\Install\boost_1_71_0 -DOPENSSL_ROOT_DIR=c:\bin\OpenSSL-Win64 ..

The mailio.sln file is generated which can be opened from VS to build the solution.

joshorenberg commented 2 years ago

Awesome thanks karastojko. I used Visual Studio CMake and the Visual Studio IDE and was able to build the project successfully. I scrapped using Qt Creator for the build it was more trouble than it's worth. I'm using Qt Creator however for my project and might switch some other time but not now. It shouldn't be a problem to use it with your libraries and code right? Right now I am getting undeclared identifier for message msg in the smtps_simple_msg.cpp example. When I try to build I get:

C:\Users\Josh\Documents\program stuff\mailio\include\mailio\message.hpp:29: error: C1083: Cannot open include file: 'boost/date_time.hpp': No such file or directory

for the line

#include <boost/date_time.hpp>

I tried manually fixing things but there's got to be something I'm doing wrong. For some reason it's not pointing to the boost headers. Any ideas why that might be? Thanks!

joshorenberg commented 2 years ago

Actually got a little further, added INCLUDEPATH += C:\boost_1_80_0 to the Qt project file. Then had to add INCLUDEPATH += "C:\Users\Josh\Documents\program stuff\mailio". Then I had to put

#include <mailio/include/mailio/message.hpp>
#include <mailio/include/mailio/smtp.hpp>
using mailio::message;
using mailio::mail_address;
using mailio::smtps;
using mailio::smtp_error;
using mailio::dialog_error;
using std::cout;
using std::endl;

before including windows.h in another part of my program some silly error from order of include statements. I was getting this error before changing the order of includes: C:\boost_1_80_0\boost\asio\detail\socket_types.hpp:24: error: C1189: #error: WinSock.h has already been included

joshorenberg commented 2 years ago

I am stuck at another point in the code. I used #define WIN32_LEAN_AND_MEAN to fix the Winsock.h already included error however I still get the error. I also tried including the mailio libraries before windows.h to fix the error as well. See here for more about the error. Before it occurred 5 times, after these modifications it occurs once. I include windows.h 4 times in my code so I think the cause of the error comes from somewhere outside of my code. You don't use the Win API at all in your library do you? I think there might be a redundant include somewhere in your code causing the error. Can you try on your end? I'll try using Visual Studio for the smtps_simple_msg.cpp example project when I have time it's just not working right now. I'm using the code straight out of smtps_simple_msg.cpp example. Thanks for the help :) I'm so close I can feel it.

karastojko commented 2 years ago

mailio does not use WinAPI directly but Boost.Asio definitely uses it. I do not use Qt Creator now, but I did in the past on Linux and I had no problems with Gcc. Do you use MinGW or MSVC together with Qt Creator?

joshorenberg commented 2 years ago

I am using MSVC 2019. I can create a project from scratch with your sample code when I have time but not sure when that would be...