windows下使用mingw和cmake编译quickjs

  1. 下载代码, 注意用命令行
    git clone --recurse-submodules https://github.com/blakeyi/quickjs-cmake-mingw

  2. 检查mingw和cmake版本

cmake直接去百度下载即可

cmake -version
cmake version 3.31.0-rc3

CMake suite maintained and supported by Kitware (kitware.com/cmake).

mingw没有的话, 因为下载起来比较麻烦, 而且sourceforge上在比较新的版本后不再提供二进制版本,只有源码版本, 可以考虑在github上下载编译好的
release,参考这个地址 `https://github.com/niXman/mingw-builds-binaries/releases/tag/8.5.0-rt_v10-rev0`, 解压后注意配置环境变量

```shell
gcc -v
Using built-in specs.
COLLECT_GCC=C:\Program Files (x86)\mingw64\bin\gcc.exe
COLLECT_LTO_WRAPPER=C:/Program\ Files\ (x86)/mingw64/bin/../libexec/gcc/x86_64-w64-mingw32/8.5.0/lto-wrapper.exe
Target: x86_64-w64-mingw32

Thread model: win32
gcc version 8.5.0 (x86_64-win32-seh-rev0, Built by MinGW-W64 project)

  1. 编译执行
    注意这里指定使用mingw,不然会默认使用mvsc
mkdir build
cd build
cmake -G "MinGW Makefiles" -DCMAKE_C_COMPILER=gcc -DCMAKE_CXX_COMPILER=g++ ..
make

这里正常libqjs.a和qjsc.exe都能编译成功, 但是qjs-app.exe一般会编译失败,错误可能是如下, 原因是少了两个源文件repl.c和qjscalc.c, 这两个文件需要使用qjsc.exe进行编译得到, 先把对应js
文件中的"use strip";注释掉, 然后执行
.\qjsc.exe -c .\repl.js -o repl.c.\qjsc.exe -c .\qjscalc.js -o qjscalc.c, 注意生成后的文件, 需要进行二次修改,把c文件中对应的变量名字里多余的下划线去除, 保留一个就行,比如
qjsc___repl_size 改成 qjsc_repl_size , 修完完后的文件需要放到quickjs源码目录, 然后把CMakeLists里注释掉的repl.c和qjscalc.c取消

[100%] Linking C executable qjs-app.exe
C:/PROGRA~2/mingw64/bin/…/lib/gcc/x86_64-w64-mingw32/8.5.0/…/…/…/…/x86_64-w64-mingw32/bin/ld.exe: CMakeFiles\qjs-app.dir/objects.a(qjs.c.obj):qjs.c:(.rdataKaTeX parse error: Undefined control sequence: \qjs at position 192: …exe: CMakeFiles\̲q̲j̲s̲-app.dir/object….refptr.qjsc_repl_size[.refptr.qjsc_repl_size]+0x0): undefined reference to qjsc_repl_size' C:/PROGRA~2/mingw64/bin/../lib/gcc/x86_64-w64-mingw32/8.5.0/../../../../x86_64-w64-mingw32/bin/ld.exe: CMakeFiles\qjs-app.dir/objects.a(qjs.c.obj):qjs.c:(.rdata$.refptr.qjsc_qjscalc[.refptr.qjsc_qjscalc]+0x0): undefined reference to qjsc_qjscalc’
C:/PROGRA~2/mingw64/bin/…/lib/gcc/x86_64-w64-mingw32/8.5.0/…/…/…/…/x86_64-w64-mingw32/bin/ld.exe: CMakeFiles\qjs-app.dir/objects.a(qjs.c.obj):qjs.c:(.rdata$.refptr.qjsc_qjscalc_size[.refptr.qjsc_qjscalc_size]+0x0): undefined reference to `qjsc_qjscalc_size’
collect2.exe: error: ld returned 1 exit status
make[2]: *** [CMakeFiles\qjs-app.dir\build.make:134: qjs-app.exe] Error 1
make[1]: *** [CMakeFiles\Makefile2:154: CMakeFiles/qjs-app.dir/all] Error 2
make: *** [Makefile:90: all] Error


参考文档:
- https://github.com/septbr/quickjs-cmake-mingw
- https://blog.csdn.net/weixin_50674989/article/details/136763247


Building wheel for quickjs (setup.py) ... error error: subprocess-exited-with-error × python setup.py bdist_wheel did not run successfully. │ exit code: 1 ╰─> [12 lines of output] running bdist_wheel running build running build_py creating build\lib.win-amd64-cpython-313\quickjs copying quickjs\__init__.py -> build\lib.win-amd64-cpython-313\quickjs running build_ext building '_quickjs' extension creating build\temp.win-amd64-cpython-313\Release creating build\temp.win-amd64-cpython-313\Release\upstream-quickjs "D:\Visual Studio\Visual Studio 2022\Community\VC\Tools\MSVC\14.43.34808\bin\HostX86\x64\cl.exe" /c /nologo /O2 /W3 /GL /DNDEBUG /MD -DCONFIG_VERSION=\"2021-03-27\" -DCONFIG_BIGNUM -IE:\Python3\include -IE:\Python3\Include "-ID:\Visual Studio\Visual Studio 2022\Community\VC\Tools\MSVC\14.43.34808\include" "-ID:\Visual Studio\Visual Studio 2022\Community\VC\Tools\MSVC\14.43.34808\ATLMFC\include" "-ID:\Visual Studio\Visual Studio 2022\Community\VC\Auxiliary\VS\include" "-ID:\Windows Kits\10\include\10.0.22621.0\ucrt" "-ID:\Windows Kits\10\\include\10.0.22621.0\\um" "-ID:\Windows Kits\10\\include\10.0.22621.0\\shared" "-ID:\Windows Kits\10\\include\10.0.22621.0\\winrt" "-ID:\Windows Kits\10\\include\10.0.22621.0\\cppwinrt" /Tcmodule.c /Fobuild\temp.win-amd64-cpython-313\Release\module.obj -Werror=incompatible-pointer-types cl: 命令行 error D8021 :无效的数值参数“/Werror=incompatible-pointer-types” error: command 'D:\\Visual Studio\\Visual Studio 2022\\Community\\VC\\Tools\\MSVC\\14.43.34808\\bin\\HostX86\\x64\\cl.exe' failed with exit code 2 [end of output] note: This error originates from a subprocess, and is likely not a problem with pip. ERROR: Failed building wheel for quickjs Running setup.py clean for quickjs Failed to build quickjs ERROR: Failed to build installable wheels for some pyproject.toml based projects (quickjs) PS C:\Users\ASUS> pip install pyquickjs ERROR: Could n
03-23
评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

当前余额3.43前往充值 >
需支付:10.00
成就一亿技术人!
领取后你会自动成为博主和红包主的粉丝 规则
hope_wisdom
发出的红包
实付
使用余额支付
点击重新获取
扫码支付
钱包余额 0

抵扣说明:

1.余额是钱包充值的虚拟货币,按照1:1的比例进行支付金额的抵扣。
2.余额无法直接购买下载,可以购买VIP、付费专栏及课程。

余额充值