Closed MicBe closed 7 years ago
Adding an explicit default constructor for each custom class registered to rttr solved the problem! Types in classes cpp were not registered before this. Seems like the exact same problem as on this forum topic : https://social.msdn.microsoft.com/Forums/vstudio/en-US/2aa2e1b7-6677-4986-99cc-62f463c94ef3/linkexe-bug-optnoref-option-doesnt-work?forum=vclanguage
"My program contains static objects whose constructors are supposed to run at the beginning of the program, but otherwise those variables are unreferenced. The problem is, when I put these variables into a .lib file, they get completely optimized away and never appear in the resulting .exe! "
Not a rttr problem!
Does it mean the registration call will not be executed? I don't know anything about these settings Link Library Dependencies
and Use Library Dependency Inputs
. When everything works for you as expected, please close the issue.
I am using rttr as a static library in a Visual Studio 2015 solution.
I have two projects: Project A: Makes calls to a "deserializer" in Project B. This project generates an executable Project B: This project depends on rttr_core_lib_s_d.lib. Contains classes to be created dynamically by rttr (variant::create()). Every class is registered to rttr in the corresponding .cpp. This project generates a .lib.
I have this code somewhere in project B, that "dynamically" creates an object of a class declared in project B:
rttr::variant arrayVariant = property.get_value(instance); auto arrayItems = arrayVariant.create_array_view(); rttr::type itemType = arrayItems.get_rank_type(1); // itemType = ProjectB::MyClassType. itemType.is_valid() returns true rttr::variant object = itemType.create(); assert(object.is_valid());
This code is working (object.is_valid() == true) in a specific condition: If Project A has a reference to Project B and both options "Link Library Dependencies" and "Use Library Dependency Inputs" on that reference are set to "True".
However, if I set "Use Library Dependency Inputs" to false, I get "object.is_valid() == false". This only occurs for the creation of objects of classes that are declared in Project B.
For technical reasons relevant to our automated build system, I cannot depend on the flag "Use Library Dependency Inputs" being set to true. Do you have an idea why the creation of objects fails when the option "Link Library Dependencies" is set to false on a project reference? That option makes the project link against the .obj files instead of the .lib generated.
Thanks!