I used a 3rd party script to automatically generate a C++ project. Specifically a .cpp
and .h
file that I now wish to compile to a .dll
with VS2017.
A portion of the generated code (.cpp
) is as follows:
const ::PROTOBUF_NAMESPACE_ID::uint32 TableStruct_gameinformation_2eproto::offsets[] PROTOBUF_SECTION_VARIABLE( protodesc_cold ) = {
PROTOBUF_FIELD_OFFSET(::GameInfo::GameInformation, _has_bits_ ),
PROTOBUF_FIELD_OFFSET(::GameInfo::GameInformation, _internal_metadata_ ),
~0u, // no _extensions_
~0u, // no _oneof_case_
~0u, // no _weak_field_map_
PROTOBUF_FIELD_OFFSET(::GameInfo::GameInformation, gamemessage_ ),
PROTOBUF_FIELD_OFFSET(::GameInfo::GameInformation, eacmessagebuffer_ ),
PROTOBUF_FIELD_OFFSET(::GameInfo::GameInformation, eacmessagelength_ ),
0,
1,
2,
};
This is the only definition/assignment of a value to this variable in the whole project.
When I try to compile my project (Release x64 in VS), this portion of code throws this error:
Error C2491 'TableStruct_gameinformation_2eproto::offsets': definition of dllimport static data member not allowed
This is the error I am trying to resolve, specifically.
I googled this, and according to the Microsoft docs, I need to get rid of the value assignment, ie, only retain this much:
const ::PROTOBUF_NAMESPACE_ID::uint32 TableStruct_gameinformation_2eproto::offsets[] PROTOBUF_SECTION_VARIABLE( protodesc_cold )
This does not seem like a robust solution to me. This file was automatically generated and I am quite sure those values are important.
After reading another Stack Overflow question, I ca nconfirm that this code (.h
) contains a define
that switches between dllimport
and dllexport
(so please don't mark as duplicate):
#if BUILD_GAMEINFORMATION
#define MY_EXPORT_MACRO __declspec( dllexport )
#else
#define MY_EXPORT_MACRO __declspec( dllimport )
#endif
If I have to take the Microsoft solution, does it matter if these values are lost? Is there somewhere else I can put them? Or is there an alternative?