One Wt executable with multiple 'plugin' DLLs that export their specific widgets

Added by S van der Hoest 4 months ago

Hi,

We are experimenting with Wt, and so far it works great, running just a single executable, like how it is done in the examples.

What we would like to achieve though is a setup in which different teams can create their own 'plugins' with 'web pages', which are served by a single server / executable.
E.g. a setup like:
- Executable M: Runs the server (WApplication/WSever)
- Lib A \
- Lib B > These all all have their own pages (e.g. WContainerWidget's)
- Lib C /

Each library then provides e.g. the functions:
- GetPageIds() : returns a list of unique strings
- GetPageWidget( pageId ) : returns a WContainerWidget for that page

This works OK when A,B,C are static libs, however, what we would like is to have them as DLLs that are explicitely linked by executable M.
That way each team can deliver its own 'plugin' DLL, update it independently,
and we then there is only one server running and listening on 1 port.

So far I've been unable to get this working.
In a test setup, returning e.g. a WText widget from DLL A and using it in application M (e.g. adding it to root() of the WApplication) gives Access Violations.
(building with VS 2008, running on Windows XP)

I'm actually wondering if this even 'can' work at all.
Things that make me wonder are:
- This simple setup does not work
- The DLLs and the executable all link with Wt and Wthttpd libs. In a normal application it is only linked in once.
- The related question: http://redmine.emweb.be/boards/2/topics/3573

Do you know if such a setup should actually work?
Or do you know another way to achive such 'plugin' functionality?


Replies

RE: One Wt executable with multiple 'plugin' DLLs that export their specific widgets - Added by Wim Dumon 4 months ago

Hello S,

I answered the question you refer to, I believe my suggestion may be your solution.

Note that to build Wt DLLs, you should set SHARED_LIBS to ON in cmake (I should have mentioned that in the other post too :)).

Can you verify if that suggestion works? As I said, I'm not 100% familiar with DLLs, and I know there are some weird corner cases, so I'm very interested to make this work.

Best regards,
Wim.

RE: One Wt executable with multiple 'plugin' DLLs that export their specific widgets - Added by S van der Hoest 4 months ago

Hi Wim,

Thanks for your response!

Today, before reading your response, I've run the test program in the debugger (had problems with the boost libs before, so far I only built for 'release'),
and I saw that the program indeed fails because of the static variables / singletons (the application & session).
These we're still NULL in the Widgets created in the DLL.

I did not think of linking to Wt as DLL before, I will try it next monday (first time I can get to it).
I'll give an update then.

RE: One Wt executable with multiple 'plugin' DLLs that export their specific widgets - Added by S van der Hoest 4 months ago

Well... it works!

Woke up early so had some time to try it out, and it works now! :)
Tested with one executable and two DLLs providing their own widget.

I set the following values in CMake:
- shared_libs: on
- boost_dynamic: on
- enable ssl: off

