Gradle c++ plugin - shared library linking


I’m building a project which has 2 sub projects: 1 shared lib and 1 exe.
The exe build.gradle has the following line:
lib project: “:lib_project”, library: “lib”, linkage: "static"
Each sub project has its own build.gradle.

I’m building on Windows 7.
When I run an install task on the exe project, the library project DLL isn’t installed in the install directory.
When I tried to change linkage to “shared” the link step fails, because lib.lib is missing.

Any ideas as to what I’m doing wrong?


I’m now trying to add my own tasks to the exe project to copy the shared lib artifacts when the exe project install tassks are called.
However I can’t access any of the tasks in the native plugin.

E.g. Adding the following code to the exe build.gradle causes a build error:

task installLibrary << {
} // end of task installAplLibrary

tasks.installX64DebugExeExecutable.dependsOn installAplLibrary

I get:
“Could not find property ‘installX64DebugExeExecutable’ on task set”

Any idea on how to access tasks in the native c++ plugin?


Have you taken a look at the multi-project native sample in the Gradle distribution? The install task should be copying the shared object library if it’s needed. Sample project:

The reason you can’t access the tasks is that they are created on demand based on which variant of the library/executable is being built.

Yes I’ve taken a look at the multi project sample. I’m now changing my project to match.
However what I want is the ability to have a multi project setup, where each component has it’s build.gradle.

The current multi project setup is not scale-able in my opinion.

It’s good for a limited number of components, but it becomes messy if you have multiple libraries and multiple apps, where each client depends on a some of the libraries. You will end up with a very large build.gradle file that will hold all the data for all the projects. This will become harder and harder to maintain as the number of projects increases.

I think it would be better to have the components of a build.gradle based not just of the contents in that file, but also in any project file it depends on.

One more suggestion - add some tasks (even empty ones) that will allow hooking additional tasks that do custom build steps.

  1. Add a preBuild task that will allow code generation tasks.
  2. Add a postBuild task that will allow some custom tests, or file copies
  3. preInstall and postInstall …


I created a plugin that solves the issue in this thread see:

It add pre/post compile/link/install tasks and tasks to copy shared library dependencies to the install executable output dir.