The following issue has been SUBMITTED. ====================================================================== http://public.kitware.com/Bug/view.php?id=14874 ====================================================================== Reported By: zub Assigned To: ====================================================================== Project: CMake Issue ID: 14874 Category: CMake Reproducibility: always Severity: minor Priority: normal Status: new ====================================================================== Date Submitted: 2014-04-14 11:50 EDT Last Modified: 2014-04-14 11:50 EDT ====================================================================== Summary: Static library can miss some object files Description: When creating a static library using binutils (ar) and there exist a duplicate object name (e.g. a/Foo.cpp.o, b/Foo.cpp.o), the resulting static library can end up having only one of the duplicate objects.
My reading of ar man page implies ar in general is OK with duplicate object names. Also, creating a simple CMake project (just a/foo.cpp, b/foo.cpp, add_library(test STATIC a/foo.cpp b/foo.cpp) results in a correct libtest.a. This bug only happens if there are many objects. This affects how CMake invokes ar. By default CMake invokes ar for the first time for a library like this: ar cr libtest.a path/to/a/foo.cpp.o path/to/b/foo.cpp.o ... and if this is the only invocation, it produces a correct libtest.a. But if there are many objects, CMake invokes ar several times, using the following for subsequent calls: ar r libtest.a other objects... Now if it happens that the first duplicate object is added in one invocation of ar, and then CMake invokes ar again to add another, ar just replaces the previous object. When I set: set(CMAKE_CXX_ARCHIVE_APPEND "<CMAKE_AR> <LINK_FLAGS> q <TARGET> <OBJECTS>") to use "q" instead of "r", the issue is resolved for me, so the fix could be just using "q" when adding objects (CMAKE_CXX_ARCHIVE_APPEND, CMAKE_C_ARCHIVE_APPEND and perhaps also CMAKE_CXX_ARCHIVE_CREATE and CMAKE_C_ARCHIVE_CREATE, though this probably won't make a difference). But I'm not sure how do other ar's handle this. I tested this using "GNU ar (GNU Binutils for Debian) 2.24". Steps to Reproduce: The issue is deterministic, but it does not occur for every project with duplicate object names - it depends on the project. To trigger this a project with many objects is required so that CMake in fact does invoke ar multiple times. Also, the duplicate objects must find their way into multiple invocations of ar, e.g.: ar cr libtest.a objects... a/foo.cpp.o objects... ar r libtest.a objects... b/foo.cpp.o objects... Then ar removes the previous foo.cpp.o. Creating a standalone testcase seems not so trivial; I run into this on a real project. If necessary, I can try to create one. ====================================================================== Issue History Date Modified Username Field Change ====================================================================== 2014-04-14 11:50 zub New Issue ====================================================================== -- Powered by www.kitware.com Please keep messages on-topic and check the CMake FAQ at: http://www.cmake.org/Wiki/CMake_FAQ Kitware offers various services to support the CMake community. For more information on each offering, please visit: CMake Support: http://cmake.org/cmake/help/support.html CMake Consulting: http://cmake.org/cmake/help/consulting.html CMake Training Courses: http://cmake.org/cmake/help/training.html Visit other Kitware open-source projects at http://www.kitware.com/opensource/opensource.html Follow this link to subscribe/unsubscribe: http://public.kitware.com/cgi-bin/mailman/listinfo/cmake-developers
