Gradle:尝试构建* .so不会产生任何结果

时间:2018-05-14 18:40:47

标签: gradle build.gradle

我是Gradle的新手,特别是关于C / C ++构建。我正在尝试将SCons翻译成Gradle。我有目录common / src,其中包含所有* .cc和* .h文件。 build.gradle包含以下内容:

apply plugin: 'c'
apply plugin: 'cpp'
apply from: './gradle.properties'
model {
    components {
        common(NativeLibrarySpec)
     }

     binaries {
         withType(SharedLibraryBinarySpec) {
            if (targetPlatform.operatingSystem.windows) {
                cppCompiler.args '/MT', '/ZI'
            }

            if (targetPlatform.operatingSystem.linux) {
                cppCompiler.args '-c', '-g', '-fPIC'
                linker.args '-pthread'
            }
        }
    }
}

我正在尝试构建.so,但什么也没有产生,甚至没有错误。

./gradlew commonSharedLibrary

Deprecated Gradle features were used in this build, making it incompatible with Gradle 5.0.
See https://docs.gradle.org/4.7/userguide/command_line_interface.html#sec:command_line_warnings

BUILD SUCCESSFUL in 0s

我错过了什么? 我在哪里可以找到一些C / C ++文档和示例?

$ ../gradlew -version
------------------------------------------------------------
Gradle 4.7
------------------------------------------------------------
Build time:   2018-04-18 09:09:12 UTC
Revision:     b9a962bf70638332300e7f810689cb2febbd4a6c

Groovy:       2.4.12
Ant:          Apache Ant(TM) version 1.9.9 compiled on February 2 2017
JVM:          1.8.0_151 (Oracle Corporation 25.151-b12)
OS:           Linux 3.10.0-514.el7.x86_64 amd64

1 个答案:

答案 0 :(得分:0)

我不认为您确实宣布了Gradle脚本将构建的来源

components {}范围内,您基本上说您正在构建一个名为Common的库...这基本上会生成commonSharedLibrary任务(实际上并没有做任何事情)

如果您调用了组件tada(NativeLibrarySpec),则会生成相应的tadaSharedLibrary

components {}内,您需要声明正在构建的source{}

main(NativeLibrarySpec) {
        sources {
            c {
                source {
                    srcDir "src/source"   <---- replace where your source is 
                    include "**/*.c"   <------ tells it to compile all c files in dir 
                }
               exportedHeaders {   <----- include files for the project
                       srcDirs  "include"
               }

            }
        }

阅读思考Building native software的文档并查看我认为可以帮助你的示例