Skip to content

Namespace Isolation

We can use namespace to isolate targets, options, and rules in different sub-projects to avoid naming conflicts.

Basic Example

EXPLORER
src
main.cpp
test.cpp
xmake.lua
src1
main.cpp
xmake.lua
src2
main.cpp
xmake.lua
xmake.lua
Lua xmake.lua
1234567891011121314
add_rules("mode.debug", "mode.release")

namespace("ns1", function ()
    includes("src1")
end)

namespace("ns2", function ()
    includes("src2")
end)

target("app")
    set_kind("binary")
    add_deps("ns1::lib", "ns2::lib")
    add_files("src/main.cpp")

Build and Run

bash
$ xmake
$ xmake run