Getting Linker error for my dll



  • When I compile a dll library I am getting "unresolved external symbol _main at WinMain@16"

    This is a library and is meant to be a plugin using the qt plugin API. I don't understand why it is looking for a main function.

    EDIT: This is a Qt specific issue since the source of the error is qtmaind.lib

    I am not sure if code will help but just in case the code for the dll (so far) is below. (FYI this plugin is an interface with .NET)

    // from the h file stgplugindotnetplatform.h:
    #ifndef STGPLUGINDOTNETPLATFORM_H
    #define STGPLUGINDOTNETPLATFORM_H
    
    #include "stgplugindotnetplatform_global.h"
    #include "../StgPluginClasses/IStgPluginPlatform.h"
    #include "../StgPluginClasses/StgPluginInfo.h"
    
    #include <qlist.h>
    #include <qstring.h>
    #include <vcclr.h>
    #using <mscorlib.dll>
    #include <string>
    
    using namespace StgDotNet;
    
    namespace Stg
    {
    
    // plugins for this application are meant to available in 3 platforms: Qt, .NET, and stdlib
    // the point of this class is to allow plugins for the qt application to be written in .NET languages such as C# and VisualBasic
    class STGPLUGINDOTNETPLATFORM_EXPORT StgPluginDotNetPlatform : public IStgPluginPlatform
    {
    	Q_OBJECT
    	Q_INTERFACES(Stg::IStgPluginPlatform)
    
    public:
    	StgPluginDotNetPlatform(QString rootPath);
    	~StgPluginDotNetPlatform();
    
    public /*overrides*/:
    	virtual StgPluginInfo* getNextPlugin() override;
    	virtual void assignPluginID(int id) override;
    	virtual QString getName() const override;
    	virtual QString getPluginFolderName() const override;
    
    private:
    	QString mName;
    	QString mPluginFolderPath;
    	gcroot<StgPluginInterface ^>  _managedObject;
    };
    
    }
    #endif 
    
    // from the cpp file:
    #include "stgplugindotnetplatform.h"
    
    using namespace Stg;
    #include <msclr\marshal_cppstd.h>
    
    std::wstring MarshalString(System::String^ s)
    {
        using namespace System::Runtime::InteropServices;
        std::wstring ret;
        System::IntPtr p = Marshal::StringToHGlobalUni(s);
        if (p.ToPointer())
        {
            ret.assign((wchar_t const*)p.ToPointer());
            Marshal::FreeHGlobal(p);
        }
        return ret;
    }
    
    QString SystemStringToQString(System::String^ string)
    {
    	using namespace msclr::interop;
        return QString::fromStdWString(MarshalString(string));
    }
    
    StgPluginDotNetPlatform::StgPluginDotNetPlatform(QString rootPath) :
    	IStgPluginPlatform(),
    	mName("DotNetPlatform"),
    	mPluginFolderPath(rootPath)
    {
    	mPluginFolderPath.append("/");
    	mPluginFolderPath.append(mName);
    
    	_managedObject = gcnew StgPluginInterface(gcnew System::String((const wchar_t*)mPluginFolderPath.utf16()));
    }
    
    StgPluginDotNetPlatform::~StgPluginDotNetPlatform()
    {
    }
    
    StgPluginInfo* StgPluginDotNetPlatform::getNextPlugin()
    {
    	ITextReader^ reader = _managedObject->GetNextPlugin();
    	StgPluginInfo* pluginInfo = new StgPluginInfo(SystemStringToQString(reader->NameText));
    	return pluginInfo;
    }
    
    void StgPluginDotNetPlatform::assignPluginID(int id)
    {
    	_managedObject->AssignPluginID(id);
    }
    
    QString StgPluginDotNetPlatform::getName() const { return mName; }
    QString StgPluginDotNetPlatform::getPluginFolderName() const { return mPluginFolderPath; }
    
    

  • Moderators

    @primem0ver Can you show the pro file?



  • I am using Visual Studio. with the plugin. What do you want to know about the project settings?


  • Moderators

    @primem0ver I wanted to see how you configured your project.



  • I am not sure what configuration you are wanting but here are both the general config and the qt config. Note this is the configuration for the project that won't link. There are currently four projects in one solution. (main exe, main class library, the .NET platform plugin, and the .NET plugin class library.

    The one that doesn't compile is the .NET plugin platform library. I have only included the "core" Qt library for this particular dll.

    alt text

    alt text



  • @primem0ver
    pro file is this:
    alt text



  • @Taz742
    Um... yes. I know what a pro file is. I already said I am using Visual Studio. Not Qt Creator.

    @jsulm
    Since this is a linker issue I am also going to include the general linker settings
    alt text



  • Ok. Here is the specific error as it appears.
    alt text

    I have done a search of ALL include files and there is no function called _main. The source (I am assuming)for the library mentioned imports "main" but I don't understand why this is even an issue since I am compiling a DLL; not an exe.

    Below is list all of the files found in the qt source that mention qtmain (the library that is referred to in the error).
    alt text


  • Moderators

    @primem0ver What is the exact Qt version you're using? For .Net you need UWP version.



  • @jsulm
    No I don't. That has nothing to do with my project.

    1. I am not using a .NET version of Qt. I am building a regular Qt App with a .NET interface.
    2. There instructions on this very site that tell you how to use Qt with .NET: http://doc.qt.io/qt-5/activeqt-dotnet.html. These instructions never even mention UWP (which appears to be for WinRT/Windows 8 and later. I am on Windows 7).
    3. The problem is that the detailed example here only shows how to access the Qt API from .NET... basically to embed Qt objects in .NET. I need to go the other way. I need to embed .NET within Qt.

    I have done the homework as far as I can find. There are a number of examples online of how to embed .NET in C++ that aren't hard to find. Unfortunately, Qt examples are hard to come by. It doesn't sound like you are familiar with any of this. So please don't tell me what I need to do unless you are familiar with what I am trying to do and how to do it.



  • Ok. If anyone else ever encounters this issue, I found my own solution thanks to this article:
    https://forum.qt.io/topic/20117/error-lnk-2019-when-merging-qt-application-with-an-existing-mfc-application

    Even though it is using a different set of libraries the solution was the same: to remove the qtmain.lib that is automatically added as a linked dependency when using the Qt project wizard to create a Qt project in Visual Studio.


Log in to reply
 

Looks like your connection to Qt Forum was lost, please wait while we try to reconnect.