[CMake] Linking static targets from sibling directories

David Cole david.cole at kitware.com
Thu Feb 18 12:00:18 EST 2010


You're simply misunderstanding what cmake does with static libs and
target_link_libraries.

It does nothing to include all symbols in one library... It simply uses that
information to chain all the libs together in a final executable.

You can do:
add_executable(e e.cxx)
target_link_libraries(e one_final_lib_that_depends_on_all_others)

...and then e will be linked against *all* of the libs chained together with
target_link_libraries calls.

If you want all the symbols in one static library, you'll have to include
all the sources in one add_library call.


HTH,
David


On Thu, Feb 18, 2010 at 11:46 AM, Scott MacVicar <macvicar at facebook.com>wrote:

> The linking doesn't include the .a files from the other directories, the
> final lib is missing those symbols.
>
> I checked with nm here, the error doesn't occur until until I attempt to
> use the built static library.
>
> Scott
>
>
>
> On 18 Feb 2010, at 07:36, "David Cole" <david.cole at kitware.com> wrote:
>
> What do you mean by "refuses to link the static libraries which are targets
> from the subfolders"
>
> I looked at your CMakeLists.txt files, which, at first glance, look
> correct... What error do you get?
>
> If you say "make VERBOSE=1" does it give you more data about what might be
> going wrong?
>
>
>
> On Thu, Feb 18, 2010 at 3:48 AM, Scott MacVicar < <macvicar at facebook.com>
> macvicar at facebook.com> wrote:
>
>> Hi,
>>
>> I've been converting a current autoconf project to use CMake, the layout
>> is such that there is a root directory and 3 sub directories containing
>> various parts of the project.
>>
>> filters and nls build two static libs and mbfl builds a third static lib
>> that links to the previous two.
>>
>> root
>> --filters
>> --mbfl
>> --nls
>>
>> mbfl contains
>> target_link_libraries(mbfl mbfl_filters)
>> target_link_libraries(mbfl mbfl_nls)
>>
>> but refuses to link the static libraries which are targets from the
>> subfolders.
>>
>> Entire repository is available at  <http://github.com/scottmac/libmbfl>
>> http://github.com/scottmac/libmbfl
>>
>> I could convert it to be built at one single lib in one go but would
>> rather keep parity with the autoconf equivalents.
>>
>> Any help or pointers would be appreciated.
>>
>> Scott
>>
>> _______________________________________________
>> Powered by <http://www.kitware.com>www.kitware.com
>>
>> Visit other Kitware open-source projects at
>> <http://www.kitware.com/opensource/opensource.html>
>> 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>http://www.cmake.org/Wiki/CMake_FAQ
>>
>> Follow this link to subscribe/unsubscribe:
>>  <http://www.cmake.org/mailman/listinfo/cmake>
>> http://www.cmake.org/mailman/listinfo/cmake
>>
>
>
-------------- next part --------------
An HTML attachment was scrubbed...
URL: <http://www.cmake.org/pipermail/cmake/attachments/20100218/1e0a3edc/attachment.htm>


More information about the CMake mailing list