13

我正在编写一个本机节点模块,我希望能够在发布和调试版本中构建它。

节点模块链接到另一个库,该库在两个不同的目录中具有调试和发布版本。

现在这是我卡住的地方 - 我如何为正在构建的当前配置指定库目录?

我试过在configurations.debug.link_settings键中设置它,但我得到错误:'在调试配置中不允许link_settings,在目标binding.gyp中找到

4

2 回答 2

17

显然,这在跨平台的方式中是不可能的。所以希望这可以节省你几个小时的实验时间。

这是一个为 Mac 和 Windows 构建插件的 gyp 文件。

//This example assumes you have an external library 'thelibrary', located in 
//./external/thelibrary
//With the two flavors, debug and release in lib/debug and lib/release
{
    "targets": [
        {
            "target_name": "addon",
            "sources": [
                "src/addon.cpp",
                "src/expose_the_library.cpp"
            ],
            "include_dirs": [
                "external/thelibrary/include"
            ],
            "cflags!": [
                "-fno-exceptions"
            ],
            "cflags_cc!": [
                "-fno-exceptions"
            ],
            "conditions": [
                [
                    "OS=='mac'",
                    {
                        "defines": [
                            "__MACOSX_CORE__"
                        ],
                        "architecture": "i386",
                        "xcode_settings": {
                            "GCC_ENABLE_CPP_EXCEPTIONS": "YES"
                        },
                        "link_settings": {
                            "libraries": [
                                "-lthelibrary",
                                "-framework",   
                                "IOBluetooth" //this is how you use a framework on OSX
                            ],
                            "configurations": {
                                "Debug": {
                                    "xcode_settings": {
                                        "OTHER_LDFLAGS": [
                                            "-Lexternal/thelibrary/lib/debug"
                                        ]
                                    }
                                },
                                "Release": {
                                    "xcode_settings": {
                                        "OTHER_LDFLAGS": [
                                            "-Lexternal/thelibrary/lib/release"
                                        ]
                                    }
                                }
                            }
                        }
                    }
                ],
                [
                    "OS=='win'",
                    {
                        "link_settings": {
                            "libraries": [
                                "-lthelibrary.lib",
                            ]
                        },
                        "configurations": {
                            "Debug": {
                                "msvs_settings": {
                                    "VCCLCompilerTool": {
                                        "ExceptionHandling": "0",
                                        "AdditionalOptions": [
                                            "/MP /EHsc"
                                        ]
                                    },
                                    "VCLibrarianTool": {
                                        "AdditionalOptions": [
                                            "/LTCG"
                                        ]
                                    },
                                    "VCLinkerTool": {
                                        "LinkTimeCodeGeneration": 1,
                                        "LinkIncremental": 1,
                                        "AdditionalLibraryDirectories": [
                                            "../external/thelibrary/lib/debug"
                                        ]
                                    }
                                }
                            },
                            "Release": {
                                "msvs_settings": {
                                    "VCCLCompilerTool": {
                                        "RuntimeLibrary": 0,
                                        "Optimization": 3,
                                        "FavorSizeOrSpeed": 1,
                                        "InlineFunctionExpansion": 2,
                                        "WholeProgramOptimization": "true",
                                        "OmitFramePointers": "true",
                                        "EnableFunctionLevelLinking": "true",
                                        "EnableIntrinsicFunctions": "true",
                                        "RuntimeTypeInfo": "false",
                                        "ExceptionHandling": "0",
                                        "AdditionalOptions": [
                                            "/MP /EHsc"
                                        ]
                                    },
                                    "VCLibrarianTool": {
                                        "AdditionalOptions": [
                                            "/LTCG"
                                        ]
                                    },
                                    "VCLinkerTool": {
                                        "LinkTimeCodeGeneration": 1,
                                        "OptimizeReferences": 2,
                                        "EnableCOMDATFolding": 2,
                                        "LinkIncremental": 1,
                                        "AdditionalLibraryDirectories": [
                                            "../external/thelibrary/lib/release"
                                        ]
                                    }
                                }
                            }
                        }
                    }
                ]
            ]
        }
    ]
}
于 2012-12-27T17:43:49.970 回答
0

I faced this issue as well and it seems that if you pass --format=make-linux (for example) on the command line it will generate for the 'make' format but it will explicitly use the 'linux' flavor.

于 2020-04-14T09:49:32.987 回答