google/mediapipe

error LNK2019: 无法解析的外部符号 "private: static class RegistrationToken::RegistrationToken const mediapipe::tool::OptionsRegistry::registration_token<class mediapipe::FaceDetectionOptions>"

lucasjinreal opened this issue · 13 comments

error LNK2019: 无法解析的外部符号 "private: static class RegistrationToken::RegistrationToken const mediapipe::tool::OptionsRegistry::registration_token"

This is due to probably a static variable not initialized in a c++ class (RegistrationToken::RegistrationToken const mediapipe::tool::OptionsRegistry).
need to investigate further.

inference_calculator_options_registry.lo.lib(inference_calculator_options_lib.obj) : error LNK2019: unresolved external symbol "private: static class RegistrationToken::RegistrationToken const mediapipe::tool::OptionsRegistry::registration_token<class mediapipe::InferenceCalculatorOptions>" (??$registration_token@VInferenceCalculatorOptions@mediapipe@@@OptionsRegistry@tool@mediapipe@@0VRegistrationToken@3@B)
referenced in function "??__E?$registration_token@VInferenceCalculatorOptions@mediapipe@@@OptionsRegistry@tool@mediapipe@@yaxxz" (??__E?$registration_token@VInferenceCalculatorOptions@mediapipe@@@OptionsRegistry@tool@mediapipe@@yaxxz)
bazel-out\x64_windows-opt\bin\mediapipe\examples\desktop\hand_tracking\hand_tracking_cpu.exe : fatal error LNK1120: 1 unresolved externals

I'm seeing the exact same problem as @jinfagang when I try to build the MediaPipe Hands example on Windows. I was able to build the Hello World example successfully, but not this one.

I worked around this problem by commenting these two lines in mediapipe\framework\tool\options_registry.h:

template <class MessageT>
static const RegistrationToken registration_token;

And by commenting this in mediapipe\framework\tool\options_lib_template.cc:

namespace mediapipe {
// The protobuf descriptor for an options message type.
template <>
const RegistrationToken tool::OptionsRegistry::registration_token<
    MP_OPTION_TYPE_NS::MP_OPTION_TYPE_NAME> =
    tool::OptionsRegistry::Register(ReadFileDescriptorSet(
        std::string(kDescriptorContents, sizeof(kDescriptorContents) - 1)));
}  // namespace mediapipe

Once I did that, the MediaPipe Hands example built successfully and worked perfectly.

This is a hacky workaround, but hopefully it helps.

@diegomacario waw, nice catch, I will test on my side. I am building face detection on desktop.

@diegomacario @jaydeepsaravaiya I think it because of the VirtualStudio version problem. for 2022 version, it fails. 2019 can build.

Oh good to know, thanks @jinfagang!

I can verify it was MSVC 2022 failed, @google-admin Please fix mediapipe MSVC 2022 build, since we are in 2023 now.

I'm seeing the exact same problem as @jinfagang when I try to build the MediaPipe Hands example on Windows. I was able to build the Hello World example successfully, but not this one.

Did Hello world worked properly for you. For me it builds but doesnt do anything.

Hello @jinfagang Is your issue resolved?

Yes. but another issue happend.

Are you satisfied with the resolution of your issue?
Yes
No