Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

$dllexport_decl$ is missing in generated .pb.cc #13084

Closed
owent opened this issue Jun 16, 2023 · 3 comments
Closed

$dllexport_decl$ is missing in generated .pb.cc #13084

owent opened this issue Jun 16, 2023 · 3 comments

Comments

@owent
Copy link
Contributor

owent commented Jun 16, 2023

What version of protobuf and what language are you using?
Version: v21/v23
Language: C++

What operating system (Linux, Windows, ...) and version?

Windows,Linux

What runtime / compiler are you using (e.g., python version or gcc version)

GCC 13, GCC 4.8, MSVC 19.36

What did you do?

  1. Using --cpp_out=dllexport_decl=XXX_API:<OUTPUT DIR>.
  2. Set the visibility to hidden.
  3. Build generated .pb.cc as shared libraries.
  4. See error

What did you expect to see

Linking success.

What did you see instead?

Unresolved reference to PACKAGE::_MESSAGE_default_instance_.

Anything else we should know about your project / environment

$dllexport_decl$ is missing for default instance in generated .pb.cc.

@owent owent added the untriaged auto added to all issues by default when created. label Jun 16, 2023
@deannagarcia
Copy link
Member

Can you provide some more details here? What version of C++ are you using? What's the full command you are running? And can you copy over error logs?

@fowles
Copy link
Contributor

fowles commented Jun 16, 2023

They sent a PR that I am already reviewing, so no need for details

fowles pushed a commit to fowles/protobuf that referenced this issue Jun 16, 2023
…3085)

Fixes protocolbuffers#13084

Closes protocolbuffers#13085

COPYBARA_INTEGRATE_REVIEW=protocolbuffers#13085 from owent:add_dllexport_decl_for_generated_default_instance a46d4e8
PiperOrigin-RevId: 540938351
@owent
Copy link
Contributor Author

owent commented Jun 17, 2023

Can you provide some more details here? What version of C++ are you using? What's the full command you are running? And can you copy over error logs?

For the usage in our project.

  1. We write a message in proto file , for example message DBattleAffix {...} in affix.proto
  2. Generate affix.pb.h and affix.pb.cc with protoc --cpp_out=dllexport_decl=TGF_BATTLE_PROTOCOL_API:$SOURCE_DIR and build them as a dll and define TGF_BATTLE_PROTOCOL_API=__declspec(dllexport).(Unreal Engine plugin on Windows)
  3. In another dll(another Unreal Engine plugin on Windows), we use the generated header file above (affix.pb.h) and define TGF_BATTLE_PROTOCOL_API=__declspec(dllimport) .
  4. When linking, it shows TGFBattleUtility.lib(BattleAffixAlgorithm.obj): Error LNK2001: unresolved external symbol "struct tgf::DBattleAffixDefaultTypeInternal tgf::_DBattleAffix_default_instance_" (?_DBattleAffix_default_instance_@tgf@@3UDBattleAffixDefaultTypeInternal@1@A)

I think there is similar problems when we build these .pb.cc files with -fvisibility=hidden and define TGF_BATTLE_PROTOCOL_API=__attribute__((visibility("default"))) , but I didn't test it yet.

@googleberg googleberg removed the untriaged auto added to all issues by default when created. label Feb 17, 2024
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

Successfully merging a pull request may close this issue.

5 participants
@fowles @owent @deannagarcia @googleberg and others