Add directory to PATH before command line build is executed

My gradle build for a native shared library looks like this at the moment:

apply plugin: 'c'
apply plugin: 'visual-studio'
  model {
  components {
         main(NativeLibrarySpec) {
      sources.c {
        source {
          srcDirs "src/main/c"
          include "**/*.c"
        }
        exportedHeaders {
          srcDirs "src/main/headers"
        }
      }
    }
  }
}

How can I add folder that contains .h and .lib files, which I depend on, so that they are found while compiling / linking? The folder I want to add is stored in LIB_NAME env variable.

i tried addig this:

toolChains {
  visualCpp(VisualCpp) {
    eachPlatform {
      cCompiler.withArguments{ args ->
        ["/I", System.env.LIB_NAME].addAll(args)
      }
    }
  }
 }

Can I enable a debug output that tells me how cl.exe was actually called? --debug gives me only ENV varibales.

I think --info/-i will tell you the command line arguments. For MSVC, this probably isn’t very useful. You can also look in build/tmp//options.txt to see the full list of arguments.

I think the way you can do this currently is to use a PrebuiltLibrary. Here’s an example.

Basically, you want to define a meaningful name and tell Gradle where to find the headers and libraries. Then in your component you add that library as a dependency. We take care of adding the header include paths during compilation and libraries during link.

I tried to adopt the example, but I couldn’t really get it to work. I’m getting this error:

A problem occurred configuring project ‘:native’. > Exception thrown while executing model rule: model.components

Cannot create a ComponentSpec named ‘dokan’ because this container does not

support creating elements by name alone. Please specify which subtype of Compon entSpec to create. Known subtypes are: NativeExecutableSpec, NativeLibrarySpec

You can access the project on github: https://github.com/sherter/jmount What is wrong?

A couple of things…

Try to keep your component names as valid Java identifiers or enclose them in quotes. I think your “dokan-jni” is being interpreted as dokan (minus) jni and it confuses the compiler.

Inside the prebuilt lib components, you have to select the binaries by type (shared object or static library) because it can have both. So inside ‘dokan {}’ you need a ‘binaries.withType(StaticLibraryBinary) {}’ around staticLibraryFile. That’s similar to what the util library has in the example.

I got it working, thank you very much for your help!

As a suggestion: The documentation on that could be improved :wink:

PRs are welcome. :slight_smile: I think our documentation will get better as we get more of the native support out of @Incubating. I’m glad you got it working.