编译C++;使用CPP插件在gradle中编写代码 我正在研究我在试图编译C++代码时的GoeLcript脚本,我的结构如下:我正在尝试在下面的机器上编译我的代码,它显示C++编译器失败了,而我没有得到Maven的一个问题,SMOMEL/P> └───src └───main ├───c++ │ ├───headers (headres is having **.h files) │ └───native (native contains **.cpp files) └───resources └───DSresources └───DSLib apply plugin: 'cpp' //-- set the group for publishing group = 'com.rohit.singh' /** * Initializing GAVC settings */ def buildProperties = new Properties() file("version.properties").withInputStream { stream -> buildProperties.load(stream) } //add the jenkins build version to the version def env = System.getenv() if (env["BUILD_NUMBER"]) buildProperties.engineBuildVersion += "_${env["BUILD_NUMBER"]}" version = buildProperties.engineBuildVersion println "${version}" //name is set in the settings.gradle file group = "com.rohit.singh" version = buildProperties.engineBuildVersion println "Building ${project.group}:${project.name}:${project.version}" model { components { main(NativeExecutableSpec) { targetPlatform "x86" targetPlatform "x64" sources { cpp { source { srcDir "src/main/c++/native" } } } } } }

编译C++;使用CPP插件在gradle中编写代码 我正在研究我在试图编译C++代码时的GoeLcript脚本,我的结构如下:我正在尝试在下面的机器上编译我的代码,它显示C++编译器失败了,而我没有得到Maven的一个问题,SMOMEL/P> └───src └───main ├───c++ │ ├───headers (headres is having **.h files) │ └───native (native contains **.cpp files) └───resources └───DSresources └───DSLib apply plugin: 'cpp' //-- set the group for publishing group = 'com.rohit.singh' /** * Initializing GAVC settings */ def buildProperties = new Properties() file("version.properties").withInputStream { stream -> buildProperties.load(stream) } //add the jenkins build version to the version def env = System.getenv() if (env["BUILD_NUMBER"]) buildProperties.engineBuildVersion += "_${env["BUILD_NUMBER"]}" version = buildProperties.engineBuildVersion println "${version}" //name is set in the settings.gradle file group = "com.rohit.singh" version = buildProperties.engineBuildVersion println "Building ${project.group}:${project.name}:${project.version}" model { components { main(NativeExecutableSpec) { targetPlatform "x86" targetPlatform "x64" sources { cpp { source { srcDir "src/main/c++/native" } } } } } },c++,gradle,build.gradle,gradlew,C++,Gradle,Build.gradle,Gradlew,Linux 2.6.32-431.el6.x86#u 64#1 SMP Sun 11月10日22:19:54 EST 2013 x86_64 x86_64 x86_64 GNU/Linux └───src └───main ├───c++ │ ├───headers (headres is having **.h files) │ └───native (native contains **.cpp files)

Linux 2.6.32-431.el6.x86#u 64#1 SMP Sun 11月10日22:19:54 EST 2013 x86_64 x86_64 x86_64 GNU/Linux

└───src
    └───main
        ├───c++
        │   ├───headers   (headres is having **.h files)
        │   └───native    (native contains  **.cpp files)
        └───resources
            └───DSresources
                └───DSLib

apply plugin: 'cpp'
//-- set the group for publishing
group = 'com.rohit.singh'
/**
 * Initializing GAVC settings
 */
def buildProperties = new Properties()
file("version.properties").withInputStream { 
    stream -> buildProperties.load(stream) 
} 
//add the jenkins build version to the version
def env = System.getenv()
if (env["BUILD_NUMBER"]) buildProperties.engineBuildVersion += "_${env["BUILD_NUMBER"]}"
version = buildProperties.engineBuildVersion
println "${version}"

//name is set in the settings.gradle file
group = "com.rohit.singh"
version = buildProperties.engineBuildVersion
println "Building ${project.group}:${project.name}:${project.version}"

model {
  components {
    main(NativeExecutableSpec) {
      targetPlatform "x86"
      targetPlatform "x64"
      sources {
        cpp {
          source {
            srcDir "src/main/c++/native"
          }
        }
      }
    }
  }
}
下面是maven代码片段

└───src
    └───main
        ├───c++
        │   ├───headers   (headres is having **.h files)
        │   └───native    (native contains  **.cpp files)
        └───resources
            └───DSresources
                └───DSLib

apply plugin: 'cpp'
//-- set the group for publishing
group = 'com.rohit.singh'
/**
 * Initializing GAVC settings
 */
def buildProperties = new Properties()
file("version.properties").withInputStream { 
    stream -> buildProperties.load(stream) 
} 
//add the jenkins build version to the version
def env = System.getenv()
if (env["BUILD_NUMBER"]) buildProperties.engineBuildVersion += "_${env["BUILD_NUMBER"]}"
version = buildProperties.engineBuildVersion
println "${version}"

