SWIG和windows导出宏

2024-05-16 12:35:39 发布

您现在位置:Python中文网/ 问答频道 /正文

我试图用VisualStudio 2018和Python 3.7和Sug 3.0.12来浏览一个简单的C++类。 我的C++头< /p>
#ifndef atATObjectH
#define atATObjectH
#include "core/atCoreExporter.h"
#include <string>
//-------------------------------------------------------------------------- 
using std::string;

class AT_CORE ATObject
{
    public:
                                ATObject();
        virtual                 ~ATObject();
        virtual const string    getTypeName() const;
};
#endif

atCoreExporter.h:

^{pr2}$

我确实创建了一个定义了AT_EXPORT_CORE的DLL。在

我使用CMake生成swigged pyd模块。这是接口文件:

^{3}$

这是CMake文件

FIND_PACKAGE(SWIG REQUIRED)
INCLUDE(${SWIG_USE_FILE})
FIND_PACKAGE(PythonLibs)
INCLUDE_DIRECTORIES(${PYTHON_INCLUDE_PATH})
INCLUDE_DIRECTORIES(${CMAKE_CURRENT_SOURCE_DIR})
SET(CMAKE_SWIG_FLAGS "")

SET_SOURCE_FILES_PROPERTIES(atexplorer.i PROPERTIES CPLUSPLUS ON)

SWIG_ADD_LIBRARY(atexplorer LANGUAGE python SOURCES atexplorer.i)
INCLUDE_DIRECTORIES(
.
${ATAPI_ROOT}
${ATAPI_ROOT}/source
${ATAPI_ROOT}/source/core
)

link_directories(${LIBRARY_OUTPUT_PATH})

SWIG_LINK_LIBRARIES (atexplorer
    atCore
    ${PYTHON_LIBRARIES}
)

SET(ATEXPLORER_PACKAGE_DIR site-package)

SET(python_files_path ${CMAKE_BINARY_DIR}/wrappers/python/atexplorer)

INSTALL(
    TARGETS _atexplorer
    DESTINATION ${ATEXPLORER_PACKAGE_DIR}
    COMPONENT python_module
)

INSTALL(
    FILES ${python_files_path}/atexplorer.py __init__.py
    DESTINATION ${ATEXPLORER_PACKAGE_DIR}
    COMPONENT python_module
)

我遇到的问题是导出/导入宏。上面的接口文件无法编译,我从生成的SWIG代码中得到编译错误,如下所示

AT_CORE * temp;
temp  = reinterpret_cast< AT_CORE * >(argp);
ATObject = *temp;

其中AT_CORE是上面atCoreExporter.h中定义的导出/导入宏。在

怎样才能解决这个问题呢?在


Tags: 文件corecmakepackagestringincludedirat
1条回答
网友
1楼 · 发布于 2024-05-16 12:35:39

在使用宏之前,请确保swig接口文件包含宏头。我可以通过在.I文件中添加“%include”来解决此问题。在

// atexplorer.i
%include "std_string.i"
%include "windows.i"

%module atexplorer
%{
#include "atATObject.h"
%}

//Expose class ATObject to Python
%include "atCoreExporter.h"
%include "atATObject.h"

相关问题 更多 >