Search code examples
c++wxwidgets

How to get libmathplot.a


I want to plot a graph using wxWidgets with gcc compiler and wxSmith. There are icons to add mpWindow, mpVector and so on, but it wouldn't work when I tried to compile it. So I downloaded the mathplot.h file and included it, but now the compiler says:

||=== Build: Debug in Lizenz_Logfile_Reader (compiler: GNU GCC Compiler) ===|
D:\Lizenz_Logfile_Reader\Lizenz_Logfile_ReaderMain.cpp||In member function 'void Lizenz_Logfile_ReaderFrame::parse()':|
D:\Lizenz_Logfile_Reader\Lizenz_Logfile_ReaderMain.cpp|187|warning: comparison between signed and unsigned integer expressions [-Wsign-compare]|
D:\Lizenz_Logfile_Reader\Lizenz_Logfile_ReaderMain.cpp|193|warning: comparison between signed and unsigned integer expressions [-Wsign-compare]|
ld.exe||cannot find -lmathplot|
||=== Build failed: 1 error(s), 2 warning(s) (0 minute(s), 3 second(s)) ===|

I searched the internet and found out I cound compile libmathplot.a myself, but when I try I get the error:

||=== Build: Debug in libmathplot (compiler: GNU GCC Compiler) ===|
C:\wxWidgets-3.0.2\include\wx\platform.h|183|fatal error: wx/setup.h: No such file or directory|
||=== Build failed: 1 error(s), 0 warning(s) (0 minute(s), 0 second(s)) ===|

I am following this answer in german, which says one should create a new static library project, add mathplot.h and mathplot.cpp in main, add wxWidgets3.0.2\include to Project->Build Oprtions->Search path Project->Build Oprtions->Compiler and compile it. Is there anything else I need do? Thank you for your help.


Edit: Another part of the linked answer is to just include mathplot.cpp as well. I tried it like following

Lizenz_Logfile_ReaderMain.cpp:
#include "Lizenz_Logfile_ReaderMain.h"
#include <wx/msgdlg.h>

#include <wx/textfile.h>
#include "mathplot.h"


Lizenz_Logfile_ReaderMain.h:
#ifndef LIZENZ_LOGFILE_READERMAIN_H
#define LIZENZ_LOGFILE_READERMAIN_H

#include <wx/textfile.h>
#include <wx/list.h>
#include <wx/vector.h>
#include "mathplot.h"
#include "mathplot.cpp"

I then get a flood of errors about things being redefined in mathplot:

