Need Help Compiling a Plugin

Discussion forum for C++ and script developers who are using the QCAD development platform or who are looking to contribute to QCAD (translations, documentation, etc).

Moderator: andrew

Forum rules

Always indicate your operating system and QCAD version.

Attach drawing files, scripts and screenshots.

Post one question per topic.

Post Reply
333onlyhalfevil
Junior Member
Posts: 24
Joined: Fri Apr 28, 2023 12:39 pm

Need Help Compiling a Plugin

Post by 333onlyhalfevil » Mon Jul 31, 2023 5:51 pm

Hello everyone:

I'm currently trying to follow the "Creating a QCAD Plugin" tutorial found here: https://qcad.org/en/tutorial-creating-a-qcad-plugin

I can't seem to get the three example files from the tutorial to compile. Note that I'm on Windows 7, Visual Studio 2017, and my installed version of Qt is 5.13.2. When I attempt to run qmake (I believe to build the makefile from which to use nmake) on exampleplugin.pro, it doesn't seem to do anything. It runs and then ends without outputting anything to the terminal and it doesn't appear to create any makefiles anywhere. What should I do?

I've never tried to compile a C++ file before so I'm probably doing something newbie.

Note that I'm trying to run qmake using the Developer Command Prompt for VS 2017. If I run the exact same command using either the Qt terminal or the terminal within VSCode, I get an error stating:
Project ERROR: Cannot run compiler 'cl'. Output:
===================
===================
Maybe you forgot to setup the environment?

I'm assuming using the VS 2017 developer terminal is the right approach since it seems to run but maybe not?

Also, does it matter where the 3 tutorial exampleplugin files are located? I downloaded the source code and created a folder within the plugins folder to contain the three files and I'm trying to compile them from there. Is that the right idea?

Another thing to note is that my VSCode, when viewing an entire folder containing the QCAD source code with the plugin files included within the plugins folder, throws errors stating that the #include statements can't be located. Maybe that's the problem?

I'm stuck and aren't sure what I should try next. Any help with this would be greatly appreciated. Thank you in advance for your time/replies.

User avatar
andrew
Site Admin
Posts: 9063
Joined: Fri Mar 30, 2007 6:07 am

Re: Need Help Compiling a Plugin

Post by andrew » Tue Aug 01, 2023 8:57 am

Compiling C++ Plugins can be very involved.

Are you sure you need a compiled plugin? What are you trying to achieve?

It might be a lot easier to use the script interface for what you are trying to do.

333onlyhalfevil
Junior Member
Posts: 24
Joined: Fri Apr 28, 2023 12:39 pm

Re: Need Help Compiling a Plugin

Post by 333onlyhalfevil » Fri Aug 04, 2023 5:16 pm

I'm not trying to program anything in particular. Just simply trying to learn / make it through the tutorial.

I have made a bit of progress since my original post. I can manage to get through qmake and get the makefile now, however, when using nmake it kinda works but eventually stops and throws a u1077 return code 0x2 error and then stops running. Note that I get the exact same error when trying to compile from source as well. I'm currently looking around online and trying things with no luck so far since most postings regarding the error are for other projects.

Do you know of any easy ways to get this error to go away, by chance?

333onlyhalfevil
Junior Member
Posts: 24
Joined: Fri Apr 28, 2023 12:39 pm

Re: Need Help Compiling a Plugin

Post by 333onlyhalfevil » Tue Aug 15, 2023 5:35 pm

Still trying to figure this out.

The problem I'm running into now is that the compiler can't instantiate an abstract class because RPluginInterface::initTranslations(void) is abstract.

Code: Select all

release\moc_RExamplePlugin.cpp(115): error C2259: 'RExamplePlugin': cannot instantiate abstract class
release\moc_RExamplePlugin.cpp(115): note: due to following members:
release\moc_RExamplePlugin.cpp(115): note: 'void RPluginInterface::initTranslations(void)': is abstract
D:\QCAD\src\core\RPluginInterface.h(90): note: see declaration of 'RPluginInterface::initTranslations'
jom: D:\QCAD\plugins\QCADplugin\Makefile.Release [release\moc_RExamplePlugin.obj] Error 2
jom: D:\QCAD\plugins\QCADplugin\Makefile [release] Error 2
That's a problem from QCAD's end, right?

333onlyhalfevil
Junior Member
Posts: 24
Joined: Fri Apr 28, 2023 12:39 pm

Re: Need Help Compiling a Plugin

Post by 333onlyhalfevil » Fri Aug 18, 2023 6:45 pm

I managed to get it figured out and have a working example plugin now. Thanks anyways.

