Export GUI Class to DLL Topic is solved

Do you have a question about makefiles, a compiler or IDE you are using and need to know how to set it up for wxWidgets or why it doesn't compile but other IDE's do ? Post your questions here.
Post Reply
Harsh
Experienced Solver
Experienced Solver
Posts: 70
Joined: Tue Apr 13, 2021 5:03 am

Export GUI Class to DLL

Post by Harsh »

I have multiple GUI pages. So to avoid huge sized .exe file and loading unnecessary GUI files I want to create DLLs with 10 or 20 forms each.
I used __declspec(exportdll) to export class. And commands to create DLL
  • "C:\msys64\mingw64\bin\g++.exe" -c ".\Source\*.cpp" -I ".\Include" -I "C:\WxAPI\include" -I "C:\WxAPI\lib\gcc810_x64_dll\mswu" -L "C:\WxAPI\lib\gcc810_x64_dll" -l wxbase31u -l wxmsw31u_core

    g++ -shared -o Form1.dll -Wl,--out-implib,libtstdll.a *.o
But it is giving errors "Undefined Reference to vtable".

I have read other solutions but I do not know most of the things it needs.

So is there any command or bat file to make it done?
ONEEYEMAN
Part Of The Furniture
Part Of The Furniture
Posts: 7477
Joined: Sat Apr 16, 2005 7:22 am
Location: USA, Ukraine

Re: Export GUI Class to DLL

Post by ONEEYEMAN »

Hi,
I think you have a typo:

__declspec(dllexport)

On top of that:

Can you post the code, please?
And are you getting an error compiling DLL or main application?

Thank you.
Harsh
Experienced Solver
Experienced Solver
Posts: 70
Joined: Tue Apr 13, 2021 5:03 am

Re: Export GUI Class to DLL

Post by Harsh »

ONEEYEMAN wrote: Tue Jul 20, 2021 1:09 pm Hi,
I think you have a typo:

__declspec(dllexport)

On top of that:

Can you post the code, please?
And are you getting an error compiling DLL or main application?

Thank you.
Sorry, I could not log in for long I don't know why.
And sorry for the typo. I wrote it write in my code.

1. I got errors while converting .o file to .dll
g++ -shared -o Form1.dll -Wl,--out-implib,libtstdll.a Form1.o //<<<At this command

2. Here is the error message.
C:/msys64/mingw64/bin/../lib/gcc/x86_64-w64-mingw32/10.3.0/../../../../x86_64-w64-mingw32/bin/ld.exe: Purchase.o:Purchase.cpp:(.rdata$.refptr._ZTV8wxMBConv[.refptr._ZTV8wxMBConv]+0x0): undefined reference to `vtable for wxMBConv'
collect2.exe: error: ld returned 1 exit status

And hundreds of similar messages above it.

3. I think dll changes are only made in .h file so I am posting only .h file code.
My .cpp file has 4000+ line code which I am planning to divide into number of .cpp files.

Code: Select all


#ifdef MAKEDLL
    #define EXPORT __declspec(dllexport)
#else
    #define EXPORT __declspec(dllimport)
#endif

#include<wx/wx.h>

class EXPORT Form1:public wxPanel{
    public:
        Form1(wxFrame*);
        
    private:

        wxPanel *p,*panel;
        wxScrolledWindow *sw;
        wxStaticText *st;
        wxTextCtrl *txt,*txt1;
        wxRect rect;
        wxRegEx *regX;
        wxButton *btn;
        wxBitmapButton *bmb;
        wxBoxSizer *vbox,*vbox1,*hbox;
        wxPopupWindow *pop;
        wxDialog *dlg;
        
        void AddRow(wxString);
        void OnText(wxCommandEvent&);
        void OnSize(wxSizeEvent&);
        void OnButton(wxCommandEvent&);
        void OnMove(wxMoveEvent&);
        void OnQuit(wxCloseEvent&);
        void OnChildFocus(wxChildFocusEvent&);
        void OnKeyDown(wxKeyEvent&);
        void OnFocus();
        void OnFocusOut();
	}
Here is the command I run to create .o file for this form

Code: Select all

"C:\Program Files\CodeBlocks\MinGW\bin\g++.exe" -c -DMAKEDLL ".\Source\*.cpp" -I ".\Include" -I "C:\WxAPI\include" -I "C:\WxAPI\lib\gcc810_x64_dll\mswu" -L "C:\WxAPI\lib\gcc810_x64_dll" -l wxbase31u -l wxmsw31u_core -mwindows
Harsh
Experienced Solver
Experienced Solver
Posts: 70
Joined: Tue Apr 13, 2021 5:03 am

How to make DLL of wxWidgets Program?[SOLVED]

Post by Harsh »

Answer :

1. First compile and create object files of the *.cpp program files which you want to add in DLL.
Command : g++ ".\Source\*.cpp" -c -DMAKEDLL -DWXUSINGDLL -I ".\Include" -I "C:\WxAPI\include" -I "C:\WxAPI\lib\gcc810_x64_dll\mswu" -L "C:\WxAPI\lib\gcc810_x64_dll" -l wxbase31u -l wxmsw31u_core

Here -DMAKEDLL I used from my *.h file which I am going to export.

Code: Select all

#ifndef MYFRAME_H
#define MYFRAME_H
#include<wx/frame.h>
#include<wx/sizer.h>

#ifdef MAKEDLL//Use it while creating object file like -c DLLClass.cpp -DMAKEDLL 
	#define EXPORT __declspec(dllexport)
#else
	#define EXPORT __declspec(dllimport)
#endif

class EXPORT MyFrame:public wxFrame{
    public:
        MyFrame();
};
#endif
And -DWXUSINGDLL is Macro defined in wxWidgets library which helps us to export our programs to DLL.
Must be used in command otherwise it gives error : undefined reference to '__wxABCXYX' file.

2. Add those object files to DLL.
Command : g++ -shared -o UI.dll *.o -Wl,--out-implib,libUI.a -I ".\Include" -I "C:\WxAPI\include" -I "C:\WxAPI\lib\gcc810_x64_dll\mswu" -L "C:\WxAPI\lib\gcc810_x64_dll" -l wxbase31u -l wxmsw31u_core sqlite3.dll

3. Compile other *.cpp files with common command to make EXE file.
* wxApp Class must be part of EXE command and not DLL.
Command : g++ MyApp.cpp -o MyApp.exe -I ".\Include" -I "C:\WxAPI\include" -I "C:\WxAPI\lib\gcc810_x64_dll\mswu" -L "C:\WxAPI\lib\gcc810_x64_dll" -l wxbase31u -l wxmsw31u_core UI.dll
Post Reply