我在vcpkg旁边安装了Visual Studio 2019。我已经安装了一个外部依赖项(使用的msmpi vcpkg install msmpi:x86-windows
),并尝试使用Visual Studio IDE创建示例MPI项目:一切正常,不需要任何其他配置,令人印象深刻。
现在-由于我正在从事的项目的性质,我想使用gradle编译我的代码(在Visual Studio外部)。为此,我使用了Gradle的cpp-application插件以及以下build.gradle:
plugins {
id 'cpp-application'
}
简单的“ Hello world”的编译有效:gradle找到Visual C ++编译器,执行该编译器,一切正常运行(顺便说一句,我也印象深刻)。
当我将外部库(mpi.h
)中的标头包含在代码中时,就会出现问题。当使用gradle和cpp-application插件进行编译时,似乎看不到通过vcpkg预先安装的依赖项(当我使用Visual Studio IDE编译代码时,不需要任何其他配置即可进行的所有工作)。如何解决该问题,最好在没有对我进行硬编码的库和标头的情况下解决build.gradle
?
通过向其提供vcpgk安装的mpi标头和库的路径,我能够获得编译我的项目的机会。我将寻找一种使其更灵活的方法。不过,这是我对build.gradle
以下内容的补充:
ext {
vcpgkIncludePath = 'path-to-include'
vcpkgLibPath = 'path-to-vcpkg-libs'
}
tasks.withType(CppCompile).configureEach {
compilerArgs.addAll toolChain.map { toolChain ->
if (toolChain in VisualCpp) {
return ["/I$vcpgkIncludePath"]
}
return []
}
}
tasks.withType(org.gradle.nativeplatform.tasks.LinkExecutable).configureEach {
linkerArgs.addAll toolChain.map { toolChain ->
if (toolChain in VisualCpp) {
return ["/LIBPATH:$vcpkgLibPath", "msmpi.lib"]
}
return []
}
}
本文收集自互联网,转载请注明来源。
如有侵权,请联系 [email protected] 删除。
我来说两句