Combining two static libraries into one

classic Classic list List threaded Threaded
7 messages Options
Reply | Threaded
Open this post in threaded view
|

Combining two static libraries into one

vinay kumar Kotegowder
Hi Everyone,

I have a requirement on combining two static library into one.
Can anyone tell me how can I achieve this?

Regards,
Vinay
--

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:
https://cmake.org/mailman/listinfo/cmake
Reply | Threaded
Open this post in threaded view
|

Re: Combining two static libraries into one

Kyle Edwards
On Tue, 2019-07-02 at 20:44 +0530, vinay kumar Kotegowder wrote:
> Hi Everyone,
>
> I have a requirement on combining two static library into one.
> Can anyone tell me how can I achieve this?
>
> Regards,
> Vinay

If you just want to make a library such that linking against that
library links against your two static libraries, you could use an
interface library. Example:

add_library(lib1 STATIC lib1.c)
add_library(lib2 STATIC lib2.c)
add_library(lib1_2 INTERFACE)
target_link_libraries(lib1_2 INTERFACE lib1 lib2)

Note that with this strategy, lib1 and lib2 will still exist as
separate files, but linking against lib1_2 will link against both of
these libraries.

Kyle
--

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:
https://cmake.org/mailman/listinfo/cmake
Reply | Threaded
Open this post in threaded view
|

Re: Combining two static libraries into one

Cristian Adam
In reply to this post by vinay kumar Kotegowder

On Tue, Jul 2, 2019 at 5:14 PM vinay kumar Kotegowder <[hidden email]> wrote:
Hi Everyone,

I have a requirement on combining two static library into one.
Can anyone tell me how can I achieve this?

Regards,
Vinay


If your compiler is GCC or Visual C++, you can use this as a base:

Cheers,
Cristian. 

--

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:
https://cmake.org/mailman/listinfo/cmake
Reply | Threaded
Open this post in threaded view
|

Re: Combining two static libraries into one

Rainer Poisel
I think there is no platform-independent way to solve this. Maybe you
could create two OBJECT libraries that are "linked" together into one
static lib.

Best regards,
  Rainer

On Tue, Jul 2, 2019 at 5:30 PM Cristian Adam <[hidden email]> wrote:

>
>
> On Tue, Jul 2, 2019 at 5:14 PM vinay kumar Kotegowder <[hidden email]> wrote:
>>
>> Hi Everyone,
>>
>> I have a requirement on combining two static library into one.
>> Can anyone tell me how can I achieve this?
>>
>> Regards,
>> Vinay
>>
>
> If your compiler is GCC or Visual C++, you can use this as a base:
> https://cristianadam.eu/20190501/bundling-together-static-libraries-with-cmake/
>
> Cheers,
> Cristian.
> --
>
> 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:
> https://cmake.org/mailman/listinfo/cmake
--

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:
https://cmake.org/mailman/listinfo/cmake
Reply | Threaded
Open this post in threaded view
|

Re: Combining two static libraries into one

vinay kumar Kotegowder
In reply to this post by Kyle Edwards
 I want to build lib2 static array with pre-built lib1 static array.
 Does this work?

 add_library(lib1 STATIC lib1.c)
 add_library(lib2 STATIC lib2.c)
 target_link_libraries(lib2 INTERFACE lib1)

 Also, Kyle said linking against lib2 will link against both lib1 and
 lib2. Is there a static way of checking the relation between lib1 and
 lib2 ? Separately and after using INTERFACE option with lib1 and lib2

 Regards,
 Vinay

On Tue, Jul 2, 2019 at 8:48 PM Kyle Edwards <[hidden email]> wrote:

>
> On Tue, 2019-07-02 at 20:44 +0530, vinay kumar Kotegowder wrote:
> > Hi Everyone,
> >
> > I have a requirement on combining two static library into one.
> > Can anyone tell me how can I achieve this?
> >
> > Regards,
> > Vinay
>
> If you just want to make a library such that linking against that
> library links against your two static libraries, you could use an
> interface library. Example:
>
> add_library(lib1 STATIC lib1.c)
> add_library(lib2 STATIC lib2.c)
> add_library(lib1_2 INTERFACE)
> target_link_libraries(lib1_2 INTERFACE lib1 lib2)
>
> Note that with this strategy, lib1 and lib2 will still exist as
> separate files, but linking against lib1_2 will link against both of
> these libraries.
>
> Kyle
--

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:
https://cmake.org/mailman/listinfo/cmake
Reply | Threaded
Open this post in threaded view
|

Re: Combining two static libraries into one

vinay kumar Kotegowder
In reply to this post by Kyle Edwards
 I want to build lib2 static library with pre-built lib1 static library.
 Does this work?

 add_library(lib1 STATIC lib1.c)
 add_library(lib2 STATIC lib2.c)
 target_link_libraries(lib2 INTERFACE lib1)

 Also, Kyle said linking against lib2 will link against both lib1 and
lib2. Is there a static way of checking the relation between lib1 and
 lib2 ? Separately and after using INTERFACE option with lib1 and lib2.

- Vinay

On Tue, Jul 2, 2019 at 8:48 PM Kyle Edwards <[hidden email]> wrote:

>
> On Tue, 2019-07-02 at 20:44 +0530, vinay kumar Kotegowder wrote:
> > Hi Everyone,
> >
> > I have a requirement on combining two static library into one.
> > Can anyone tell me how can I achieve this?
> >
> > Regards,
> > Vinay
>
> If you just want to make a library such that linking against that
> library links against your two static libraries, you could use an
> interface library. Example:
>
> add_library(lib1 STATIC lib1.c)
> add_library(lib2 STATIC lib2.c)
> add_library(lib1_2 INTERFACE)
> target_link_libraries(lib1_2 INTERFACE lib1 lib2)
>
> Note that with this strategy, lib1 and lib2 will still exist as
> separate files, but linking against lib1_2 will link against both of
> these libraries.
>
> Kyle
--

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:
https://cmake.org/mailman/listinfo/cmake
Reply | Threaded
Open this post in threaded view
|

Re: Combining two static libraries into one

Kyle Edwards
On Wed, 2019-07-03 at 18:55 +0530, vinay kumar Kotegowder wrote:
>  I want to build lib2 static library with pre-built lib1 static
> library.
>  Does this work?
>
>  add_library(lib1 STATIC lib1.c)
>  add_library(lib2 STATIC lib2.c)
>  target_link_libraries(lib2 INTERFACE lib1)

Yes, this will work.

>  Also, Kyle said linking against lib2 will link against both lib1 and
> lib2. Is there a static way of checking the relation between lib1 and
>  lib2 ? Separately and after using INTERFACE option with lib1 and
> lib2.

Asking "does lib1 link against lib2" has long been a requested feature
of CMake, but unfortunately, the existence of generator expressions
precludes this hypothetical feature. Because target_link_libraries()
supports generator expressions, which means the linking could change
based on the configuration (Debug, Release, etc.), we don't actually
know if lib1 links against lib2 until generate time, at which point
it's too late to do anything in configure time.

Kyle
--

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:
https://cmake.org/mailman/listinfo/cmake