0

I've been using PyQt for years now and had to recode a project in C++ using CLion. I have managed (after awhile) to get the code building on my MacBookPro, but when I move the project to Windows 10, all hell broke loose! I've reloaded mingw with the x86 version and gotten everything to work except MOC and AUTOUIC. The only lines I changed in the CMakeLists.txt file between Oses were the ones that pointed to the Qt install. As I said, I'm new to all this in C++ and may have some 'mistakes' in my makefile, but it works on OSX but not in Windows!

I am able to compile ui and resources files manually and get the build to compile, but I don't know how to resolve this issue.

Any help and guidance would be greatly appreciated!

====================[ Build | crapsStarter | Debug ]============================ C:\Users\a.fireheart.CLion2019.3\system\cygwin_cmake\bin\cmake.exe --build /cygdrive/c/Users/a.fireheart/CLionProjects/crapsStarter/cmake-build-debug --target crapsStarter -- -j 6 [ 14%] Automatic MOC for target crapsStarter

AutoMoc subprocess error ------------------------ The moc process failed to compile "/cygdrive/c/Users/a.fireheart/CLionProjects/crapsStarter/craps.h" into
"/cygdrive/c/Users/a.fireheart/CLionProjects/crapsStarter/cmake-build-debug/crapsStarter_autogen/EWIEGA46WW/moc_craps.cpp".

Command ------- C:/Qt/5.14.1/winrt_x64_msvc2017/bin/moc.exe -I/cygdrive/c/Users/a.fireheart/CLionProjects/crapsStarter/cmake-build-debug -I/cygdrive/c/Users/a.fireheart/CLionProjects/crapsStarter -I/cygdrive/c/Users/a.fireheart/CLionProjects/crapsStarter/cmake-build-debug/crapsStarter_autogen/include -IC:/Qt/5.14.1/winrt_x64_msvc2017/include -IC:/Qt/5.14.1/winrt_x64_msvc2017/include/QtCore -IC:/Qt/5.14.1/winrt_x64_msvc2017/./mkspecs/winrt-x64-msvc2017 -IC:/Qt/5.14.1/winrt_x64_msvc2017/include/QtGui -IC:/Qt/5.14.1/winrt_x64_msvc2017/include/QtANGLE -IC:/Qt/5.14.1/winrt_x64_msvc2017/include/QtWidgets -I/usr/lib/gcc/x86_64-pc-cygwin/9.2.0/include/c++ -I/usr/lib/gcc/x86_64-pc-cygwin/9.2.0/include/c++/x86_64-pc-cygwin -I/usr/lib/gcc/x86_64-pc-cygwin/9.2.0/include/c++/backward -I/usr/lib/gcc/x86_64-pc-cygwin/9.2.0/include -I/usr/include -I/usr/include/w32api -DQT_CORE_LIB -DQT_GUI_LIB -DQT_WIDGETS_LIB --include /cygdrive/c/Users/a.fireheart/CLionProjects/crapsStarter/cmake-build-debug/crapsStarter_autogen/moc_predefs.h -o /cygdrive/c/Users/a.fireheart/CLionProjects/crapsStarter/cmake-build-debug/crapsStarter_autogen/EWIEGA46WW/moc_craps.cpp /cygdrive/c/Users/a.fireheart/CLionProjects/crapsStarter/craps.h

Output

make[3]: * [CMakeFiles/crapsStarter_autogen.dir/build.make:58: CMakeFiles/crapsStarter_autogen] Error 1 make[2]: [CMakeFiles/Makefile2:104: CMakeFiles/crapsStarter_autogen.dir/all] Error 2 make[1]: [CMakeFiles/Makefile2:84: CMakeFiles/crapsStarter.dir/rule] Error 2 make: * [Makefile:118: crapsStarter] Error 2

***************** My CMakeLists.txt file content *******************************

cmake_minimum_required(VERSION 3.15)
project(crapsStarter)

set(CMAKE_CXX_STANDARD 17)

#set(RESOURCES crapsResources.qrc)
set(CMAKE_AUTOMOC ON)
set(CMAKE_INCLUDE_CURRENT_DIR ON)
#set(CMAKE_AUTOUIC ON)
include_directories(cmake-build-debug/crapsStarter_autogen/include)

# Tell cmake where Qt is located
set(Qt5_DIR "C:/Qt/5.14.1/winrt_x64_msvc2017/lib/cmake/Qt5")
set(QT_INCLUDES "C:/Qt/5.14.1/winrt_x64_msvc2017/include")
MESSAGE("QT_INCLUDES: ${QT_INCLUDES}")