That was certainly a journey for me so I'm going to use the remainder of this post to dump a whole bunch of information related to plugins and compiling with the hopes that it helps whoever might find themselves here in the future. Note that I'm on Windows 10 and have not tested anything on Mac, Linux, or any other versions of Windows so take the following with a grain of salt.

For convenience, here is the link to the creating a QCAD plugin tutorial:
https://qcad.org/en/tutorial-creating-a-qcad-plugin

First off, I'd recommend that you learn how to successfully compile from source before attempting to compile a plugin. For your convenience, here is a link to the Compiling QCAD from Sources tutorial:
https://qcad.org/en/component/content/a ... om-sources
There are two reasons you need to start with learning how to compile QCAD from sources. The first reason is that the tutorial itself is better and contains more information about compiling than does the plugins tutorial. The second (and primary) reason is that, in order to successfully compile a plugin, you're going to need some files that (to the best of my knowledge) you can only obtain through compiling from sources. If you look at exampleplugin.pro within the plugins tutorial, notice that the last line is referencing the qcadcore, qcadgui, and qcadecmaapi libraries (which are *.lib files). You have to compile from sources in order to get them and, if you don't have them, the compiler will throw an error and exit prematurely when you're trying to compile your plugin.

To do the compiling, I used the x86_x64 Cross Tools Command Prompt for VS 2017 ran as Administrator. When you install Visual Studio, it'll install multiple command prompts so you need to make sure to use the correct one. Notice that the Qt installer for Windows is an x86 installer whereas the Qt installers for Mac and Linux are x64. If you're running a 64bit version of Windows, you're going to need to use the same command prompt that I used so you can cross over the 32bit Qt installation into a 64bit QCAD installation. If you used the x86 QCAD installer, I could imagine you need to use the x86 Native Tools Command Prompt instead.

I could imagine that it doesn't matter which command prompt you use as long as the programs you're using it to run are the same. I recommend you use the one I mentioned in the paragraph above because you'll have everything you need to do the QCAD/plugins compiling ready to go. If you use another terminal, you're going to need to make sure your environment is set up correctly or your compiler is going to throw an error (jom will throw Error 2 and nmake will throw Error U1077 return code 0x2) and exit prematurely when you're trying to compile your plugin. At a minimum, you need to try to run link.exe and nmake.exe (or jom) and see if you get a response. If you get a command not found reply then you need to add one or both of those programs to your PATH environment variable. Note that I didn't use another terminal other than the one I mentioned in the above paragraph so there might be more that you need to do other than this.

The jom Error 2 and/or the nmake Error U1077 return code 0x2 errors mentioned in the paragraph above are errors you're probably going to run into at some point (unless your perfect). Running into this error over and over again was annoying for me because the error message doesn't necessarily tell you what is wrong (sometimes it does) and there are a bunch of different issues that could be causing it which makes searching the internet for a solution difficult. If you're finding yourself getting this error and don't know what's wrong, here are some things you can try. (1) Make sure your environment is set up correctly and that the locations of all the programs you need (including programs which get ran by the programs that you run) can be found by whatever command prompt you're using (you do this by placing their locations within the PATH environment variable). (2) Make sure your antivirus program isn't flagging anything created by qmake as a potential virus and blocking your command prompt from accessing it (you might need to disable your antivirus when compiling QCAD/plugin). (3) Make sure the location of the QCAD sources isn't too deep with too long of a location path name (if the location path contains too many characters, the compiler will exit prematurely when you're trying to compile your plugin). (4) Make sure you're using the correct bit version of the programs (i.e., x86 or x86_64) and also possibly the correct program for whatever CPU architecture you have. (5) Make sure you don't have any MSYS programs in your PATH environment variable because, if you do, qmake will place Unix commands in the makefiles instead of Windows commands and the compiler will throw an error and exit prematurely when it runs into a Unix command (if you have cygwin installed you should uninstall it as it can cause this issue).

You can skip step 3 on the Compiling QCAD from Sources tutorial. I couldn't find and get access to Teigha and it didn't come up or matter for me. For step 4, notice that there's a type in the run qmake line (it's missing a .2). The correct command to run is:

Code: Select all

c:\Qt\Qt5.13.2\5.13.2\msvc2015_64\bin\qmake -r CONFIG+=ractivated
For step 5, I'd recommend that you don't install and use cygwin. It can cause qmake to put unix commands in the makefiles which will ruin your attempts to compile. Also, it doesn't have an uninstaller so if you ever want to remove it for whatever reason, you're going to end up searching around on the internet for how to do so. Uninstalling it was a pain for me because I kept having permissions issues (even though I was trying to delete it as an Administrator) and I ended up having to use a command prompt to forcibly delete it. Another strange thing to note about cygwin is that uninstalling it caused the compiler to change up the order in which it went through all of the QCAD files (weird since it's supposedly a completely separate program that wasn't ever ran during all this). If you really want a Linux terminal in Windows, I'd recommend git bash instead. For convenience, here is the link to where you can download it: https://git-scm.com/downloads I'd also recommend that you install and use jom instead of nmake since jom is faster because it uses all available CPU cores while nmake doesn't.