||=== Build: Debug in Lizenz_Logfile_Reader (compiler: GNU GCC Compiler) ===|
D:\Lizenz_Logfile_Reader\mathplot.cpp|15|warning: #pragma implementation for 'mathplot.h' appears after file is included [enabled by default]|
D:\Lizenz_Logfile_Reader\mathplot.cpp||In member function 'bool mpWindow::SaveScreenshot(const wxString&, int, wxSize, bool)':|
D:\Lizenz_Logfile_Reader\mathplot.cpp|2239|warning: 'bool wxImage::SaveFile(const wxString&, long int) const' is deprecated (declared at C:\wxWidgets-3.0.2\include/wx/image.h:560) [-Wdeprecated-declarations]|
D:\Lizenz_Logfile_Reader\Lizenz_Logfile_ReaderMain.cpp||In member function 'void Lizenz_Logfile_ReaderFrame::parse()':|
D:\Lizenz_Logfile_Reader\Lizenz_Logfile_ReaderMain.cpp|188|warning: comparison between signed and unsigned integer expressions [-Wsign-compare]|
D:\Lizenz_Logfile_Reader\Lizenz_Logfile_ReaderMain.cpp|194|warning: comparison between signed and unsigned integer expressions [-Wsign-compare]|
obj\Debug\Lizenz_Logfile_ReaderMain.o||In function `ZNK7mpLayer12GetClassInfoEv':|
D:\Lizenz_Logfile_Reader\mathplot.cpp|78|multiple definition of `mpLayer::GetClassInfo() const'|
obj\Debug\Lizenz_Logfile_ReaderApp.o:D:\Lizenz_Logfile_Reader\mathplot.cpp|78|first defined here|
obj\Debug\Lizenz_Logfile_ReaderMain.o||In function `ZN7mpLayerC2Ev':|
D:\Lizenz_Logfile_Reader\mathplot.cpp|80|multiple definition of `mpLayer::mpLayer()'|
obj\Debug\Lizenz_Logfile_ReaderApp.o:D:\Lizenz_Logfile_Reader\mathplot.cpp|80|first defined here|
obj\Debug\Lizenz_Logfile_ReaderMain.o||In function `ZN7mpLayerC2Ev':|
D:\Lizenz_Logfile_Reader\mathplot.cpp|80|multiple definition of `mpLayer::mpLayer()'|
obj\Debug\Lizenz_Logfile_ReaderApp.o:D:\Lizenz_Logfile_Reader\mathplot.cpp|80|first defined here|
obj\Debug\Lizenz_Logfile_ReaderMain.o||In function `ZN7mpLayer15GetColourSquareEi':|
D:\Lizenz_Logfile_Reader\mathplot.cpp|91|multiple definition of `mpLayer::GetColourSquare(int)'|
obj\Debug\Lizenz_Logfile_ReaderApp.o:D:\Lizenz_Logfile_Reader\mathplot.cpp|91|first defined here|
obj\Debug\Lizenz_Logfile_ReaderMain.o||In function `ZNK11mpInfoLayer12GetClassInfoEv':|
D:\Lizenz_Logfile_Reader\mathplot.cpp|106|multiple definition of `mpInfoLayer::GetClassInfo() const'|
obj\Debug\Lizenz_Logfile_ReaderApp.o:D:\Lizenz_Logfile_Reader\mathplot.cpp|106|first defined here|
obj\Debug\Lizenz_Logfile_ReaderMain.o||In function `ZN11mpInfoLayer14wxCreateObjectEv':|
D:\Lizenz_Logfile_Reader\mathplot.cpp|106|multiple definition of `mpInfoLayer::wxCreateObject()'|
obj\Debug\Lizenz_Logfile_ReaderApp.o:D:\Lizenz_Logfile_Reader\mathplot.cpp|106|first defined here|
obj\Debug\Lizenz_Logfile_ReaderMain.o||In function `ZN11mpInfoLayerC2Ev':|
D:\Lizenz_Logfile_Reader\mathplot.cpp|108|multiple definition of `mpInfoLayer::mpInfoLayer()'|
obj\Debug\Lizenz_Logfile_ReaderApp.o:D:\Lizenz_Logfile_Reader\mathplot.cpp|108|first defined here|
obj\Debug\Lizenz_Logfile_ReaderMain.o||In function `ZN11mpInfoLayerC2Ev':|
D:\Lizenz_Logfile_Reader\mathplot.cpp|108|multiple definition of `mpInfoLayer::mpInfoLayer()'|
obj\Debug\Lizenz_Logfile_ReaderApp.o:D:\Lizenz_Logfile_Reader\mathplot.cpp|108|first defined here|
obj\Debug\Lizenz_Logfile_ReaderMain.o||In function `ZN11mpInfoLayerC2E6wxRectPK7wxBrush':|
D:\Lizenz_Logfile_Reader\mathplot.cpp|118|multiple definition of `mpInfoLayer::mpInfoLayer(wxRect, wxBrush const*)'|
obj\Debug\Lizenz_Logfile_ReaderApp.o:D:\Lizenz_Logfile_Reader\mathplot.cpp|118|first defined here|
obj\Debug\Lizenz_Logfile_ReaderMain.o||In function `ZN11mpInfoLayerC2E6wxRectPK7wxBrush':|
D:\Lizenz_Logfile_Reader\mathplot.cpp|118|multiple definition of `mpInfoLayer::mpInfoLayer(wxRect, wxBrush const*)'|
obj\Debug\Lizenz_Logfile_ReaderApp.o:D:\Lizenz_Logfile_Reader\mathplot.cpp|118|first defined here|
obj\Debug\Lizenz_Logfile_ReaderMain.o||In function `ZN11mpInfoLayerD2Ev':|
D:\Lizenz_Logfile_Reader\mathplot.cpp|128|multiple definition of `mpInfoLayer::~mpInfoLayer()'|
obj\Debug\Lizenz_Logfile_ReaderApp.o:D:\Lizenz_Logfile_Reader\mathplot.cpp|128|first defined here|
obj\Debug\Lizenz_Logfile_ReaderMain.o||In function `ZN11mpInfoLayerD2Ev':|
D:\Lizenz_Logfile_Reader\mathplot.cpp|128|multiple definition of `mpInfoLayer::~mpInfoLayer()'|
obj\Debug\Lizenz_Logfile_ReaderApp.o:D:\Lizenz_Logfile_Reader\mathplot.cpp|128|first defined here|
obj\Debug\Lizenz_Logfile_ReaderMain.o||In function `ZN11mpInfoLayerD0Ev':|
D:\Lizenz_Logfile_Reader\mathplot.cpp|128|multiple definition of `mpInfoLayer::~mpInfoLayer()'|
obj\Debug\Lizenz_Logfile_ReaderApp.o:D:\Lizenz_Logfile_Reader\mathplot.cpp|128|first defined here|
obj\Debug\Lizenz_Logfile_ReaderMain.o||In function `ZN11mpInfoLayer10UpdateInfoER8mpWindowR7wxEvent':|
D:\Lizenz_Logfile_Reader\mathplot.cpp|134|multiple definition of `mpInfoLayer::UpdateInfo(mpWindow&, wxEvent&)'|
obj\Debug\Lizenz_Logfile_ReaderApp.o:D:\Lizenz_Logfile_Reader\mathplot.cpp|134|first defined here|
obj\Debug\Lizenz_Logfile_ReaderMain.o||In function `ZN11mpInfoLayer6InsideER7wxPoint':|
D:\Lizenz_Logfile_Reader\mathplot.cpp|139|multiple definition of `mpInfoLayer::Inside(wxPoint&)'|
obj\Debug\Lizenz_Logfile_ReaderApp.o:D:\Lizenz_Logfile_Reader\mathplot.cpp|139|first defined here|
obj\Debug\Lizenz_Logfile_ReaderMain.o||In function `ZN11mpInfoLayer4MoveE7wxPoint':|
D:\Lizenz_Logfile_Reader\mathplot.cpp|144|multiple definition of `mpInfoLayer::Move(wxPoint)'|
obj\Debug\Lizenz_Logfile_ReaderApp.o:D:\Lizenz_Logfile_Reader\mathplot.cpp|144|first defined here|
obj\Debug\Lizenz_Logfile_ReaderMain.o||In function `ZN11mpInfoLayer15UpdateReferenceEv':|
D:\Lizenz_Logfile_Reader\mathplot.cpp|150|multiple definition of `mpInfoLayer::UpdateReference()'|
obj\Debug\Lizenz_Logfile_ReaderApp.o:D:\Lizenz_Logfile_Reader\mathplot.cpp|150|first defined here|
obj\Debug\Lizenz_Logfile_ReaderMain.o||In function `ZN11mpInfoLayer4PlotER4wxDCR8mpWindow':|
D:\Lizenz_Logfile_Reader\mathplot.cpp|157|multiple definition of `mpInfoLayer::Plot(wxDC&, mpWindow&)'|
obj\Debug\Lizenz_Logfile_ReaderApp.o:D:\Lizenz_Logfile_Reader\mathplot.cpp|157|first defined here|
obj\Debug\Lizenz_Logfile_ReaderMain.o||In function `ZN11mpInfoLayer11GetPositionEv':|
D:\Lizenz_Logfile_Reader\mathplot.cpp|189|multiple definition of `mpInfoLayer::GetPosition()'|
obj\Debug\Lizenz_Logfile_ReaderApp.o:D:\Lizenz_Logfile_Reader\mathplot.cpp|189|first defined here|
obj\Debug\Lizenz_Logfile_ReaderMain.o||In function `ZN11mpInfoLayer7GetSizeEv':|
D:\Lizenz_Logfile_Reader\mathplot.cpp|194|multiple definition of `mpInfoLayer::GetSize()'|
obj\Debug\Lizenz_Logfile_ReaderApp.o:D:\Lizenz_Logfile_Reader\mathplot.cpp|194|first defined here|
obj\Debug\Lizenz_Logfile_ReaderMain.o||In function `ZN12mpInfoCoordsC2Ev':|
D:\Lizenz_Logfile_Reader\mathplot.cpp|198|multiple definition of `mpInfoCoords::mpInfoCoords()'|
obj\Debug\Lizenz_Logfile_ReaderApp.o:D:\Lizenz_Logfile_Reader\mathplot.cpp|198|first defined here|
obj\Debug\Lizenz_Logfile_ReaderMain.o||In function `ZN12mpInfoCoordsC2Ev':|
D:\Lizenz_Logfile_Reader\mathplot.cpp|198|multiple definition of `mpInfoCoords::mpInfoCoords()'|
obj\Debug\Lizenz_Logfile_ReaderApp.o:D:\Lizenz_Logfile_Reader\mathplot.cpp|198|first defined here|
obj\Debug\Lizenz_Logfile_ReaderMain.o||In function `ZN12mpInfoCoordsC2E6wxRectPK7wxBrush':|
D:\Lizenz_Logfile_Reader\mathplot.cpp|203|multiple definition of `mpInfoCoords::mpInfoCoords(wxRect, wxBrush const*)'|
obj\Debug\Lizenz_Logfile_ReaderApp.o:D:\Lizenz_Logfile_Reader\mathplot.cpp|203|first defined here|
obj\Debug\Lizenz_Logfile_ReaderMain.o||In function `ZN12mpInfoCoordsC2E6wxRectPK7wxBrush':|
D:\Lizenz_Logfile_Reader\mathplot.cpp|203|multiple definition of `mpInfoCoords::mpInfoCoords(wxRect, wxBrush const*)'|
obj\Debug\Lizenz_Logfile_ReaderApp.o:D:\Lizenz_Logfile_Reader\mathplot.cpp|203|first defined here|
obj\Debug\Lizenz_Logfile_ReaderMain.o||In function `ZN12mpInfoCoordsD2Ev':|
D:\Lizenz_Logfile_Reader\mathplot.cpp|208|multiple definition of `mpInfoCoords::~mpInfoCoords()'|
obj\Debug\Lizenz_Logfile_ReaderApp.o:D:\Lizenz_Logfile_Reader\mathplot.cpp|208|first defined here|
||More errors follow but not being shown.|
||Edit the max errors limit in compiler options...|
||=== Build failed: 50 error(s), 4 warning(s) (0 minute(s), 5 second(s)) ===|

I already deleted :: in lines 2610, 2749-2751, 2763, 2847 and 2877 as suggested in the answer which made some errors disappear, but now the error log above shows.


Solution

  • First, make sure your app builds without wxMathPlot (no realted #include's, no libs, etc). YourWXdir/include must be set in Project->Build Options->Search.

    Second, add mathplot.cpp to your project, as any other file from your app. #include mathplot.h in those files where your app needs wxMathPlot API, but only once per file (you hace duplicated it). Don't #include mathplot.cpp.

    The duplicated definitions come from using both mathplot.cpp and its library at once. Chose only one way of using it.

    The signed-unsigned conversion is in your code Lizenz_Logfile_ReaderMain.cpp.