Long story short, I would like to create a Protocol Buffer object inside the initializePlugin()
, defined in pluginMain.cpp as shown below:
// pluginMain.cpp
#include "hello.pb.h"
MStatus initializePlugin( MObject obj )
{
MGlobal::displayInfo( "Plugin is initialized!" );
hellopb_plugin::Foo f1;
return MStatus::kSuccess;
}
MStatus uninitializePlugin( MObject obj )
{
...
}
hellopb_plugin
is a very simple protobuf type defined by the following hello.proto file:
// hello.proto
syntax = "proto3";
package hellopb_plugin;
message Foo
{
optional string name = 1;
}
The CMakeLists.txt I use includes the following:
cmake_minimum_required(VERSION 3.12)
if (NOT DEFINED CMAKE_TOOLCHAIN_FILE AND DEFINED ENV{CMAKE_TOOLCHAIN_FILE})
set(CMAKE_TOOLCHAIN_FILE $ENV{CMAKE_TOOLCHAIN_FILE})
endif()
project( Hello )
find_package( Protobuf REQUIRED )
include_directories( ${Protobuf_INCLUDE_DIRS} )
file( TO_NATIVE_PATH ${CMAKE_CURRENT_SOURCE_DIR} PROTO_INPUT_PATH )
file( TO_NATIVE_PATH ${CMAKE_CURRENT_SOURCE_DIR} PROTO_OUTPUT_PATH )
file( GLOB PROTO_FILES "${CMAKE_CURRENT_SOURCE_DIR}/*.proto" )
foreach( proto ${PROTO_FILES})
file( TO_NATIVE_PATH ${proto} proto_native )
execute_process( COMMAND ${PROTOBUF_PROTOC_EXECUTABLE} --proto_path=${PROTO_INPUT_PATH} --cpp_out=${PROTO_OUTPUT_PATH} ${proto_native} )
endforeach()
file( GLOB HDRS "${CMAKE_CURRENT_SOURCE_DIR}/*.pb.h" )
file( GLOB SRCS "${CMAKE_CURRENT_SOURCE_DIR}/*.pb.cc" )
add_library( ${PROJECT_NAME}Proto ${HDRS} ${SRCS} )
link_libraries( ${PROJECT_NAME}Proto ${Protobuf_LIBRARIES} )
set( ${PROJECT_NAME}Proto_PATH ${PROJECT_NAME}Proto )
set( SOURCE_FILES pluginMain.cpp )
set( LIBRARIES OpenMaya OpenMayaUI OpenMayaAnim OpenMayaFX OpenMayaRender Foundation ${PROJECT_NAME}Proto )
include( $ENV{DEVKIT_LOCATION}/cmake/pluginEntry.cmake )
build_plugin()
Currently, the code builds, and links, fine when running cmake ..
and cmake --build . --clean-first
from a build/
inside the project folder, but the plugin cannot be loaded. The following error is shown in the script editor:
// Error: file: C:/.../Autodesk/Maya2022/scripts/others/pluginWin.mel line 934: Unable to dynamically load : C:/.../maya_plugin/build/Debug/Hello.mll
The specified module could not be found.
// Error: file: C:/.../Autodesk/Maya2022/scripts/others/pluginWin.mel line 934: The specified module could not be found.
(Hello) //
// Warning: file: C:/.../Autodesk/Maya2022/scripts/others/pluginWin.mel line 937: Could not load C:/.../maya_plugin/build/Debug/Hello.mll as a plug-in //
Although Hello.mll
is created in the Debug/
, it seems that there is a run-time problem that prevents the plugin from being loaded. As a test, I commented out the definition of f1
from the initialize_plugin()
function, and the plugin was loaded successfully.
Q1: What is causing this problem?
Q2: Is the CMakeLists.txt file properly written to load Protocol Buffers?
Please note, that the CMakeLists.txt should not create an executable, as it's a plugin. Also, I am currently running Windows 10 and I have successfully installed Google's Protocol Buffers via vcpkg
. To test the installation of the library, I created a similar example only as an executable, and it works properly.