簡體   English   中英

使用 python 的 C++ 的簡單 SWIG 可以編譯,但 output 似乎不正確?

[英]Simple SWIG with C++ for python compiles but the output does not seem to be correct?

我對 SWIG(和 c++)相當陌生,所以我試圖使用這個網站上的一個例子,這似乎是一個簡單的代碼。 我在 Visual Studio 上編譯它......成功(我認為?)。

1>------ Rebuild All started: Project: minimal, Configuration: Release x64 ------
1>Performing Custom Build Tools
1>minimal.cpp
1>minimal_wrap.cxx
1>   Creating library ..._minimal2.lib and object ...minimal2.exp
1>Generating code
1>Previous IPDB not found, fall back to full compilation.
1>All 70 functions were compiled because no usable IPDB/IOBJ from previous compilation was found.
1>Finished generating code
1>minimal.vcxproj -> C:\...\_minimal.pyd
========== Rebuild All: 1 succeeded, 0 failed, 0 skipped ==========

但是當我嘗試在 spyder (ipython 控制台)上運行它時

import _minimal
m1 = minimal.minimal()
print(m1)

輸出<minimal.minimal; proxy of <Swig Object of type 'minimal2 *' at 0x000001D0C68BDDE0> <minimal.minimal; proxy of <Swig Object of type 'minimal2 *' at 0x000001D0C68BDDE0>

從教程網站上,聽起來我應該得到一些整數?

m1.print_num_instances()

此命令導致沒有 output... 我的文件沒有正確構建嗎?

所以看起來我必須添加“typemaps.i”並定義 output 類型。 我沒有處理上述問題中使用的示例,但我發現另一個示例非常有用。

/* typemaps.i allows input and output pointer arguments to be specified using the names INPUT, OUTPUT, or INOUT */
%include "typemaps.i"

void   hw1(double r1, double r2, double *OUTPUT);

該示例顯示了他們的第一次嘗試以我得到的類似指針類型的響應失敗。 然后在 typeamps.i 之后,它 hw1 function 工作!

暫無
暫無

聲明:本站的技術帖子網頁,遵循CC BY-SA 4.0協議,如果您需要轉載,請注明本站網址或者原文地址。任何問題請咨詢:yoyou2525@163.com.

 
粵ICP備18138465號  © 2020-2024 STACKOOM.COM