protobuf icon indicating copy to clipboard operation
protobuf copied to clipboard

Static variables in the autogenerated C++ headers prevent delay loading of dll

Open stolstov opened this issue 6 years ago • 4 comments

What language does this apply to? C++ Auto-generated code for C++

Describe the problem you are trying to solve. We build protobuf auto generated code into a dll. We would like to use delay-loading with this dll (DELAYLOAD linker option in Visual Studio). The auto generated header files contain exported static variables that produce the following link error: fatal error LNK1194: cannot delay-load 'mydll.dll' due to import of data symbol '"__declspec(dllimport) class xxxx::XXXXXDefaultTypeInternal xxxx::XXXX_default_instance"

Describe the solution you'd like Allow delay loading of the dll that exports protobuf autogenerated structures. A solution would be to avoid declaring exported static variables in the auto generated header files.

Describe alternatives you've considered We don't use delay load option right now.

stolstov avatar Feb 05 '19 23:02 stolstov

@stolstov I'm not sure if it's feasible for us to get rid of those static variables but do you have any ideas on how to do it?

acozzette avatar Feb 07 '19 22:02 acozzette

@acozzette In the header file you have this:

namespace xxx { __declspec(dllexport) XXXXXDefaultTypeInternal XXXX_default_instance }

Is it possible to replace these export variables with export functions that return the reference? namespace xxx { _declspec(dllexport) XXXXXDefaultTypeInternal& get_XXXX_default_instance(); }

In the cpp

XXXXXDefaultTypeInternal& get_XXXX_default_instance_() { return XXXX_default_instance }

Use get_XXXX_default_instance_() functions instead of global variables XXXX_default_instance in the auto generated code?

stolstov avatar Feb 07 '19 22:02 stolstov

The one potential issue is that if those functions are not inlined then there may be a performance cost.

acozzette avatar Feb 12 '19 23:02 acozzette

We triage inactive PRs and issues in order to make it easier to find active work. If this issue should remain active or becomes active again, please add a comment.

This issue is labeled inactive because the last activity was over 90 days ago.

github-actions[bot] avatar May 05 '24 10:05 github-actions[bot]

We triage inactive PRs and issues in order to make it easier to find active work. If this issue should remain active or becomes active again, please reopen it.

This issue was closed and archived because there has been no new activity in the 14 days since the inactive label was added.

github-actions[bot] avatar May 20 '24 10:05 github-actions[bot]