# Native C++: define multiple external libraries with a loop

**URL:** <https://discuss.gradle.org/t/native-c-define-multiple-external-libraries-with-a-loop/11189>\
**Category:** Help/Discuss\
**Created:** [August 15, 2015, 7:49pm UTC](https://discuss.gradle.org/t/native-c-define-multiple-external-libraries-with-a-loop/11189 "2015-08-15T19:49:16Z")\
**Posts on this page:** 3\
**Page:** 1

<div class="post-metadata">

**Author:** ![nodakai](https://sea1.discourse-cdn.com/gradle/user_avatar/discuss.gradle.org/nodakai/32/2529_2.png) [@nodakai](https://discuss.gradle.org/u/nodakai)\
**Post date:** [August 15, 2015, 7:49pm UTC](https://discuss.gradle.org/t/native-c-define-multiple-external-libraries-with-a-loop/11189/1 "2015-08-15T19:49:16Z")

</div>

I have a native project with multiple references to external libraries (on Linux):

```
model {
  components { ... }
  repositories {
    libs(PrebuiltLibraries) {
      m {
        binaries.withType(SharedLibraryBinary) {
          sharedLibraryFile = file("/usr/lib64/libm.so")
        }
      }

      rt {
        binaries.withType(SharedLibraryBinary) {
          sharedLibraryFile = file("/usr/lib64/librt.so")
        }
      }
    }
  }
}

```

I’m sure I can define `m { ... }` and `rt { ... }` with a loop because they follow the same template:

```
  ["m", "rt"].each {
    ??? {
      binaries.withType(SharedLibraryBinary) {
        sharedLibraryFile = file("/usr/lib64/lib${it}.so")
      }
    }
  }

```

How can I do so?

> <https://gist.github.com/nodakai/b612a7f58c840cda0fb0>

---

<div class="post-metadata">

**Author:** ![Francois\_Guillot](https://sea1.discourse-cdn.com/gradle/user_avatar/discuss.gradle.org/francois_guillot/32/8566_2.png) [@Francois\_Guillot](https://discuss.gradle.org/u/Francois_Guillot)\
**Post date:** [August 15, 2015, 8:37pm UTC](https://discuss.gradle.org/t/native-c-define-multiple-external-libraries-with-a-loop/11189/2 "2015-08-15T20:37:33Z")

</div>

Simply with a groovy g-string  
Use “$it” instead of your ‘???’

---

<div class="post-metadata">

**Author:** ![nodakai](https://sea1.discourse-cdn.com/gradle/user_avatar/discuss.gradle.org/nodakai/32/2529_2.png) [@nodakai](https://discuss.gradle.org/u/nodakai)\
**Post date:** [August 15, 2015, 10:55pm UTC](https://discuss.gradle.org/t/native-c-define-multiple-external-libraries-with-a-loop/11189/3 "2015-08-15T22:55:59Z")

</div>

> [@Francois\_Guillot](#):
>
> Use “$it” instead of your ‘???’

Thanks, it worked! Actually I had tried `it { ... }` before I posted this question, only to get an error `No signature of method`. What is the difference between `it` and `"$it"` here? I thought they were equivalent.
