how to build lib or dll for wxmathplot using mingw64 in windows

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
cshen
In need of some credit
In need of some credit
Posts: 6
Joined: Thu Jul 08, 2021 6:35 pm

how to build lib or dll for wxmathplot using mingw64 in windows

Post by cshen »

Hi all
I have read many posts of how to build/use mathplot for wxWidgets but none of them is for mingw64 in windows.
I have most current source code of wxWidgets from git repo trunk (I think it is 3.1.5 using git clone --recurse-submodules https://github.com/wxWidgets/wxWidgets.git) and I built the lib/dll for mswud (UNICODE=1 DEBUG=1) using mingw64.
Then I use Code::block to create dll project for mathplot, add mathplot.cpp and mathplot.h to the project.
I setup code::block enviroment such as search path for compiler and linker to wxWidgets include folder and lib/dll folders.
Which are in (here $(WSHOME) is the wxWidgets source folder. All built dll and lib files are in mswud folders)

$(WXHOME)\include
$(WXHOME)\lib\gcc_dll\mswud
$(WXHOME)\lib\gcc_lib\mswud

In linker settings I add all wxWidgets built dll and lib files to the project.
Then I try to compile the project. I got errors like those:

Code: Select all

In file included from F:\wxWidgets\include/wx/object.h:57,
from F:\wxWidgets\include/wx/event.h:16,
from F:\wxWidgets\include/wx/window.h:18,
from F:\wx\mathplot\mathplot.cpp:19:
F:\wx\mathplot\mathplot.cpp: At global scope:
F:\wx\mathplot\mathplot.cpp:492:25: error: no declaration matches 'wxObject* mpWindow::wxCreateObject()'
IMPLEMENT_DYNAMIC_CLASS(mpWindow, wxScrolledWindow)
^~~~~~~~
F:\wxWidgets\include/wx/rtti.h:187:15: note: in definition of macro 'wxIMPLEMENT_DYNAMIC_CLASS'
wxObject* name::wxCreateObject() \
^~~~
F:\wx\mathplot\mathplot.cpp:492:1: note: in expansion of macro 'IMPLEMENT_DYNAMIC_CLASS'
IMPLEMENT_DYNAMIC_CLASS(mpWindow, wxScrolledWindow)
^~~~~~~~~~~~~~~~~~~~~~~
F:\wx\mathplot\mathplot.cpp:492:25: note: no functions named 'wxObject* mpWindow::wxCreateObject()'
IMPLEMENT_DYNAMIC_CLASS(mpWindow, wxScrolledWindow)
^~~~~~~~
F:\wxWidgets\include/wx/rtti.h:187:15: note: in definition of macro 'wxIMPLEMENT_DYNAMIC_CLASS'
wxObject* name::wxCreateObject() \
^~~~
F:\wx\mathplot\mathplot.cpp:492:1: note: in expansion of macro 'IMPLEMENT_DYNAMIC_CLASS'
IMPLEMENT_DYNAMIC_CLASS(mpWindow, wxScrolledWindow)
^~~~~~~~~~~~~~~~~~~~~~~
In file included from F:\wx\mathplot\mathplot.cpp:42:
F:\wx\mathplot\mathplot.h:556:19: note: 'class mpWindow' defined here
class WXDLLEXPORT mpWindow : public wxScrolledWindow
^~~~~~~~
F:\wx\mathplot\mathplot.cpp:562:11: error: no declaration matches 'wxObject* mpWindow::wxCreateObject()'
wxObject* mpWindow::wxCreateObject()
^~~~~~~~
F:\wx\mathplot\mathplot.cpp:562:11: note: no functions named 'wxObject* mpWindow::wxCreateObject()'
In file included from F:\wx\mathplot\mathplot.cpp:42:
F:\wx\mathplot\mathplot.h:556:19: note: 'class mpWindow' defined here
class WXDLLEXPORT mpWindow : public wxScrolledWindow
^~~~~~~~
F:\wx\mathplot\mathplot.cpp: In member function 'void mpWindow::OnMouseMove(wxMouseEvent&)':
F:\wx\mathplot\mathplot.cpp:663:46: warning: 'wxPen::wxPen(const wxColour&, int, int)' is deprecated: use wxPENSTYLE_XXX constants [-Wdeprecated-declarations]
wxPen pen(*wxLIGHT_GREY, 1, wxDOT);
^
In file included from F:\wxWidgets\include/wx/pen.h:103,
from F:\wxWidgets\include/wx/dc.h:25,
from F:\wxWidgets\include/wx/dcclient.h:12,
from F:\wx\mathplot\mathplot.cpp:38:
F:\wxWidgets\include/wx/msw/pen.h:61:5: note: declared here
Last edited by cshen on Fri Jul 09, 2021 3:11 pm, edited 1 time in total.
ONEEYEMAN
Part Of The Furniture
Part Of The Furniture
Posts: 7459
Joined: Sat Apr 16, 2005 7:22 am
Location: USA, Ukraine

Re: how to build lib or dll for wxmathplot using mingw64 in windows

Post by ONEEYEMAN »

Hi,
This will not work.
You need only one build of wxWidgets - either static one (lib) or dynamic one (dll).
In Windows it is preferred to have a static build, so you need to start over.

Create a project in C::B for a static build of wxWidgets (leave everything else as appropriate for your wxWidgets configuration).
Add the wxmatplot files to the project.
Build and run.

You will have one (1) executable file. No DLLs other than MS/MinGW CRT.

Thank you.
cshen
In need of some credit
In need of some credit
Posts: 6
Joined: Thu Jul 08, 2021 6:35 pm

Re: how to build lib or dll for wxmathplot using mingw64 in windows

Post by cshen »

Thanks
I have two projects, one is to build lib and another is to build dll. Both do not work. But I will try what you sugested again.
ONEEYEMAN
Part Of The Furniture
Part Of The Furniture
Posts: 7459
Joined: Sat Apr 16, 2005 7:22 am
Location: USA, Ukraine

Re: how to build lib or dll for wxmathplot using mingw64 in windows

Post by ONEEYEMAN »

Hi,
Are you getting those errors in both configurations?
Please create wxWidgets project in C::B and make sure project settings are match to the library build settings.

Thank you.
cshen
In need of some credit
In need of some credit
Posts: 6
Joined: Thu Jul 08, 2021 6:35 pm

Re: how to build lib or dll for wxmathplot using mingw64 in windows

Post by cshen »

What I did:
(1) In CB create a project for static lib project
(2)remove any files (main.c)
(3)add mathplot.cpp and mathplot.h
(4)add all lib files wxWidgets/lib/gcc_lib/msw as linker libs
(5)add wxWidgets\include, wxWidgets/lib/gcc_lib/msw to search path

Got the same error

Now I create an empty wxWidgets project and add mathplot.cpp and mathplot.h , add wxWidgets libs to linker
I got new errors like this:

Code: Select all

obj\Debug\mathplot.o: In function `mpLayer::mpLayer()':
mathplot.cpp:81: undefined reference to `__imp__ZN7wxBrushC1Ev'
mathplot.cpp:83: undefined reference to `__imp__ZN10wxStockGDI6GetPenENS_4ItemE'
mathplot.cpp:81: undefined reference to `__imp__ZN7wxBrushD1Ev'
mathplot.cpp:81: undefined reference to `__imp__ZN6wxFontD1Ev'
obj\Debug\mathplot.o: In function `mpLayer::GetColourSquare(int)':
mathplot.cpp:94: undefined reference to `__imp__ZNK5wxPen9GetColourEv'
mathplot.cpp:95: undefined reference to `__imp__ZN7wxBrushC1ERK8wxColouri'
mathplot.cpp:96: undefined reference to `__imp__ZN10wxMemoryDCC1Ev'
mathplot.cpp:97: undefined reference to `__imp__ZN10wxMemoryDC12SelectObjectER8wxBitmap'
mathplot.cpp:100: undefined reference to `__imp_wxNullBitmap'
mathplot.cpp:100: undefined reference to `__imp__ZN10wxMemoryDC12SelectObjectER8wxBitmap'
mathplot.cpp:95: undefined reference to `__imp__ZN7wxBrushD1Ev'
mathplot.cpp:95: undefined reference to `__imp__ZN7wxBrushD1Ev'
mathplot.cpp:94: undefined reference to `__imp__ZN8wxBitmapD1Ev'
obj\Debug\mathplot.o: In function `mpInfoLayer::mpInfoLayer()':
mathplot.cpp:109: undefined reference to `__imp__ZN7wxBrushC1Ev'
mathplot.cpp:112: undefined reference to `__imp__ZN10wxStockGDI8GetBrushENS_4ItemE'
mathplot.cpp:109: undefined reference to `__imp__ZN7wxBrushD1Ev'
obj\Debug\mathplot.o: In function `mpInfoLayer::mpInfoLayer(wxRect, wxBrush const*)':
mathplot.cpp:119: undefined reference to `__imp__ZN7wxBrushC1Ev'
mathplot.cpp:119: undefined reference to `__imp__ZN7wxBrushD1Ev'
obj\Debug\mathplot.o: In function `mpInfoLayer::~mpInfoLayer()':
mathplot.cpp:129: undefined reference to `__imp__ZN7wxBrushD1Ev'
obj\Debug\mathplot.o: In function `mpInfoCoords::UpdateInfo(mpWindow&, wxEvent&)':
mathplot.cpp:223: undefined reference to `__imp_wxEVT_MOTION'
obj\Debug\mathplot.o: In function `mpInfoCoords::Plot(wxDC&, mpWindow&)':
mathplot.cpp:305: undefined reference to `__imp__ZNK8wxString11BeforeFirstE9wxUniCharPS_'
mathplot.cpp:306: undefined reference to `__imp__ZNK8wxString10AfterFirstE9wxUniChar'
obj\Debug\mathplot.o: In function `mpInfoLegend::Plot(wxDC&, mpWindow&)':
mathplot.cpp:386: undefined reference to `__imp__ZN10wxStockGDI9GetColourENS_4ItemE'
Seems to me a wxWidgets project inlcudes some macro but I cannot find them from project property. This error looks like c/c++ mixing issues.
Last edited by cshen on Fri Jul 09, 2021 5:57 pm, edited 1 time in total.
cshen
In need of some credit
In need of some credit
Posts: 6
Joined: Thu Jul 08, 2021 6:35 pm

Re: how to build lib or dll for wxmathplot using mingw64 in windows

Post by cshen »

ONEEYEMAN wrote: Fri Jul 09, 2021 3:54 pm Hi,
Are you getting those errors in both configurations?
Please create wxWidgets project in C::B and make sure project settings are match to the library build settings.

Thank you.
Yes. they are the same error.
PB
Part Of The Furniture
Part Of The Furniture
Posts: 4193
Joined: Sun Jan 03, 2010 5:45 pm

Re: how to build lib or dll for wxmathplot using mingw64 in windows

Post by PB »

cshen wrote: Thu Jul 08, 2021 7:13 pm I setup code::block enviroment such as search path for compiler and linker to wxWidgets include folder and lib/dll folders.
I consider this a very bad practice, the library should be set in the project instead of compiler properties? How will you use both Debug and Release builds of wxWidgets?
cshen wrote: Thu Jul 08, 2021 7:13 pm I built the lib/dll for mswud (UNICODE=1 DEBUG=1)
This does not build the shared (DLL) build, unless you used also SHARED=1 but did not list it here. I would also build the release build as well. BTW, UNICODE=1 is the default so you do not need to use it.

Can you even build and run a simple wxWidgets application not using wxMathPlot, to make sure your wxWidgets build is correct?

I would do:
1. Remove the library specific stuff from the compiler properties in CB.
2. Use the wxWidgets project wizard in CB to create a simple wxWidgets project.
3. Build and run the project to make sure wxWidgets work properly.
4. Add the wxMathPlot header and source file and rebuild the project to make sure it still builds.
5. Replace the code created by the wizard with the one from the wxMathPlot sample1.

FWIW, I wrote a guide about building wxWidgets with GCC/mingw64 and setting up a wxWidgets project in Code::Blocks but I guess you are past this stage.
cshen
In need of some credit
In need of some credit
Posts: 6
Joined: Thu Jul 08, 2021 6:35 pm

Re: how to build lib or dll for wxmathplot using mingw64 in windows

Post by cshen »

OK I think I find the problem:
I can build sample in the samples folder using its makefile.gcc. So I build a CODE::BLOCK project for one of the sample animation with empty wxWidgets project. Add the source and header files to the project and compare the log file to the output of makefile.gcc. The CB project has same error I have before. So I compare the difference of makefile.gcc and the CB project flags.

I find two major differences:
C:B has -D__GNUWIN32__ So I delete it from project->property->"compiler setting"->#define (My dll and lib are for x64)

Makefile has those two flag and CB does not have:
-DwxUSE_UNICODE=0 (add to project->property->"compiler setting"->#define)
-fno-keep-inline-dllexport ( add to project->property->"other compiler"->option)

After that error is gone.

So I think it is 32 verses 64 and unicode setting. Default CB project does not use unicode. I think the inline things is not important.
compare CB log with makefile.gcc flags
compare CB log with makefile.gcc flags
cberror.png (26.72 KiB) Viewed 4334 times
ONEEYEMAN
Part Of The Furniture
Part Of The Furniture
Posts: 7459
Joined: Sat Apr 16, 2005 7:22 am
Location: USA, Ukraine

Re: how to build lib or dll for wxmathplot using mingw64 in windows

Post by ONEEYEMAN »

Hi,
Did you explicitly set UNICODE=0, when building wxWidgets?
If so - why?

Also - C::B does have a checkbox, whether to use UNICODE or not in its project wizard for wxWidgets projects.

Thank you.
cshen
In need of some credit
In need of some credit
Posts: 6
Joined: Thu Jul 08, 2021 6:35 pm

Re: how to build lib or dll for wxmathplot using mingw64 in windows

Post by cshen »

I compiled all type dll/libs for wxWidgets. Just to use UNICODE=0 version for Linux OS. No specific reasons.
For windows OS, I am using MinGW64 tool chain and CB project default is 32 version, so just correct this will solve the problem. Also linker settings must point to correct version.

That is the lesson.
ONEEYEMAN
Part Of The Furniture
Part Of The Furniture
Posts: 7459
Joined: Sat Apr 16, 2005 7:22 am
Location: USA, Ukraine

Re: how to build lib or dll for wxmathplot using mingw64 in windows

Post by ONEEYEMAN »

Hi,
This is 21 century. UNICODE is the default settings, and it is expected that ANSI build will be dropped (probably after the next major release - which will come very soon).

So I suggest rebuild wxWidgets with UNICODE =1 (or just remove this completely) and make sure that your own program is successfully built and run.

Also make sure you are NOT using MONOLITHIC build as it could potentially make you life miserable. ;-)
This build is very rarely tested by core developers and is almost unmaintained. The only reason it is present - C::B itself is using it. So unless you plan on improving this IDE - don't use MONOLITHIC build.

Thank you.
Post Reply