# baseName isn't applied for 64bit debug mode in cpp plugin

**URL:** <https://discuss.gradle.org/t/basename-isnt-applied-for-64bit-debug-mode-in-cpp-plugin/19814>\
**Category:** Bugs\
**Tags:** plugins\
**Created:** [September 30, 2016, 9:23am UTC](https://discuss.gradle.org/t/basename-isnt-applied-for-64bit-debug-mode-in-cpp-plugin/19814 "2016-09-30T09:23:11Z")\
**Posts on this page:** 3\
**Page:** 1

<div class="post-metadata">

**Author:** ![Emily](https://avatars.discourse-cdn.com/v4/letter/e/8c91f0/32.png) [@Emily](https://discuss.gradle.org/u/Emily)\
**Post date:** [September 30, 2016, 9:23am UTC](https://discuss.gradle.org/t/basename-isnt-applied-for-64bit-debug-mode-in-cpp-plugin/19814/1 "2016-09-30T09:23:11Z")

</div>

I’m building a mixed Java and C++ (JNI) library project called `avio` and I’m having some issues with the `baseName` property not being properly applied for combination `debug` and `x86_64` while it is being applied to all other build modes.

I’m using the default source sets for source files and some other folders for supporting the build:

> src/main/java/_.java  
> src/main/cpp/_.{cpp, hpp}  
> src/main/resources/native/windows\_x{64,86}/_.dll  
> libs/cpp/windows\_x{64,86}/_.lib  
> libs/cpp/include/\*.{h,hpp}

so my java module is called `main` which is OK as I prefer convention over configuration. And as the JNI project is part of this module, I find it suitable that it lives in the same module. However I will need to change the name of the produced shared library to avoid a naming conflict, so I set `baseName` in my `cpp` `model`.

Building all configurations results in the following outputs:

> build/libs/main/shared/windows\_x64/debug/main.dll  
> build/libs/main/shared/windows\_x64/release/avio.dll  
> build/libs/main/shared/windows\_x86/debug/avio.dll  
> build/libs/main/shared/windows\_x86/release/avio.dll

Note how the `baseName` attribute isn’t applied to 64 bit debug builds but all other builds.

Relevant excerpt from my `build.gradle` file, I’m using default source sets for a mixed Java and JNI project. I.e:

```gradle
def mavenArtifactID = 'avio'

```

```gradle
model {
    toolChains {
        mingw_x86(Gcc) {
            path "$System.env.MINGW32"
            target("windows_x86")
        }
        mingw_x86_64(Gcc) {
            path "$System.env.MINGW64"
            target("windows_x86_64")
        }
    }
    platforms {
        windows_x86 {
            architecture "x86"
        }
        windows_x64 {
            architecture "x86_64"
        }
    }
    buildTypes {
        release
        debug
    }
    components {
        main(NativeLibrarySpec){         
            targetPlatform "windows_x86"
            targetPlatform "windows_x64"
             
            binaries.all{
                baseName = mavenArtifactID;
            
                def javaHome = org.gradle.internal.jvm.Jvm.current().javaHome.absolutePath
                cppCompiler.args "-I${javaHome}/include"
                cppCompiler.args "-I${javaHome}/include/win32"
                cppCompiler.args "-I${projectDir}/libs/cpp/include"
                cppCompiler.args "-Wall", "-Wextra", "-pedantic"
            
                if(buildType == buildTypes.release){
                    cppCompiler.args "-O2"
                }
                
                if(buildType == buildTypes.debug){
                    cppCompiler.args "-O0", "-g3", "-fno-inline"
                    linker.args "-g3"
                }
                
                linker.args "-static-libgcc", "-static-libstdc++", "-static"
                linker.args "-Wl,--kill-at"
                if(targetPlatform == platforms.windows_x64){
                    linker.args "-L${projectDir}/libs/cpp/windows_x64"
               	}
               	else{
           	    linker.args "-L${projectDir}/libs/cpp/windows_x86"
               	}
               	linker.args "-lavformat", "-lavcodec", "-lavdevice", "-lavfilter", "-lavutil", "-lswscale"
            }
        }
    }
}

```

Gradle Version: 3.1  
Operating System and JVM version: Windows 7 JDK 8u101

---

<div class="post-metadata">

**Author:** ![rodrigo](https://sea1.discourse-cdn.com/gradle/user_avatar/discuss.gradle.org/rodrigo/32/3431_2.png) [@rodrigo](https://discuss.gradle.org/u/rodrigo)\
**Post date:** [September 30, 2016, 12:49pm UTC](https://discuss.gradle.org/t/basename-isnt-applied-for-64bit-debug-mode-in-cpp-plugin/19814/2 "2016-09-30T12:49:46Z")

</div>

Hi Emily,

I suspect the `baseName` property is being set too late. Note that `baseName` belongs to `NativeLibrarySpec` itself and not to its binaries.

Please try to move it up to the `NativeLibrarySpec` level just after you set the target platforms and see if that makes a difference:

```
main(NativeLibrarySpec){         
    targetPlatform "windows_x86"
    targetPlatform "windows_x64"
    baseName = mavenArtifactID

    binaries.all{ ...

```

Cheers,  
Rodrigo

---

<div class="post-metadata">

**Author:** ![Emily](https://avatars.discourse-cdn.com/v4/letter/e/8c91f0/32.png) [@Emily](https://discuss.gradle.org/u/Emily)\
**Post date:** [October 4, 2016, 9:41am UTC](https://discuss.gradle.org/t/basename-isnt-applied-for-64bit-debug-mode-in-cpp-plugin/19814/3 "2016-10-04T09:41:13Z")

</div>

That works, thanks!

Being new to gradle I wholly expected it to work when put under binaries, or at least not fail silently for 25% of the cases 😖
