Gradle C ++项目:不包括Win32依赖项

时间:2018-07-26 10:21:45

标签: c++ gradle build.gradle

我在使用C ++的gradle时遇到问题。专门在一个使用win32和opengl的项目中构建本机库规范,并尝试从另一个可执行的测试项目中引用该静态库。

库gradle.build设置:

        repositories {
        libs(PrebuiltLibraries) {

            //defines the windows pre-built library, headers and .lib files

            windowsSDK {
                headers.srcDirs srcWindowsSDKDirName
                 binaries.withType(PrebuiltStaticLibraryBinary) {
                staticLibraryFile = file(srcWindowsSDKLibName+"10.0.16299.0/"+"um/"+"x86/"+"User32.Lib")

                binaries.withType(SharedLibraryBinary) {
                            sharedLibraryLinkFile = file(srcWindowsSDKLibName+"10.0.16299.0/"+"um/"+"x86/"+"User32.Lib")
                        }

                }
            }

            windowsSDKGLU {

               headers.srcDir srcWindowsSDKDirName
                binaries.withType(PrebuiltStaticLibraryBinary) {
                    staticLibraryFile = file(srcWindowsSDKLibName+"10.0.16299.0/"+"um/"+"x86/"+"GlU32.Lib") 
                }

                binaries.withType(SharedLibraryBinary) {
                sharedLibraryLinkFile = file(srcWindowsSDKLibName+"10.0.16299.0/"+"um/"+"x86/"+"GlU32.Lib")     
                }
            }

            windowsSDKGL {

               headers.srcDir srcWindowsSDKDirName
                binaries.withType(PrebuiltStaticLibraryBinary) {
                    staticLibraryFile = file(srcWindowsSDKLibName+"10.0.16299.0/"+"um/"+"x86/"+"OpenGL32.Lib")  
                }

                binaries.withType(SharedLibraryBinary) {
                sharedLibraryLinkFile = file(srcWindowsSDKLibName+"10.0.16299.0/"+"um/"+"x86/"+"OpenGL32.Lib")      
                }
            }

            windowsSDKGDI {

               headers.srcDir srcWindowsSDKDirName
                binaries.withType(PrebuiltStaticLibraryBinary) {
                    staticLibraryFile = file(srcWindowsSDKLibName+"10.0.16299.0/"+"um/"+"x86/"+"GDI32.lib") 
                }

                binaries.withType(SharedLibraryBinary) {
                sharedLibraryLinkFile = file(srcWindowsSDKLibName+"10.0.16299.0/"+"um/"+"x86/"+"GDI32.lib")     
                }
            }

        }
    }

这些是nativelibraryspec使用的库,该库项目实际上可以按预期构建,并输出.lib和.dll。

在NativeExecutableSpec(我的测试项目)中,我尝试首先包含整个项目:

lib project: ':mylibrary', linkage: "static", library: 'main'

这似乎在包括库本身方面起作用-它找到.lib或.dll。但是,它会产生链接错误:

main.lib(minimal.obj) : error LNK2019: unresolved external symbol __imp__ChoosePixelFormat@8 referenced in function "public: int __thiscall

还有更多……

要手动进行测试,我以引用Win32.lib文件的相同方式手动引用了静态库,并以这种方式将其包含在项目中:

    repositories {
        libs(PrebuiltLibraries) {

            //defines the windows pre-built library, headers and .lib files

            mySDK {
                headers.srcDirs "mysdk/Shared/headers"
                binaries.withType(PrebuiltStaticLibraryBinary) {
                staticLibraryFile = file("mysdk/build/libs/main/static/main.lib")

                binaries.withType(SharedLibraryBinary) {
                            sharedLibraryLinkFile = file("mysdk/build/libs/main/static/main.lib")
                        }

                }
            }
        }
    }

并将这些库包含在测试NativeExecutableSpec中。

                        lib library: "mySDK", linkage: "static"

试图链接引用这些Windows库的静态库的两种方法似乎都会导致链接错误,并且不确定为什么...如上所述的库本身可以编译,但是测试可执行文件无法链接,因为它似乎无法继承引用该项目的lib。

我研究了可能的原因,但是到目前为止,我找不到关于为什么编译该库的合理解释,但是任何引用该库的lib的解释都没有。

任何帮助将不胜感激。

0 个答案:

没有答案