Before you start trying to compile QCAD from sources, you need to update the console.pro file located in src/console. If you open that file in a text editor, you'll see that it includes a Unix command which will cause your compiler to throw an error exit prematurely when trying to compile QCAD from sources because mv is not a windows command. You need to add in a win32 if statement to that file that includes the same command but in Windows format. For your convenience, here is the file I used.

Code: Select all

include( ../run/run.pri )

CONFIG += console
TARGET = qcadcmd.com

win32 {
    QMAKE_POST_LINK = ren "D:\QCAD\release\qcadcmd.com.exe" "qcadcmd.com"
}
else {
    QMAKE_POST_LINK = mv "$${DESTDIR}/qcadcmd.com.exe" "$${DESTDIR}/qcadcmd.com"
}
Notice in the Windows command line that I manually typed out the appropriate directory path. You need to change this to whatever directory path you're using. There's probably a better way to do it but I don't feel like figuring it out right now. Note that $${DESTDIR} will cause the compiler to throw an error and exit prematurely because it puts in forward slashes and windows needs backslashes.

This is enough information to (easily, hopefully) compile QCAD from sources successfully on Windows. Just make sure there's no plugin source files in your QCAD source code directory at this point since it adds in a whole layer of potential problems for you to run into. After you've successfully compiled QCAD from sources, you're ready to compile your plugin (I'm going to be referring to the example plugin from the Creating a QCAD Plugin tutorial for the remainder of this post).

Within your completed QCAD compiled from sources directory, navigate to src/3rdparty, create a folder called exampleplugin, and place the three files from the Creating a QCAD Plugin tutorial within the directory you just created. I don't believe the name of the directory matters, however, it is good practice to name it something similar to whatever your plugin is called. The location of where you put this folder doesn't matter either as long as the reference within exampleplugin.pro points to the shared.pri file within your completed QCAD compiled from sources directory. Note that you can't have it point to the shared.pri file of a QCAD installation installed by one of the main installers because the QCAD installation directory created by the main installers won't have the qcadcore, qcadgui, and qcadecmaapi LIBS files the plugin needs. If you try, the compiler will throw an error and exit prematurely.

You need to edit your RExamplePlugin.h file and make it implement ALL of the functions of the RPluginInterface.h interface. The RPluginInterface.h file from the QCAD source code has a function in it called initTranslations() and the RExamplePlugin.h file from the Creating a QCAD Plugin tutorial is missing a line that implements that function. For your convenience, here is an updated RExamplePlugin.h:

Code: Select all

#include <QObject>
#include <QScriptEngine>

#include "RPluginInterface.h"

class RExamplePlugin : public QObject, public RPluginInterface
{
    Q_OBJECT
    Q_INTERFACES(RPluginInterface)
#if QT_VERSION >= 0x050000
    Q_PLUGIN_METADATA(IID "org.qcad.exampleplugin")
#endif

public:
    virtual bool init() { return true; }
    virtual void uninit(bool) {}
    virtual void postInit(InitStatus status) {}
    virtual void initScriptExtensions(QScriptEngine& engine) {}
    virtual void initTranslations() {}
    virtual RPluginInfo getPluginInfo();
    virtual bool checkLicense() { return true; }
};
If you try to compile your example plugin without adding the virtual void initTranslations() {} line to the RExamplePlugin.h, the compiler will throw the error shown in my previous post and exit prematurely.

This is enough information to (easily, hopefully) create a QCAD plugin successfully on Windows. Doing so is similar to compiling QCAD from sources. To do so, cd into your exampleplugin folder you created from two paragraphs above. Then run qmake. I left out the -r and the CONFIG+=ractivated from the qmake line and the example plugin worked fine. I'm not sure if it matters or not as I didn't try it using -r and/or CONFIG+=ractivated. I wouldn't be surprised if it doesn't matter. After qmake is finished, you run nmake release (or nmake debug or jom release or jom debug).

At this point, you should have your three example plugin files within the plugins folder of your completed QCAD compiled from sources directory. You can then copy/paste those three files into the plugins folder of your main QCAD installation. It should work and you should be able to see your example plugin information within the Plugins tab of Help-->About when your main QCAD installation is running.

That's all the information I have on this. I hope it helps out someone at some point.

Post Reply

Return to “QCAD Programming, Script Programming and Contributing”