How to properly use the main application's DBO models in DLL plugins?
Added by Alex Tumovsky 30 days ago
Hello. I need help.
I'm trying to write an application with a modular architecture: a main application (which includes static plugins during compilation) and dynamic libraries (subroutine modules) loaded into it.
My problem is this: the main application needs to have some "base" models that need to be accessed natively in both the main application, static modules, and dynamic modules. Dynamic modules can also contain their own models (but they're easier, as the necessary data is retrieved from them using an API).
And the task is to compile it all (Windows/Linux).
I encountered an issue with exporting template DBO symbols for model classes (e.g., User, Categories, Accounting, etc.).
template class Wt::Dbo::ptr;
template class Wt::Dbo::Dbo;
template class Wt::Dbo::MetaDbo;
Template class Wt::Dbo::collection< Wt::Dbo::ptr >;
Template class Wt::Dbo::Query< Wt::Dbo::ptr,
Wt::Dbo::DynamicBinding >;
So, I'd like to use the DBO model, which is fully defined in the main application in a dynamic module, using the standard DBO methods (find, query, etc).
I tried moving all the common models into a static library and including it in all parts of the application, but this also doesn't work transparently with DBO, complaining about the missing structure definition.
Is there a way to implement something like this?
Replies (2)
RE: How to properly use the main application's DBO models in DLL plugins? - Added by Matthias Van Ceulebroeck 30 days ago
Hi Alex,
from the top of my head I would attempt something like this structure (in CMake)
# Common library with Dbo items
add_library(common {...sources})
# Add wtdbo publicly, so any binary that links to `common` can find `wtdbo` as well.
target_link_library(common PUBLIC wtdbo)
# Main application
add_executable(executable {...sources})
target_link_library(executable PRIVATE common)
# Modules
add_executable(module1 {...sources})
target_link_library(module1 PRIVATE common)
This wasn't tested specifically, but I would expect this to work.
RE: How to properly use the main application's DBO models in DLL plugins? - Added by Christian Meyer 12 days ago
Hi Alex,
I am not 100% sure what you are planning and having trouble with.
But I do have a Modularized Architecture in my Project:
moduleSession
- Contains a ConnectionPool and defines all things regarding the Session Object
- Links to wtdbo and the available backends
moduleFunction - named Module for Functionality
- just includes Dbo headers where necessary
- has helper function to add Dbo classes to Session object in moduleSession
- does not link to moduleSession or wt at all, is standalone sharedLib
add_library
appFunction - named for App
- Combines different Modules
- links to moduleFunction
- links to moduleSession
add_library
my Server can host multiple Apps (primary exec)
- depending on CMake variables, apps can be activated and deactivated
- provides entryPoints
- links appFunction wt wthttp
add_executable
I only had this build in linux devcontainer with shared libs.
No Experience with dynamic libraries in this.
If this is interesting, please reach out =)
Cheers, Christian