Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

启用Win32编译 #16

Merged
merged 1 commit into from
Apr 13, 2016
Merged

启用Win32编译 #16

merged 1 commit into from
Apr 13, 2016

Conversation

acgrid
Copy link
Contributor

@acgrid acgrid commented Apr 13, 2016

环境:VS2015 Community
目标:PHP 7.0.2 源码忘记更新了,不过对API影响甚微

Build type Release
Thread Safety No
Compiler MSVC14 (Visual C++ 2015)
Architecture x64
Optimization PGO disabled
Static analyzer disabled
  1. 创建PHP的Windows编译环境,编译官方源码PHP通过后进入下一步。
    参考: https://wiki.php.net/internals/windows/stepbystepbuild
    没有VC14目录自己仿照现有的创建。
  2. 将本扩展的git仓库clone到对应版本的pecl目录下,如D:\Local\php-sdk\phpdev\vc14\x64\pecl\opencc4php。
  3. 下载OpenCC Win32/64(与目标对应)官方二进制包或者自己编译(我没编译出来)
    https://bintray.com/byvoid/opencc/OpenCC/1.0.1/view
    解压到某个位置,如D:\Local\opencc-1.0.1-win64。
  4. 打开VS2015 (x64) 本机工具命令提示符,如果目标是x64一定要选x64的命令行
    进入D:\Local\php-sdk,运行一次bin\phpsdk_setvars.bat设置变量
  5. 进入php编译目录,如D:\Local\php-sdk\phpdev\vc14\x64\php-7.0.2-src,运行buildconf生成configure.js,通过configure --help确认opencc是否加入编译选项。
  6. 由于大部分情况下需要的是DLL,使用configure --disable-all --disable-zts --enable-cli --with-opencc=shared,D:\Local\opencc-1.0.1-win64做最小编译,请根据ZTS、Debug/Release与否调整相应参数,--with-opencc中的shared表示编译为共享DLL模块,否则将被编入php.dll,OpenCC目录务必填写正确。
  7. 配置无误,即配置总结信息中出现opencc:shared/static后,运行nmake开始编译。
  8. 根据平台、ZTS、是否调试版本,在某个输出目录中会出现php_opencc.dll,不再列举了。复制到php的ext目录、添加php.ini亦不再赘述。
  9. 由于php_opencc.dll本身不连接OpenCC,需要把OpenCC目录下的opencc.dll复制到php根目录(不是ext,和php.exe在一起),和其他DLL一个原理。
  10. 通过php -m检查是否正确加载扩展
  11. 在Win下使用扩展,必须使用绝对路径加载JSON配置,如D:\Local\opencc-1.0.1-win64\t2s.json

That's all. 如果目标和我一致可以拿走无责任成品:
https://drive.google.com/open?id=0B-cvAlivZFgkM1A4aktKTklMMXM

@nauxliu nauxliu merged commit c1a023b into nauxliu:master Apr 13, 2016
@lucifer-v
Copy link

请问,我在编译的时候出现了 opencc.h(66):error C2054 在"OPENCC_EXPORT"之后应该输入"(" 之类的错误。这个应该怎么解决呢?

@acgrid
Copy link
Contributor Author

acgrid commented Feb 28, 2018

https://github.com/BYVoid/OpenCC/blob/ver.1.0.4/src/opencc.h
使用新版本的opencc.h,应该能通过VS15编译

@henryanna
Copy link

您好,编译不成,使用无责任成品提示提示错误乱码为 ext\php_opencc.dll' - %1 ������Ч�� Win32 Ӧ�ó���,希望您能帮忙,是我加载错误还是缺少了什么。请Email联系,2000411(#)163.com,十分感谢!!!

@zhangkg
Copy link

zhangkg commented Aug 20, 2018

PHP Warning: PHP Startup: Unable to load dynamic library 'D:\phpStudy2018\PHPTutorial\php\php-7.1.13-nts\ext\php_opencc.dll' - %1 不是有效的 Win32 应用程序。
in Unknown on line 0

@acgrid
Copy link
Contributor Author

acgrid commented Aug 23, 2018

之前那个dll是7.0的,肯定不能用在7.1上面,另外32/64也必须一样才行。7.2没记错的话是编译成功了,不过7.2的win32工具链又改了上面写的不完全适用😭。

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

Successfully merging this pull request may close these issues.

None yet

5 participants