今天我遇到了同样的问题,对我来说,我没有在课堂上包含类型。那就是我必须改变:
class Core
{
private:
py::object cls;
py::object obj;
py::object startFunc;
py::object startFuncAsync;
py::object stopFunc;
...
public:
...
};
至
#ifndef CORE_H
#define CORE_H
/* If we are we on Windows, we want a single define for it.*/
#if !defined(_WIN32) && (defined(__WIN32__) || defined(WIN32) || defined(__MINGW32__))
#define _WIN32
#endif /* _WIN32 */
#if defined(_WIN32) && defined(_CORE_BUILD_DLL)
/* We are building FV as a Win32 DLL */
#define CORE_API __declspec(dllexport)
#elif defined(_WIN32) && defined(CORE_DLL)
/* We are calling FV as a Win32 DLL */
#define CORE_API __declspec(dllimport)
#elif defined(__GNUC__) && defined(_CORE_BUILD_DLL)
/* We are building FV as a shared / dynamic library */
#define CORE_API __attribute__((visibility("default")))
#else
/* We are building or calling CORE as a static library */
#define CORE_API
#endif
class CORE_API Core
{
private:
py::object cls;
py::object obj;
py::object startFunc;
py::object startFuncAsync;
py::object stopFunc;
...
public:
...
};
边注:
这将允许将您的项目构建为 adll
或 alib
并且两者都不是(即通过包含它们来使用它们)并且您还可以在 linux 下编译此代码,因此这里没有特定于平台的内容。
如果您在 Visual Studio 中并想构建一个 dll,只需转到 Properties>C/C++>CommandLine 并输入:
/D_CORE_BUILD_DLL
并替换CORE
为您自己指定的名称。