[CMake] Object library doesn't work with CMake 2.8.10.2 Xcode generator

David Cole david.cole at kitware.com
Thu Jan 3 16:37:35 EST 2013


On Thu, Jan 3, 2013 at 4:33 PM, Bin Chen <Bin.Chen at dts.com> wrote:

>  David,
>
>
>
> CMake generator works fine. In Xcode, I got this error when I click build.
>
>
>
> Ld /Users/bchen/share/temp/cmake-obj-lib/b-xcode/Debug/t normal x86_64
>
>     cd /Users/bchen/share/temp/cmake-obj-lib/src
>
>
> /Applications/Xcode.app/Contents/Developer/Toolchains/XcodeDefault.xctoolchain/usr/bin/clang
> -arch x86_64 -L/Users/bchen/share/temp/cmake-obj-lib/b-xcode/Debug
> -F/Users/bchen/share/temp/cmake-obj-lib/b-xcode/Debug -filelist
> /Users/bchen/share/temp/cmake-obj-lib/b-xcode/test.build/Debug/t.build/Objects-normal/x86_64/t.LinkFileList
> -Wl,-search_paths_first -Wl,-headerpad_max_install_names
> /Users/bchen/share/temp/cmake-obj-lib/b-xcode/Debug/liba.a
> /Users/bchen/share/temp/cmake-obj-lib/b-xcode/Debug/libb.a -o
> /Users/bchen/share/temp/cmake-obj-lib/b-xcode/Debug/t
>
>
>
> clang: error: no such file or directory:
> '/Users/bchen/share/temp/cmake-obj-lib/b-xcode/Debug/liba.a'
>
> clang: error: no such file or directory:
> '/Users/bchen/share/temp/cmake-obj-lib/b-xcode/Debug/libb.a'
>
>
>
> Searched the build tree, it generated two libs with _obj.
>
>
>
> ./test.build/Debug/a_obj.build/Objects-normal/liba_obj.a
>
> ./test.build/Debug/b_obj.build/Objects-normal/libb_obj.a
>
>
>
> Thanks!
>
> Best regards,
>
> Bin Chen
>
>
>
> *From:* David Cole [mailto:david.cole at kitware.com]
> *Sent:* Thursday, January 03, 2013 1:26 PM
> *To:* Bin Chen
> *Cc:* cmake at cmake.org
> *Subject:* Re: [CMake] Object library doesn't work with CMake 2.8.10.2
> Xcode generator
>
>
>
> We have a test of OBJECT_LIBRARY that does work on all our dashboards,
> including ones running with Xcode.
>
>
>
> When you say "it doesn't work" -- what do you mean? Do you get some error
> output?
>
>
>
> On Thu, Jan 3, 2013 at 3:56 PM, Bin Chen <Bin.Chen at dts.com> wrote:
>
> Following CMakeLists.txt doesn’t work with Xcode (4.5.2). Is there anyone
> experienced the same? Thanks!
>
> Visual Studio 10 and Linux makefile works fine.
>
>
>
> cmake_minimum_required ( VERSION 2.8.8 )
>
>
>
> project( test )
>
>
>
> add_library( a_obj OBJECT t1.c t2.c )
>
> add_library( b_obj OBJECT t3.c t4.c )
>
>
>
> add_library( a $<TARGET_OBJECTS:a_obj> )
>
> add_library( b $<TARGET_OBJECTS:b_obj> )
>
>
>
> add_executable( t t.c )
>
> target_link_libraries( t a b )
>
>
>
>
>
> ::::::::::::::
>
> t.c
>
> ::::::::::::::
>
> #include <stdio.h>
>
>
>
> int func1( int a );
>
> int func2( int a );
>
> int func3( int a );
>
> int func4( int a );
>
>
>
> int main()
>
> {
>
>     int a = 100;
>
>     printf( "%d %d %d %d %d\n", a, func1(a), func2(a), func3(a), func4(a)
> );
>
>     return 0;
>
> }
>
> ::::::::::::::
>
> t1.c
>
> ::::::::::::::
>
> int func1( int a )
>
> {
>
>     return a*1;
>
> }
>
> ::::::::::::::
>
> t2.c
>
> ::::::::::::::
>
> int func2( int a )
>
> {
>
>     return a*2;
>
> }
>
> ::::::::::::::
>
> t3.c
>
> ::::::::::::::
>
> int func3( int a )
>
> {
>
>     return a*3;
>
> }
>
> ::::::::::::::
>
> t4.c
>
> ::::::::::::::
>
> int func4( int a )
>
> {
>
>     return a*4;
>
> }
>
>
>
> Best regards,
>
> Bin Chen
>
>
>
>
>  ------------------------------
>
>
> Notice:
> This message and any included attachments are intended only for the use of
> the addressee, and may contain information that is privileged or
> confidential. If you are not the intended recipient, you are hereby
> notified that any dissemination, distribution or copying of this
> communication is strictly prohibited. If you have received this
> communication in error, please destroy the original message and any copies
> or printouts hereof.
>
>
> --
>
> Powered by www.kitware.com
>
> Visit other Kitware open-source projects at
> http://www.kitware.com/opensource/opensource.html
>
> Please keep messages on-topic and check the CMake FAQ at:
> http://www.cmake.org/Wiki/CMake_FAQ
>
> Follow this link to subscribe/unsubscribe:
> http://www.cmake.org/mailman/listinfo/cmake
>
>
>
> ------------------------------
>
> Notice:
> This message and any included attachments are intended only for the use of
> the addressee, and may contain information that is privileged or
> confidential. If you are not the intended recipient, you are hereby
> notified that any dissemination, distribution or copying of this
> communication is strictly prohibited. If you have received this
> communication in error, please destroy the original message and any copies
> or printouts hereof.
>
>

I had misread/misunderstood your original post.


Instead of this:

add_library( a $<TARGET_OBJECTS:a_obj> )

add_library( b $<TARGET_OBJECTS:b_obj> )

add_executable( t t.c )


Just write this:

add_executable( t t.c $<TARGET_OBJECTS:a_obj> $<TARGET_OBJECTS:b_obj>)


Why do you try to put the objects from an OBJECT library into another
library? Just use them directly in your executable...


HTH,

David
-------------- next part --------------
An HTML attachment was scrubbed...
URL: <http://www.cmake.org/pipermail/cmake/attachments/20130103/77d78b2c/attachment-0001.htm>


More information about the CMake mailing list