//name is set in the settings.gradle file
group = "com.rohit.singh"
version = buildProperties.engineBuildVersion
println "Building ${project.group}:${project.name}:${project.version}"

model {
  components {
    main(NativeExecutableSpec) {
      targetPlatform "x86"
      targetPlatform "x64"
      sources {
        cpp {
          source {
            srcDir "src/main/c++/native"
          }
        }
      }
    }
  }
}
profile>
            <id>Linux</id>
            <activation>
                <os>
                    <family>Linux</family>
                </os>
            </activation>
            <properties>
                <packaging.type>so</packaging.type>
            </properties>
            <build>
                <plugins>
                    <plugin>
                        <groupId>org.codehaus.mojo</groupId>
                        <artifactId>native-maven-plugin</artifactId>
                        <version>1.0-alpha-8</version>
                        <extensions>true</extensions>
                        <configuration>

                            <javahOS>linux</javahOS>

                            <compilerProvider>generic-classic</compilerProvider>
                            <compilerExecutable>g++</compilerExecutable>
                            <linkerExecutable>g++</linkerExecutable>
                            <sources>
                                <source>
                                    <directory>NativeJNI/../src/main/c++/native</directory>
                                    <fileNames>
                                        <fileName>JniSupport.cpp</fileName>
                                        <fileName>DiseaseStagingJni.cpp</fileName>
                                    </fileNames>
                                </source>
                            </sources>
                            <compilerStartOptions>
                                <compilerStartOption>-fPIC</compilerStartOption>
                            </compilerStartOptions>
                            <linkerFinalName>NativeJNI</linkerFinalName>
                            <linkerStartOptions>
                                <linkerStartOption>-shared -L${basedir}/src/main/resources/DSresources/DSLib -lds64 -Wl,-rpath,${basedir}/src/main/resources/DSresources/DSLib</linkerStartOption>
                            </linkerStartOptions>

                        </configuration>
                        <executions>
                            <execution>
                                <id>javah</id>
                                <phase>generate-sources</phase>
                                <configuration>
                                    <finalName>LinuxNativeJNI</finalName>
                                    <javahOS>linux</javahOS>
                                    <javahProvider>default</javahProvider>
                                    <javahOutputDirectory>${project.build.directory}/custom-javah</javahOutputDirectory>
                                    <workingDirectory>${basedir}</workingDirectory>
                                    <javahOutputFileName>DiseaseStagingJniWrapper.h</javahOutputFileName>
                                    <javahClassNames>
                                        <javahClassName>com.truvenwealth.analyticsengine.common.diseasestaging.DiseaseStagingJniWrapper</javahClassName>
                                    </javahClassNames>
                                </configuration>
                                <goals>
                                    <goal>javah</goal>
                                </goals>
                            </execution>
                        </executions>
                    </plugin>
                    <plugin>
profile>
Linux
Linux
所以
org.codehaus.mojo
原生maven插件
1.0-α-8
真的
linux
通用经典
g++
g++
NativeJNI/./src/main/c++/native
JniSupport.cpp
疾病分期jni.cpp
-fPIC
土生土长
-shared-L${basedir}/src/main/resources/DSresources/DSLib-lds64-Wl,-rpath,${basedir}/src/main/resources/DSresources/DSLib
爪哇
生成源
LinuxNativeJNI
linux
违约
${project.build.directory}/customjavah
${basedir}
疾病分期JNIWRAPPER.h
com.truvenwealth.analyticsengine.common.diseasetaging.diseasetagingjniwrapper
爪哇

我以下面的方式使用Javah函数

└───src
    └───main
        ├───c++
        │   ├───headers   (headres is having **.h files)
        │   └───native    (native contains  **.cpp files)
        └───resources
            └───DSresources
                └───DSLib

apply plugin: 'cpp'
//-- set the group for publishing
group = 'com.rohit.singh'
/**
 * Initializing GAVC settings
 */
def buildProperties = new Properties()
file("version.properties").withInputStream { 
    stream -> buildProperties.load(stream) 
} 
//add the jenkins build version to the version
def env = System.getenv()
if (env["BUILD_NUMBER"]) buildProperties.engineBuildVersion += "_${env["BUILD_NUMBER"]}"
version = buildProperties.engineBuildVersion
println "${version}"

//name is set in the settings.gradle file
group = "com.rohit.singh"
version = buildProperties.engineBuildVersion
println "Building ${project.group}:${project.name}:${project.version}"

model {
  components {
    main(NativeExecutableSpec) {
      targetPlatform "x86"
      targetPlatform "x64"
      sources {
        cpp {
          source {
            srcDir "src/main/c++/native"
          }
        }
      }
    }
  }
}
apply plugin: 'cpp'
apply plugin: 'java'
//-- set the group for publishing
group = 'com.rohit.singh'

/**
 * Initializing GAVC settings
 */
