Link Options
gpAddLinkOption() adds linker flags to a target. Like the other GPBT APIs, GPBT already applies the correct per-linker and per-configuration flags automatically — use this one for module-specific linker requirements.
Syntax
gpAddLinkOption(visibility flag [flag2 ...])
visibility is one of PUBLIC, PRIVATE, or INTERNAL.
Common use cases
Version scripts and symbol visibility
On Linux, you can restrict which symbols a shared library exports:
gpStartModule("renderer/core")
if(UNIX AND NOT APPLE)
gpAddLinkOption(PRIVATE "-Wl,--version-script=${CMAKE_CURRENT_LIST_DIR}/renderer_core.map")
endif()
gpEndModule()
Subsystem selection on Windows
gpStartExecutable("launcher")
if(WIN32)
gpAddLinkOption(PRIVATE /SUBSYSTEM:WINDOWS)
endif()
gpEndExecutable()
tip
For GUI executables on Windows, prefer gpSetGuiExecutable() rather than adding /SUBSYSTEM:WINDOWS manually. See Executable Specific for details.
System library flags
gpStartModule("platform")
if(UNIX AND NOT APPLE)
gpAddLinkOption(PRIVATE -ldl -lpthread)
endif()
gpEndModule()
Configuration-specific link options
Generator expressions work the same way as for compile options:
gpStartModule("core")
gpAddLinkOption(PRIVATE "$<$<CONFIG:Shipping>:-Wl,--gc-sections>")
gpEndModule()
Visibility reference
| Visibility | Effect |
|---|---|
PUBLIC | Applied to this target and propagated to all dependents |
PRIVATE | Applied to this target only |
INTERNAL | Applied to this target and modules connected via INTERNAL dependency edges |