如何通过wasm-pack将rust wasm应用程序与libpq链接 ?

问题描述 投票:0回答:1

我正在尝试使用WASM数据库层创建NodeJS应用程序。我使用Rust,Diesel作为数据库驱动程序,并使用wasm-pack作为Web Assembly编译器。

但是,当我尝试使用wasm-pack构建服务时,尝试链接libpq库失败。设置了PQ_LIB_DIR环境变量,并且diesel-cli正常工作。但是,当我尝试编译我的服务时,它失败并显示以下错误:

error: linking with `rust-lld` failed: exit code: 1
  = note: rust-lld: error: unable to find library -llibpq

我该如何解决?

我的系统:

  • OS:Windows 10
  • Rust:1.38.0
  • wasm-pack:0.8.1
  • 柴油:1.4.0
  • PostgreSQL:12
rust webassembly rust-diesel wasm-bindgen wasm-pack
1个回答
0
投票

libpq在postgreSQL安装二进制文件中可用

例如,PosgreSQL Binary Download Site如果打开zip发行版postgresql-12.0-1-windows-x64-binaries.zip,则可以看到

pgsql \ lib \ libpq.dll和pgsql \ lib \ libpq.lib

您需要指定LD_LIBRARY_PATH,或者可以在编译器参数中指定-L来告知将自动选择那些文件的文件夹路径

如果使用过安装程序,则安装文件夹中应该有相同的文件

您也可以参考此stackoverflow链接How to I tell Rust where to look for a static library?

© www.soinside.com 2019 - 2024. All rights reserved.