def buildProperties = new Properties()
file("version.properties").withInputStream {
        stream -> buildProperties.load(stream)
}
//add the jenkins build version to the version
def env = System.getenv()
if (env["BUILD_NUMBER"]) buildProperties.ncdefBuildVersion += "_${env["BUILD_NUMBER"]}"
version = buildProperties.anal
println "${version}"

//name is set in the settings.gradle file
group = "com.rohit.singh"
version = buildProperties.anal
println "Building ${project.group}:${project.name}:${project.version}"

repositories {
    maven {
      url "http://xxx.tsh.xxon.com:x/factory/libslocal"
    }
     maven {
      url "http://xxx.tsh.xxon.com:x/factory/libs-release"
    }
}
    dependencies {
   compile ([
    "com.rohit.singh:engine-common:4.+"
      ])
}



model {
  repositories {
    libs(PrebuiltLibraries) {
      jdk {
        headers.srcDirs "${System.properties['java.home']}/../include",
        "${System.properties['java.home']}/../include/win32",
        "${System.properties['java.home']}/../include/darwin",
        "${System.properties['java.home']}/../include/linux"
      }
    }
  }
}

model {
  platforms {
    x64 { architecture "x86_64" }
    x86 { architecture "x86" }
  }
}

model {
  components {
    main(NativeLibrarySpec) {
      sources {
        cpp {
          source {
            lib library: 'main', linkage: 'static'
            lib library: 'jdk', linkage: 'api'
            srcDir "src/main/c++/native"
            include "**/JniSupport.cpp"
            include "**/DiseaseStagingJni.cpp"
          }
        }
      }
    }
  }
}

def nativeHeadersDir = file("$buildDir/nativeHeaders")
//def compilePath = configurations.compile.resolve().collect {it.absolutePath}.join(";")
binaries.all {
    // Define toolchain-specific compiler and linker options
    if (toolChain in Gcc) {
        cppCompiler.args "-I${nativeHeadersDir}"
        cppCompiler.args "-g"
        linker.args '-Xlinker', '-shared -LNativeJNI/src/main/resources/DSresources/DSLib -lds64 -Wl'
}
}

**//def nativeHeadersDir = file("$buildDir/nativeHeaders")
task nativeHeaders {
    // def nativeHeadersDir = file("$buildDir/nativeHeaders")
     def outputFile = file("$nativeHeadersDir/DiseaseStagingJniWrapper.h")
     def classes = [
             'com.abcedefgh.nice.common.diseasestaging.DiseaseStagingJniWrapper'
                  ]
     inputs.files sourceSets.main.output
     inputs.property('classes', classes)
     outputs.file outputFile
     doLast {
         outputFile.parentFile.mkdirs()
         def compilePath = configurations.compile.resolve().collect {it.absolutePath}.join(":")
         println "Using Compile Path: ${compilePath}"
         exec {
             executable org.gradle.internal.jvm.Jvm.current().getExecutable('javah')
             args '-o', outputFile
             args '-classpath', compilePath
             args classes
         }
     }
 }

             tasks.withType(CppCompile) { task ->
                 task.dependsOn nativeHeaders
             }**
//def filechange = file("NativeJNI-${project.version}.so")
//println filechange
task fixartifactname (type: Copy) {
       //def filechange = "NativeJNI-${project.version}.so"
       //println filechange
       from 'build/binaries/mainSharedLibrary'
       into 'build/libs'
def filechange = file("NativeJNI-${project.version}.so")
println filechange
include('libmain.so')
rename ('libmain.so', '${filechange}')
}
//println fixartifactname
build.dependsOn fixartifactname

正如我所说的,错误是说C++编译器失败了。我粘贴了我的POM文件片段,就像我的问题一样。你的<代码> SRCIDR < /C>不包括<代码>标题>代码>目录。您能否检查添加
srcDir“src/main/c++/headers”
是否可以解决您的问题,您能否使用--info标志运行gradle以获得更详细的输出,这可能有助于理解编译失败?我在build.gradle脚本中添加了它,并获得了以下错误,但我不明白它为什么会出现此错误。我的linux系统有gcc编译器。其中是gcc:/usr/bin/gcc/usr/lib/gcc/usr/libexec/gcc/usr/share/man/man1/gcc.1.gz。任务的执行失败:compileMainExecutableMainCpp'>没有可用于为平台“linux_x86-64”生成的工具链:工具链“gcc”(GNU gcc):-找不到C编译器“gcc”。在:/usr/bin/gccI中搜索到,如果我在build.gradle脚本中对gcc路径进行了注释,那么它会抛出一些不同的错误。它正在尝试运行以下任务:compilemainecutablemaincpp并尝试执行此/applications/jenkins/workspace/NativeJNI/NativeJNI/src/main/c++/native/ds64.lib:2:错误:程序中的“杂散”并说C++编译器失败