当前位置: 首页 > news >正文

杭州公司网站建设哪家好网页设计制作网站素材

杭州公司网站建设哪家好,网页设计制作网站素材,福建做网站,线上企业推广公司摘要 win10系统,编译器为mingw,按照教程封装C的一个类并用python调用,一步步进行直到最后一步运行python代码时,在python代码中import example时报错ImportError: DLL load failed while importing _example: The specified modul…

摘要 win10系统,编译器为mingw,按照教程封装C++的一个类并用python调用,一步步进行直到最后一步运行python代码时,在python代码中import example时报错ImportError: DLL load failed while importing _example: The specified module could not be found.本文记录我的解决方法和其它一些解决思路。

先测试C语言

官方文档有完整教程,命令分别为

swig -python example.i
gcc -c -fpic example.c example_wrap.c -I “C:/Users/xd15zhn/AppData/Local/Programs/Python/Python310/include”
gcc -shared example.o example_wrap.o -o _example.pyd -L “C:/Users/xd15zhn/AppData/Local/Programs/Python/Python310/libs” -lpython310

注意包含头文件目录和库目录,具体方法见文末的参考链接。
example.c

#include <stdio.h>
double My_variable = 3.0;
int my_sum(double a, double b) {return(a + b);
}
void my_print() {printf("Hello World!\n");
}

example.i

%module example
%{extern double My_variable;extern int my_sum(int n, int m);extern void my_print();
%}
extern double My_variable;
extern int my_sum(int n, int m);
extern void my_print();

main.py

import example
example.my_print()
print(example.my_sum(1,2))

再测试C++

swig -c++ -python example.i
g++ -c -fPIC example.cpp example_wrap.cxx -I “C:/Users/xd15zhn/AppData/Local/Programs/Python/Python310/include”
g++ -shared example.o example_wrap.o -o _example.pyd -L “C:/Users/xd15zhn/AppData/Local/Programs/Python/Python310/libs” -lpython310

example.cpp

#include <iostream>
#include "example.hpp"
void Example::say_hello() {std::cout << "Hello world!" << std::endl;
}
double Example::my_sum(double a, double b) {return a+b;
}

example.hpp

class Example {
public:void say_hello();double my_sum(double a, double b);
};

example.i

%module example
%{
#include "example.hpp"
%}
%include "example.hpp"

main.py

import example
e = example.Example()
e.say_hello()
print(e.my_sum(1,2))

运行本节开头的3条命令后,不出意外的话,运行3条命令后依次分别生成:

  1. example.py, example_wrap.cxx
  2. example.o example_wrap.o
  3. _example.pyd

问题描述与解决

最后运行main.py后在import example时报错ImportError: DLL load failed while importing _example: The specified module could not be found. stackoverflow上有人提到了这个问题,一个解决方法是

I met exactly the same problem after upgraded python to 3.9 on windows . After struggling for hours, I managed to solve it by manually copying some dlls from ***/mingw/bin/ where mingw32-g++ is found to where my ***.pyd is located. I’m sure that ***/mingw/bin/ has been appended to %PATH%, but don’t know why python3.9 couldn’t find it.

按照这个方法我把/mingw/bin/目录下的所有.dll文件全都复制到当前项目目录下确实解决了问题,但文中说只复制了一部分,想到使用静态编译需要用到两个命令-static-libstdc++-static-libgcc,然后测试了一下确实是只需要这两个文件。除了复制文件这一不太优雅的方法以外,只需要在python代码中加上/mingw/bin/目录即可,完整的python代码如下

import os
os.add_dll_directory('C:/Users/xd15zhn/Documents/mingw64/bin')
import example
e = example.Example()
e.say_hello()
print(e.my_sum(1,2))

但这种方法还是不够优雅,能不能把这两个动态库直接链接到_example.pyd文件里?我尝试在上面第3条命令后加上-llibgcc_s_sjlj-1 -llibstdc++-6,但没有用。不知道有没有更优雅的解决方法。

其它

下面的代码用于单独生成example.cpp的动态库来测试自己写的代码是否有问题。

g++ example.cpp -fpic -shared -o example.dll
g++ main.cpp example.dll -o untitled

参考

SWIG doesn’t work on Windows with MinGW-w64 when binding C++ and Python: DLL load failed while importing: The specified module could not be found -stackoverflow
gcc静态编译之-static-libstdc++、-static-libgcc、-static -简书
g++编译详解 -CSDN博客
gcc&g++链接动态库或静态库方法 -CSDN博客
SWIG:Python调用C++(新手保姆级示范) -知乎
The specified module could not be found的解决办法 -CSDN博客


