# Gradle 3.0 - PrebuiltLibraries dependency link error

**URL:** <https://discuss.gradle.org/t/gradle-3-0-prebuiltlibraries-dependency-link-error/24834>\
**Category:** Help/Discuss\
**Created:** [November 18, 2017, 8:27pm UTC](https://discuss.gradle.org/t/gradle-3-0-prebuiltlibraries-dependency-link-error/24834 "2017-11-18T20:27:13Z")\
**Posts on this page:** 3\
**Page:** 1

<div class="post-metadata">

**Author:** ![blien](https://avatars.discourse-cdn.com/v4/letter/b/ecae2f/32.png) [@blien](https://discuss.gradle.org/u/blien)\
**Post date:** [November 18, 2017, 8:27pm UTC](https://discuss.gradle.org/t/gradle-3-0-prebuiltlibraries-dependency-link-error/24834/1 "2017-11-18T20:27:14Z")

</div>

I have a C++ project and trying to link against a library built in another project that compiles a C library with gcc.

If I build the first project “A” and use the following in “B” which uses cpp plugin I can compile and run fine. However, I fail from a clean build with parallelization, because the prebuilt library isn’t there yet.

What I would like is a mechanism that I can force A’s build to run to completion before reaching B’s linkTestExecutable that tries to link my “prebuilt” library. My issue, is the use of some C includes won’t let me compile A with the g++ compiler.

What are my options?

```
apply plugin: 'cpp'

build.dependsOn([':A:build'])
clean.dependsOn([':A:clean'])

model {
    components {
        B (NativeExecutableSpec) {
         sources {
                cpp {
                    lib library: "myA", linkage: 'static'
                } 
            }
        }
    }
}

model {
    repositories {
        libs(PrebuiltLibraries) {
            myA { 
                def baseDir = "../A/build/libs/A/static/"
                headers.srcDir "../A/src/A/headers/"

                binaries.withType(StaticLibraryBinary) {
                    staticLibraryFile = file("${baseDir}/libA.a")
                }
            }
        }
    }

    binaries {
        all {
            cppCompiler.args "-std=c++11", "-pthread","-fPIC","-ggdb", "-fext-numeric-literals"
        }
    }
```

---

<div class="post-metadata">

**Author:** ![Kevin2](https://avatars.discourse-cdn.com/v4/letter/k/bcef8e/32.png) [@Kevin2](https://discuss.gradle.org/u/Kevin2)\
**Post date:** [November 21, 2017, 5:56pm UTC](https://discuss.gradle.org/t/gradle-3-0-prebuiltlibraries-dependency-link-error/24834/2 "2017-11-21T17:56:51Z")

</div>

If project A and project B are both managed by the same Gradle build, then you should define “A” as a project dependency of “B” instead of defining “myA” as a PrebuiltLibrary. This would involve changing the `cpp {}` to:

```gradle
model {
    components {
        B (NativeExecutableSpec) {
         sources {
                cpp {
                    // Make project B depend on project A's "A" library.
                    // This assumes the component (library) you've defined in project A is named "A"
                    lib project: ':A', library: 'A', linkage: 'static'
                } 
            }
        }
    }
}

```

If project A and project B are managed by different Gradle builds, then you may want to look into Gradle’s composite builds.

---

<div class="post-metadata">

**Author:** ![blien](https://avatars.discourse-cdn.com/v4/letter/b/ecae2f/32.png) [@blien](https://discuss.gradle.org/u/blien)\
**Post date:** [November 27, 2017, 4:28pm UTC](https://discuss.gradle.org/t/gradle-3-0-prebuiltlibraries-dependency-link-error/24834/3 "2017-11-27T16:28:08Z")

</div>

I think I’ve misrepresented my problem after reverting to something similar to your post @Kevin2. I can build using the standard ./gradlew build.

However I was trying to find a workaround to resolving the error i get when running: ./gradlew build --parallel.

I have a C++ library, statically linked against a C library, statically linked against a C executable. If I put my “lib project:” lines in a particular order it will build fine using build command.

i was trying to use the prebuilt as a mechanism to resolve the --parallel build option that causes the G++ link error.
