我正在使用Rust,bindgen和build script来开发与库的FFI绑定相关的项目。
该库使用OpenMP构建,因此在链接时,我通常会向编译器传递-fopenmp
标志。
如何在使用Cargo构建库时,通过build.rs
设置该标志?
当前,使用Cargo构建失败,失败命令类似于:
cc -Wl,--as-needed -Wl,-z,noexecstack -m64 -l gomp -l stdc++
...skipping dozens of paths/files...
-Wl,-Bdynamic -l dl -l rt -l pthread -l gcc_s -l c -l m -l rt -l pthread -l util
这段代码出现了数百个 undefined reference to 'GOMP_parallel_end'
错误。
手动添加 -fopenmp
标志并重新运行上述生成的命令可以成功。
我可以在编译之前使用 RUSTFLAGS='-C link-args=-fopenmp'
指定标志,但是否有一种方法可以在 build.rs
中指定它?
rustc-flags
是毫无意义的。 - Stargateuropenmp-sys
。 - Stargateurrustc-flags
根本不是我想要的,我只是在寻找一种在构建期间调用cc
命令时添加标志的方法。不过我会研究一下openmp-sys
,之前并不知道,谢谢。 - Dave Challiscc.flag(&env::var("DEP_OPENMP_FLAG").unwrap());
。 - Stargateur