From 31e29aff46694de65721781f8e5085d3a4041ea9 Mon Sep 17 00:00:00 2001 From: ruki Date: Sat, 14 Mar 2020 12:51:00 +0800 Subject: fix repeat objectfiles --- xmake/core/project/target.lua | 15 +++++++++++---- 1 file changed, 11 insertions(+), 4 deletions(-) (limited to 'xmake') diff --git a/xmake/core/project/target.lua b/xmake/core/project/target.lua index cb486a025..c6dca9f94 100644 --- a/xmake/core/project/target.lua +++ b/xmake/core/project/target.lua @@ -1069,22 +1069,29 @@ function _instance:objectfiles() -- get object files from source batches local objectfiles = {} + local batchcount = 0 for _, sourcebatch in pairs(self:sourcebatches()) do table.join2(objectfiles, sourcebatch.objectfiles) + batchcount = batchcount + 1 end + -- some object files may be repeat and appear link errors if multi-batches exists, so we need remove all repeat object files + -- e.g. add_files("src/*.c", {rules = {"rule1", "rule2"}}) + local remove_repeat = batchcount > 1 + -- get object files from all dependent targets (object kind) if self:orderdeps() then - local remove_repeat = false for _, dep in ipairs(self:orderdeps()) do if dep:targetkind() == "object" then table.join2(objectfiles, dep:objectfiles()) remove_repeat = true end end - if remove_repeat then - objectfiles = table.unique(objectfiles) - end + end + + -- remove repeat object files + if remove_repeat then + objectfiles = table.unique(objectfiles) end -- cache it -- cgit v1.3.1