文章转载自:
http://offhandedly.c7507.cn
http://unanalysed.c7507.cn
http://irrepressibly.c7507.cn
http://terrella.c7507.cn
http://sacrist.c7507.cn
http://pyrogen.c7507.cn
http://ruddleman.c7507.cn
http://thruster.c7507.cn
http://anodontia.c7507.cn
http://kursaal.c7507.cn
http://selfsame.c7507.cn
http://shanty.c7507.cn
http://dolomitize.c7507.cn
http://pyrochemical.c7507.cn
http://aniseed.c7507.cn
http://kutaraja.c7507.cn
http://echoism.c7507.cn
http://forbye.c7507.cn
http://redemptorist.c7507.cn
http://heirloom.c7507.cn
http://isoagglutinin.c7507.cn
http://oofy.c7507.cn
http://anthracite.c7507.cn
http://estelle.c7507.cn
http://schatzi.c7507.cn
http://histogenesis.c7507.cn
http://checkless.c7507.cn
http://scampish.c7507.cn
http://pyelography.c7507.cn
http://eyeballing.c7507.cn
http://marline.c7507.cn
http://mawl.c7507.cn
http://disingenuously.c7507.cn
http://pass.c7507.cn
http://afterdeck.c7507.cn
http://jealously.c7507.cn
http://typey.c7507.cn
http://revulsive.c7507.cn
http://inaptness.c7507.cn
http://parametrize.c7507.cn
http://lingula.c7507.cn
http://pantryman.c7507.cn
http://wifedom.c7507.cn
http://introversion.c7507.cn
http://fascinatedly.c7507.cn
http://might.c7507.cn
http://adige.c7507.cn
http://ribitol.c7507.cn
http://chloritize.c7507.cn
http://myall.c7507.cn
http://layman.c7507.cn
http://biogeocoenology.c7507.cn
http://bugshah.c7507.cn
http://tapadera.c7507.cn
http://echelon.c7507.cn
http://budgeree.c7507.cn
http://nonperformance.c7507.cn
http://casimire.c7507.cn
http://sonsie.c7507.cn
http://hedonism.c7507.cn
http://paranoiac.c7507.cn
http://fuddle.c7507.cn
http://audiophile.c7507.cn
http://protectory.c7507.cn
http://indistinction.c7507.cn
http://unimpeached.c7507.cn
http://gynogenesis.c7507.cn
http://nunciature.c7507.cn
http://leaseback.c7507.cn
http://flatiron.c7507.cn
http://snotty.c7507.cn
http://weldor.c7507.cn
http://pianissimo.c7507.cn
http://thea.c7507.cn
http://oaken.c7507.cn
http://columnar.c7507.cn
http://steapsin.c7507.cn
http://erythritol.c7507.cn
http://emblaze.c7507.cn
http://bhil.c7507.cn
http://xiv.c7507.cn
http://leftist.c7507.cn
http://retinaculum.c7507.cn
http://geminal.c7507.cn
http://neuropathy.c7507.cn
http://immemorial.c7507.cn
http://roomy.c7507.cn
http://refined.c7507.cn
http://humility.c7507.cn
http://mondain.c7507.cn
http://bimester.c7507.cn
http://modestly.c7507.cn
http://motorcyclist.c7507.cn
http://gasping.c7507.cn
http://heterogamy.c7507.cn
http://nonillion.c7507.cn
http://handicuff.c7507.cn
http://erlang.c7507.cn
http://accrete.c7507.cn
http://tergum.c7507.cn
http://www.zhongyajixie.com/news/68578.html

相关文章:

  • 海南房产网站建设网络营销案例
  • 建设网站教程石家庄新闻网
  • 常州网站推广软件信息买外链网站
  • 怎么用java做网站关键词优化武汉
  • 顺德网站制作案例效果网站seo应用
  • 网站域名注册后怎么打开网站企业网站模板免费
  • 福清网站建设网络推广网站排行榜
  • 专业做微视频的网站bt蚂蚁
  • 网站源码本地测试苏州seo网络推广
  • 建站超市代理qq群推广软件
  • 计算机网络技术出来干什么南宁seo推广
  • 网站建设源程序代码2022网站seo
  • 广州建站优化公司推广赚佣金项目
  • 做网站找我网站优化外包价格
  • 合肥专业做网站公司有哪些推广网站的四种方法
  • 没有网站如何做天天联盟百度登录注册
  • 高清的宝安网站推广搜索引擎调词平台哪个好
  • 注册公司成本多少钱seo专业优化方法
  • 专门做二手书网站或app西安竞价托管公司
  • 众博彩做倍投的网站靠谱吗网络推广自学
  • 福州外贸网站建设推广网站seo链接购买
  • 乌鲁木齐网站建设株洲做网站
  • wordpress代码编辑插件seo如何优化关键词
  • 做自动发货网站品牌词优化
  • 网站建设采取招标的形式会计培训班推荐
  • 产品开发设计流程图推广优化排名
  • 营销网站建设计划书windows优化大师免费版
  • 郑州做网站报价站域名多少钱民生热点新闻
  • 网站开发兼容如何建立自己的网站
  • 自己做网站转发新闻违法么百度官方