I am using visual studio 2015 with wxwidgets 3.1.0
I have a main project with a library and a unit test project.
basically I would like to use wxwidgets in the library and compile it as a dll which both the main project and unit test will use.
when i am using stl i can export the dll no problem.
I am having difficulty compiling my library project when i start including wxwidgets in the source code.
could somebody show please direct me as to where to find some examples on how to do this if there are any existing for wxwidgts 3.1.0
thanks.
wxwidgets dll example Topic is solved
Re: wxwidgets dll example
From your post it is unclear what is the acual issue?
I am not sure I understand: all you need is to link wxWidgets dynamically? This is supported out of the box, just build wxWidgets as DLL, link the import library, and define WXUSINGDLL.
VC 2015 solutions (*_vc14.sln) for samples have DLL configurations for both Release and Debug builds so you check those to see how it works.
I am not sure I understand: all you need is to link wxWidgets dynamically? This is supported out of the box, just build wxWidgets as DLL, link the import library, and define WXUSINGDLL.
VC 2015 solutions (*_vc14.sln) for samples have DLL configurations for both Release and Debug builds so you check those to see how it works.
Re: wxwidgets dll example
originally i have the one application that uses wxwidgets and its been working fine.
i would like to split my solution into 3 projects.
a main project , a library , and a unit test project.
the sample code with the mathlibrary i can use with my unit test fine.
could you show me an example for the wxwidgets case.
how do i export the class below as a dll?
what do i put in the preprocessor?
i would like to split my solution into 3 projects.
a main project , a library , and a unit test project.
the sample code with the mathlibrary i can use with my unit test fine.
could you show me an example for the wxwidgets case.
Code: Select all
// MathLibrary.h - Contains declaration of Function class
#pragma once
#ifdef MATHLIBRARY_EXPORTS
#define MATHLIBRARY_API __declspec(dllexport)
#else
#define MATHLIBRARY_API __declspec(dllimport)
#endif
namespace MathLibrary
{
// This class is exported from the MathLibrary.dll
class Functions
{
public:
// Returns a + b
static MATHLIBRARY_API double Add(double a, double b);
// Returns a * b
static MATHLIBRARY_API double Multiply(double a, double b);
// Returns a + (a * b)
static MATHLIBRARY_API double AddMultiply(double a, double b);
};
}
what do i put in the preprocessor?
Code: Select all
class output
{
public:
XXXXX wxString hello()
{
return wxString("hello world");
};
}
Re: wxwidgets dll example
Now I am legitimately confused. AFAIK, you do not need to do anything for a wxWidgets class such as wxString, it is done by
1. wxWidgets declaring all classes with WXDLLIMPEXP_* macro (basically a sophisticated version of your MATHLIBRARY_API).
2. You defining WXUSINGDLL macro in your project when linking with wxWidgets DLL.
If you want to export your own class, you should do the same. For example, this is how export/import macro looks in my wxAutoExcel library WXDLLIMPEXP_DATA_WXAUTOEXCEL is used for declaring variables to be exported. You may also need to create a macro for forward class declarations, similar to WXDLLIMPEXP_FWD_*
And the class itself can be declared as The individual class methods do not require you to do tag them.
Of course, WXEXPORT and WXIMPORT macros are for MSVC defined as
You could also take a look at how it is done in one of popular 3rd party wxWidgets libraries, such as wxSQLite but it is basically always more or less the same...
1. wxWidgets declaring all classes with WXDLLIMPEXP_* macro (basically a sophisticated version of your MATHLIBRARY_API).
2. You defining WXUSINGDLL macro in your project when linking with wxWidgets DLL.
If you want to export your own class, you should do the same. For example, this is how export/import macro looks in my wxAutoExcel library
Code: Select all
#ifdef WXMAKINGDLL_WXAUTOEXCEL
#define WXDLLIMPEXP_WXAUTOEXCEL WXEXPORT
#define WXDLLIMPEXP_DATA_WXAUTOEXCEL(type) WXEXPORT type
#elif defined(WXUSINGDLL_WXAUTOEXCEL)
#define WXDLLIMPEXP_WXAUTOEXCEL WXIMPORT
#define WXDLLIMPEXP_DATA_WXAUTOEXCEL(type) WXIMPORT type
#else // not making nor using DLL
#define WXDLLIMPEXP_WXAUTOEXCEL
#define WXDLLIMPEXP_DATA_WXAUTOEXCEL(type) type
#endif
And the class itself can be declared as
Code: Select all
class WXDLLIMPEXP_WXAUTOEXCEL wxExcelApplication : public wxExcelRangeOwner
Of course, WXEXPORT and WXIMPORT macros are for MSVC defined as
Code: Select all
#define WXEXPORT __declspec(dllexport)
#define WXIMPORT __declspec(dllimport)
Re: wxwidgets dll example
thanks for the input i narrowed my problem down.
this is what i am using now
In environment i added the code below
but the unit test project doesn't pick up the path.
i copied all the dlls needed to the unit test executable path and it is working now.
this is what i am using now
Code: Select all
#pragma once
#include <wx/wx.h>
#ifdef CONTROLLERLIBRARY_EXPORTS
#define CONTROLLERLIBRARY_EXPORT __declspec(dllexport)
#else
#define CONTROLLERLIBRARY_EXPORT __declspec(dllimport)
#endif
class CONTROLLERLIBRARY_EXPORT Controller
{
public:
wxString hello();
};
Code: Select all
PATH=$(WX31)\lib\vc140_x64_dll;
i copied all the dlls needed to the unit test executable path and it is working now.
Re: wxwidgets dll example
If you want to refer to a system environment variable such as PATH on a command line, you need to use the %var_name% syntax, e.g.rafae11 wrote: In environment i added the code belowCode: Select all
PATH=$(WX31)\lib\vc140_x64_dll;
Code: Select all
PATH=%WX31%\lib\vc140_x64_dll;%PATH%