I also did the fix for the bug with 'HashFunction.C' in Wt 3.2.0 to get Wt to build as DLL.
(see http://redmine.webtoolkit.eu/boards/2/topics/3496)

When building the whole Wt solution I still get errors in 3 WT projects:
- wtdbo and wtdbosqlite3: errors on boost::gregorian::greg_month already being defined
- test: errors with dllimports of a few functions (exeption_safety, logged_expectations, unit_test_main)

I'll see if can find out what is the problem there later.
For now Wt, Wthttp and all the examples build OK.
Thanks!

RE: One Wt executable with multiple 'plugin' DLLs that export their specific widgets - Added by S van der Hoest 4 months ago

I've looked further into the build errors of the DBO + test projects.
On another PC in total 17 projects failed to build, e.g. also the 'dbo' example projects.

Turned out that these project files contain includes of specific static boost libs (LIBboost...'mt'),
while they I think only should link to the dynamic boost libs (boost...'mt' (non-debug) or 'mt-gd' (debug)).
After removing these 'includes' from the vcproj files, the errors were gone.

RE: One Wt executable with multiple 'plugin' DLLs that export their specific widgets - Added by Wim Dumon 4 months ago

There is a BOOST_DYNAMIC cmake variable that will let Wt link to boost DLLs instead of static libraries.

Not sure how you could resolve this by modifying 'includes', since the boost versions should be auto-detected on Windows...

Wrt the other compile errors, what is your exact configuration (wt version, boost version, compiler version)? What project fails to build?

Wim.

RE: One Wt executable with multiple 'plugin' DLLs that export their specific widgets - Added by S van der Hoest 4 months ago

Hi,

Yes, I have enabled the 'boost_dynamic' and 'shared_libs' option, and disabled 'enabled_sll'.

Configuration:
Wt: 3.2.0
Boost: 1.47
Compiler: VS 2008
CMake: 2.8.7

After selecting those options / configure / generate in CMake, I get libboost included in the 'AdditionalDependencies' options in several .vcproj files.
E.g.:
"C:\Program Files (x86)\boost\boost_1_47\lib\libboost_thread-vc90-mt-gd-1_47.lib"

Search "libboost" (152 hits in 19 files):
C:\Projects\wt-3.2.0\build\examples\blog\blog.wt.vcproj (8 hits)
C:\Projects\wt-3.2.0\build\examples\codeview\codingview.wt.vcproj (4 hits)
C:\Projects\wt-3.2.0\build\examples\feature\auth1\auth1.wt.vcproj (8 hits)
C:\Projects\wt-3.2.0\build\examples\feature\dbo\dbo-tutorial1.vcproj (8 hits)
C:\Projects\wt-3.2.0\build\examples\feature\dbo\dbo-tutorial2.vcproj (8 hits)
C:\Projects\wt-3.2.0\build\examples\feature\dbo\dbo-tutorial3.vcproj (8 hits)
C:\Projects\wt-3.2.0\build\examples\feature\dbo\dbo-tutorial4.vcproj (8 hits)
C:\Projects\wt-3.2.0\build\examples\feature\dbo\dbo-tutorial5.vcproj (8 hits)
C:\Projects\wt-3.2.0\build\examples\feature\dbo\dbo-tutorial6.vcproj (8 hits)
C:\Projects\wt-3.2.0\build\examples\feature\dbo\dbo-tutorial7.vcproj (8 hits)
C:\Projects\wt-3.2.0\build\examples\feature\dbo\dbo-tutorial8.vcproj (8 hits)
C:\Projects\wt-3.2.0\build\examples\filetreetable\filetreetable.wt.vcproj (4 hits)
C:\Projects\wt-3.2.0\build\examples\hangman\hangman.wt.vcproj (8 hits)
C:\Projects\wt-3.2.0\build\examples\planner\planner.wt.vcproj (8 hits)
C:\Projects\wt-3.2.0\build\examples\simplechat\simplechat.wt.vcproj (4 hits)
C:\Projects\wt-3.2.0\build\examples\wt-homepage\Home.wt.vcproj (12 hits)
C:\Projects\wt-3.2.0\build\src\Wt\Dbo\backend\wtdbosqlite3.vcproj (12 hits)
C:\Projects\wt-3.2.0\build\src\Wt\Dbo\wtdbo.vcproj (8 hits)
C:\Projects\wt-3.2.0\build\test\test.vcproj (12 hits)

With those boost libs installed, I get 'duplicate defined' errors, e.g. building 'wtdbo':
1>libboost_thread-vc90-mt-gd-1_47.lib(thread.obj) : error LNK2005: "public: __thiscall boost::gregorian::greg_month::greg_month(unsigned short)" (??0greg_month@gregorian@boost@@QAE@G@Z) already defined in boost_date_time-vc90-mt-gd-1_47.lib(boost_date_time-vc90-mt-gd-1_47.dll)

After removing those 'additional dependencies' it builds fine.

It seems that the CMake variables like 'Boost_DATE_TIME_LIBRARY_DEBUG' (which has 'libboost') end up incorrectly in the 'additional dependencies' section.