我正在尝试使用cmake编译在Maya API找到的示例插件来创建Visual Studio 2012项目。但是,在编译Maya附带的库时似乎存在许多问题。第一个问题是库试图补偿一些旧的缺失bool实现,这是通过添加预处理器定义来解决的
add_definitions(-D _BOOL)
到cmake文件。
它们库中的下一个错误是它试图访问std :: ostream而无法在'std'中找到它的问题,这是使用cmake中的另一个定义来解决的:
add_definitions(-D REQUIRE_IOSTREAM)
这导致了我无法通过的最终错误,我已经用Google搜索了它,查看了stackoverflow并查看了maya附带的示例VSproject文件,无法解决。 错误(总共18个)源于链接器,并且都是未解析的外部符号,例如错误:
Error 1 error LNK2019: unresolved external symbol "__declspec(dllimport) public: __thiscall MStatus::MStatus(enum MStatus::MStatusCode)" (__imp_??0MStatus@@QAE@W4MStatusCode@0@@Z) referenced in function "public: virtual class MStatus __thiscall hello::doIt(class MArgList const &)" (?doIt@hello@@UAE?AVMStatus@@ABVMArgList@@@Z) C:\path\mayacmake_sample\helloworld.obj Sample_helloworld
修改 使用Andreas修改过的cmakelist没有产生任何差异: 嘿,谢谢你的回复,但我仍然在inresolved externals中遇到很多错误:
Error 1 error LNK2019: unresolved external symbol "__declspec(dllimport) public: __thiscall MStatus::MStatus(enum MStatus::MStatusCode)" (__imp_??0MStatus@@QAE@W4MStatusCode@0@@Z) referenced in function "public: virtual class MStatus __thiscall hello::doIt(class MArgList const &)" (?doIt@hello@@UAE?AVMStatus@@ABVMArgList@@@Z) D:\mayacmake_sample\helloworld.obj Maya_Sample_Plugin
Error 13 error LNK2001: unresolved external symbol "public: virtual bool __thiscall MPxCommand::hasSyntax(void)const " (?hasSyntax@MPxCommand@@UBE_NXZ) D:\mayacmake_sample\helloworld.obj Maya_Sample_Plugin
我删除了其他错误,因为它们与上面的两个错误相同。 我确保修改cmake文件中的路径以适合我的安装,现在看起来如下:
cmake_minimum_required (VERSION 2.6)
SET(MAYA_PLUGIN_NAME "Maya_Sample_Plugin")
SET(MAYA_DIRECTORY "C:/Program Files/Autodesk/Maya2013")
SET(MAYA_HEADERS_DIR "${MAYA_DIRECTORY}/include")
SET(MAYA_LIBRARY_DIR "${MAYA_DIRECTORY}/lib")
SET(SOURCE_FILES
helloworld.cpp
)
source_group("" FILES ${SOURCE_FILES})
INCLUDE_DIRECTORIES(
${MAYA_HEADERS_DIR}
${Boost_INCLUDE_DIR}
)
LINK_DIRECTORIES(
${MAYA_LIBRARY_DIR}
)
SET(LIBRARIES
Foundation.lib
OpenMaya.lib
OpenMayaAnim.lib
OpenMayaUI.lib
)
SET(MAYA_DEFINITIONS _AFXDLL _MBCS NT_PLUGIN REQUIRE_IOSTREAM _BOOL)
ADD_LIBRARY(${MAYA_PLUGIN_NAME} SHARED ${SOURCE_FILES})
TARGET_LINK_LIBRARIES(${MAYA_PLUGIN_NAME} ${LIBRARIES})
SET_TARGET_PROPERTIES(${MAYA_PLUGIN_NAME} PROPERTIES COMPILE_DEFINITIONS "${MAYA_DEFINITIONS}")
SET_TARGET_PROPERTIES(${MAYA_PLUGIN_NAME} PROPERTIES OUTPUT_NAME "${MAYA_PLUGIN_NAME}")
SET_TARGET_PROPERTIES(${MAYA_PLUGIN_NAME} PROPERTIES SUFFIX ".mll")
SET_TARGET_PROPERTIES(${MAYA_PLUGIN_NAME} PROPERTIES CLEAN_DIRECT_OUTPUT 1)
任何有关此事的帮助都是适当的。
答案 0 :(得分:2)
您需要告诉链接器链接哪些lib,完成TARGET_LINK_LIBRARIES
。这是我在CMakeLists.txt中使用的内容。
SET(MAYA_PLUGIN_NAME "myCoolPlugin")
SET(MAYA_DIRECTORY "D:/Program Files (x86)/Autodesk Maya2011")
SET(MAYA_HEADERS_DIR "${MAYA_DIRECTORY}/include")
SET(MAYA_LIBRARY_DIR "${MAYA_DIRECTORY}/lib")
SET(SOURCE_FILES
myCoolPlugin.cpp
)
source_group("" FILES ${SOURCE_FILES})
INCLUDE_DIRECTORIES(${MAYA_HEADERS_DIR})
LINK_DIRECTORIES(${MAYA_LIBRARY_DIR})
SET(LIBRARIES Foundation.lib OpenMaya.lib OpenMayaAnim.lib OpenMayaUI.lib)
SET(MAYA_DEFINITIONS _AFXDLL _MBCS NT_PLUGIN REQUIRE_IOSTREAM _BOOL)
ADD_LIBRARY(${MAYA_PLUGIN_NAME} SHARED ${SOURCE_FILES})
TARGET_LINK_LIBRARIES(${MAYA_PLUGIN_NAME} ${LIBRARIES})
SET_TARGET_PROPERTIES(${MAYA_PLUGIN_NAME} PROPERTIES COMPILE_DEFINITIONS "${MAYA_DEFINITIONS}")
SET_TARGET_PROPERTIES(${MAYA_PLUGIN_NAME} PROPERTIES OUTPUT_NAME "${MAYA_PLUGIN_NAME}")
SET_TARGET_PROPERTIES(${MAYA_PLUGIN_NAME} PROPERTIES SUFFIX ".mll")
SET_TARGET_PROPERTIES(${MAYA_PLUGIN_NAME} PROPERTIES CLEAN_DIRECT_OUTPUT 1)
SET_TARGET_PROPERTIES(${MAYA_PLUGIN_NAME} PROPERTIES LINK_FLAGS "/export:initializePlugin /export:uninitializePlugin")