Xcode generator duplicates .o sources in .a static libraries
CMakeLists.txt:
cmake_minimum_required(VERSION 3.24)
project(cmake_obj_test)
add_library(a empty.c src.o)
src.c:
void foo() {}
empty.c: (empty file)
Manually run:
clang -c -o src.o src.c
When the Xcode generator is used, the resultant xcode project specifies src.o
both in the source list and frameworks list for a
. Consequently, liba.a
ends up with two copies of src.o
. Normally this goes unnoticed, but if the library is linked using WHOLE_ARCHIVE then it leads to a duplicate symbol error.