带有 Gradle cpp 插件的 Buld DLL

Buld DLL with Gradle cpp plugin

本文关键字:Buld DLL 插件 Gradle cpp 带有      更新时间:2023-10-16

有一个模块:

mod-native
------  build
------  sources
------------    myDll
----------------------- cpp
------------------------------  dllmain.cpp
------------------------------  MakeString.cpp
------------------------------  stdafx.cpp
------------------------------  MyDll.cpp
----------------------- headers
------------------------------  base64.h
------------------------------  tmain.h
------  build.gradle

所以,我的build.gradle

apply plugin: 'cpp'
model{
    toolChains{
        vs(VisualCpp){
            installDir "C:\Microsoft Visual Studio 12.0"
            windowsSdkDir "C:\Microsoft SDKs\Windows\v7.0"
        }
    }
    // target binary for win32
    platforms{
        win32{
            architecture "i386"
            operatingSystem "windows"
        }
    }
    components {
            toCms(NativeLibrarySpec){
                sources{
                    cpp{
                        source.srcDir "sources/myDll/cpp"
                        exportedHeaders.srcDir "sources/myDll/headers"
                    }
                }
            }
        }
}

我想获取 MyDll.dll 文件,但似乎 gradle 试图构建 *.lib 文件而不是 *.dll。如何构建 MyDll.dll ??谢谢!

如果未指定,gradle 将同时构建 *.lib 和 *.dll,这取决于您执行的任务。

如果您执行任务 toCmsDebug共享,它应该可以工作

注意:您应该使用 gradle 默认布局(因此您不必手动设置 srcDir):

src/
----*component name*/
---------cpp/
---------headers/

注2:当你想编译一个*.exe时,请确保你运行以"install"开头的任务(例如:installMyCmsDebugExecutable),这有很大的不同,因为Visual Studio将运行这个。

您可以在 *.vcxproj, xml 标记中检查为构建执行了哪个任务<NMakeBuildCommandLine>