# Include a library search using find_package()
# via REQUIRED, specify that libraries are required
set(Qt5 NEED)
find_package(Qt5 COMPONENTS Core Gui Widgets REQUIRED)

set(SOURCE_FILES craps.cpp die.cpp crapsGame.cpp crapsResources.cpp)
add_executable(crapsStarter ${SOURCE_FILES})

# specify which libraries to connect
target_link_libraries(${PROJECT_NAME} Qt5::Core)
target_link_libraries(${PROJECT_NAME} Qt5::Gui)
target_link_libraries(${PROJECT_NAME} Qt5::Widgets)

craps.h

//
// Created by Arana Fireheart on 2/2/20.
//

#ifndef CRAPSSTARTER_CRAPS_H
#define CRAPSSTARTER_CRAPS_H

#include "ui_CrapsMainWindow.h"
#include "die.h"
#include <QMainWindow>

class CrapsMainWindow : public QMainWindow, private Ui::CrapsMainWindow {
    Q_OBJECT

    public:
        CrapsMainWindow(QMainWindow *parent = nullptr);
        void printStringRep();
        void updateUI();

    private:
        Die die1, die2;
        bool firstRoll = true;
        int winsCount = 0;

    public Q_SLOTS:
        void rollButtonClickedHandler();
};

#include "moc_craps.cpp"
#endif //CRAPSSTARTER_CRAPS_H

craps.cpp

#include <iostream>
#include <stdio.h>
//#include <QApplication>
//#include <QWidget>
//#include <QGridLayout>
//#include <QPushButton>
//#include <QLabel>
//#include <QPixmap>

#include "die.h"
#include "craps.h"
#include "ui_CrapsMainWindow.h"


CrapsMainWindow :: CrapsMainWindow(QMainWindow *parent) {
    // Build a GUI window with two dice.

    setupUi(this);

    Die die1, die2;
    bool firstRoll = true;
    int winsCount = 0;

    QObject::connect(rollButton, SIGNAL(clicked()), this, SLOT(rollButtonClickedHandler()));
}
void CrapsMainWindow::printStringRep() {
    // String representation for Craps.
    char buffer[25];
    int length =  sprintf(buffer, "Die1: %i\nDie2: %i\n", die1.getValue(), die2.getValue());
    printf("%s", buffer);
}
void CrapsMainWindow::updateUI() {
//    printf("Inside updateUI()\n");
    std::string die1ImageName = ":/dieImages/" + std::to_string(die1.getValue());
    std::string die2ImageName = ":/dieImages/" + std::to_string(die2.getValue());
    die1UI->setPixmap(QPixmap(QString::fromStdString(die1ImageName)));
    die2UI->setPixmap(QPixmap(QString::fromStdString(die2ImageName)));

    currentBankValueUI->setText(QString::fromStdString("100"));
}

// Player asked for another roll of the dice.
void CrapsMainWindow::rollButtonClickedHandler() {
//void Craps::rollButtonClickedHandler() {
    printf("Roll button clicked\n");
    die1.roll();
    die2.roll();
    printStringRep();
    updateUI();
}
Arana
  • 179
  • 1
  • 14
  • Your headers should not be in the list of `SOURCE_FILES`, only source `.cpp` files. You can include your headers using `target_include_directories(crapsStarter PUBLIC ${CMAKE_CURRENT_SOURCE_DIR})`. – Kevin Mar 02 '20 at 23:39
  • That looked funny to me too! I cobbled together most of what I have from 'tutorials' I found on the net. Shouldn't they already be included by reference in the cpp files? I thought that I shouldn't need them in the make file at all. Although, after removing them the MOC problem is unchanged... ☹️ – Arana Mar 03 '20 at 01:46
  • It is hard to know what might be wrong with out knowing more information, such as the contents of some of the headers/source files. One answer [here](https://stackoverflow.com/a/16481750/3987854) may contain some helpful info, and consider checking out the CMake `AUTOMOC` [docs](https://stackoverflow.com/a/16481750/3987854). – Kevin Mar 03 '20 at 03:58
  • Thanks for the hints. I've gotten a little clearer now on some of the details of the MOC and it's use. I guess that the real question lies in my definition of the QMainWindow subclass CrapsMainWindow. I believe I copied this from the example in the Qt docs, I am using the Slots and SIGNALS constructs/calls, hence the Q_OBJECT macro in the header file and the MOC invocation. This all seems to work (hidden bugs...?) when running under OS X. It's Windows 10 I'm having problems with... – Arana Mar 03 '20 at 14:07

0 Answers0