其他包含路径和链接器选项Gradle for C ++ [英] Additional include paths and linker options Gradle for C++
问题描述
我试图使用Gradle编译C ++项目,但找不到找到在编译时声明我想要的其他包含路径以及在链接时声明哪些其他库的方法.我已经在项目中看到涉及 model {}
的解决方案(我不记得了).(但是没有用,Gradle一直抱怨不存在的功能.)
I was trying to use Gradle to compile a C++ project, but I can't find the way of declaring what additional include paths I want at compile time, and what additional libraries at link time.
I've seen solutions involving model { }
inside project (I don't remember exactly). (But didn't work, Gradle complains all the time about non existing function.)
似乎也不是将Conan依赖项添加到Gradle项目中的明确或简单的方法.剩下的工作就是我自己编译库,然后再添加到构建系统中,但是同样,我找不到路.
Also does not seem to be a clear or simple way to add Conan dependencies to a Gradle project yet. That leaves me compiling libraries on my own and then adding to the build system, but again, I can't find the way.
我一直在寻找答案的文档,但是我发现的只是添加Maven依赖项(但是我想GLFW,GLEW和DearIMGUI不在Maven上.)
I've been looking in the docs for the answer, but all I find is about adding maven dependencies (But GLFW, GLEW and DearIMGUI aren't on Maven I guess...).
有什么古怪吗?我怎么可能只注册其他包含/链接文件?
Any quirk? How Can I possibly just register additional includes/link files?
我的 build.gradle.kts
:
plugins {
id("cpp-application")
}
tasks.register("runDebug") {
doLast {
exec {
executable = "./build/exe/main/debug/my-app.exe"
}
}
}
推荐答案
经过5个小时的搜索,我终于找到了使用Gradle构建QT应用程序的解决方案.感谢@ s-kadakov.
After 5 hours of searching, I finally found a solution to build QT application with Gradle. Thanks to @s-kadakov.
plugins {
id 'cpp-application'
id 'cpp-unit-test'
}
application {
targetMachines.add(machines.linux.x86_64)
}
tasks.withType(CppCompile).configureEach {
compilerArgs.add '-fPIC'
includes {
'/usr/include/qt'
}
compilerArgs.addAll toolChain.map { toolChain ->
if (toolChain in [ Gcc, Clang ]) {
return ['-O2', '-fno-access-control']
} else if (toolChain in VisualCpp) {
return ['/Zi']
}
return []
}
}
tasks.withType(LinkExecutable).configureEach {
linkerArgs.add '-v'
linkerArgs.add '-lQt5Core'
linkerArgs.add '-lQt5Widgets'
linkerArgs.add '-lQt5Gui'
}
希望这对您有所帮助.
这篇关于其他包含路径和链接器选项Gradle for C ++的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!