Export UI pages collectively 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 UI pages collectively to DLL

Post by Harsh »

Changes made in .H file to create DLL is as below

Code: Select all


#ifndef MYPANEL_H
#define MYPANEL_H

#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();
};
#endif
Command used to create an object file is as below.
  • "C:\msys64\mingw64\bin\g++.exe" -c -DMAKEDLL ".\Source\Form1.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
Command used to create DLL is as below.
  • g++ -shared -o Form1.dll -Wl,--out-implib,libtstdll.a Form1.o
Error thrown by this command is
  • 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
What does it need to cover undefined references?
stahta01
Ultimate wxWidgets Guru
Ultimate wxWidgets Guru
Posts: 548
Joined: Fri Nov 03, 2006 2:00 pm

Re: Export UI pages collectively to DLL

Post by stahta01 »

You forgot to define the using wx DLL macro "WXUSINGDLL".

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

Re: Export UI pages collectively to DLL

Post by Harsh »

stahta01 wrote: Wed Jul 21, 2021 12:05 pm You forgot to define the using wx DLL macro "WXUSINGDLL".

Tim S.
I do not know how and where to define it. Will You Please Help Me With It?

I am new to CPP.
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