How is the linker language of a library determined?

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

How is the linker language of a library determined?

Robin Verschueren
Hi there,

I'm building some C code into a library. The library needs to link to a C++ static library (IMPORTED target). I'm puzzled by the following:
  • with BUILD_SHARED_LIBS=OFF (default), everything works as expected and CMake sees the C library as a "C++ library" (i.e. it uses the C++ compiler/linker to link the two libraries together into a static library).
  • with BUILD_SHARED_LIBS=ON however, CMake tries to link the C library to the C++ library with cc (clang in my case), and I get linker errors.
My questions:

What mechanism does CMake use to determine the linker language, and why is it different in these two cases? Is it because I want to link a shared library against a static library as opposed to two static ones? Or is BUILD_SHARED_LIBS a red herring? Does CMake have a notion of what linker language to use for IMPORTED targets?

I'm looking forward to your answer,
Robin

--

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

Re: How is the linker language of a library determined?

Craig Scott-3


On Wed, Nov 8, 2017 at 7:29 AM, Robin Verschueren <[hidden email]> wrote:
Hi there,

I'm building some C code into a library. The library needs to link to a C++ static library (IMPORTED target). I'm puzzled by the following:
  • with BUILD_SHARED_LIBS=OFF (default), everything works as expected and CMake sees the C library as a "C++ library" (i.e. it uses the C++ compiler/linker to link the two libraries together into a static library).
  • with BUILD_SHARED_LIBS=ON however, CMake tries to link the C library to the C++ library with cc (clang in my case), and I get linker errors.
My questions:

What mechanism does CMake use to determine the linker language, and why is it different in these two cases? Is it because I want to link a shared library against a static library as opposed to two static ones? Or is BUILD_SHARED_LIBS a red herring? Does CMake have a notion of what linker language to use for IMPORTED targets?


Can you confirm which CMake generator type you are using? If it is the Xcode generator, do you get the same behaviour building at the command line as you do from within the IDE? I only ask because your symptoms sound eerily familiar to a problem I've seen before where linking used a different launcher from the command line compared to the IDE (see the Xcode section of this article).


--
Craig Scott
Melbourne, Australia

--

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

Re: How is the linker language of a library determined?

Robin Verschueren
I use the "Unix Makefiles" generator (on macOS), with clang and clang++ as compilers (XCode version 9).

On Wed, 8 Nov 2017 at 03:47 Craig Scott <[hidden email]> wrote:

On Wed, Nov 8, 2017 at 7:29 AM, Robin Verschueren <[hidden email]> wrote:
Hi there,

I'm building some C code into a library. The library needs to link to a C++ static library (IMPORTED target). I'm puzzled by the following:
  • with BUILD_SHARED_LIBS=OFF (default), everything works as expected and CMake sees the C library as a "C++ library" (i.e. it uses the C++ compiler/linker to link the two libraries together into a static library).
  • with BUILD_SHARED_LIBS=ON however, CMake tries to link the C library to the C++ library with cc (clang in my case), and I get linker errors.
My questions:

What mechanism does CMake use to determine the linker language, and why is it different in these two cases? Is it because I want to link a shared library against a static library as opposed to two static ones? Or is BUILD_SHARED_LIBS a red herring? Does CMake have a notion of what linker language to use for IMPORTED targets?


Can you confirm which CMake generator type you are using? If it is the Xcode generator, do you get the same behaviour building at the command line as you do from within the IDE? I only ask because your symptoms sound eerily familiar to a problem I've seen before where linking used a different launcher from the command line compared to the IDE (see the Xcode section of this article).



--
Craig Scott
Melbourne, Australia

--

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

Re: How is the linker language of a library determined?

Craig Scott-3
Can you create a small, self-contained example that reproduces the problem? A bit more than trivial since imported targets are involved, but give it a go, it will help narrow down the problem. If you're able to do that, please then report this in the issue tracker and attach that example. Also include the build output highlighting where you believe the commands used are incorrect.

On Wed, Nov 8, 2017 at 3:40 PM, Robin Verschueren <[hidden email]> wrote:
I use the "Unix Makefiles" generator (on macOS), with clang and clang++ as compilers (XCode version 9).

On Wed, 8 Nov 2017 at 03:47 Craig Scott <[hidden email]> wrote:

On Wed, Nov 8, 2017 at 7:29 AM, Robin Verschueren <[hidden email]> wrote:
Hi there,

I'm building some C code into a library. The library needs to link to a C++ static library (IMPORTED target). I'm puzzled by the following:
  • with BUILD_SHARED_LIBS=OFF (default), everything works as expected and CMake sees the C library as a "C++ library" (i.e. it uses the C++ compiler/linker to link the two libraries together into a static library).
  • with BUILD_SHARED_LIBS=ON however, CMake tries to link the C library to the C++ library with cc (clang in my case), and I get linker errors.
My questions:

What mechanism does CMake use to determine the linker language, and why is it different in these two cases? Is it because I want to link a shared library against a static library as opposed to two static ones? Or is BUILD_SHARED_LIBS a red herring? Does CMake have a notion of what linker language to use for IMPORTED targets?


Can you confirm which CMake generator type you are using? If it is the Xcode generator, do you get the same behaviour building at the command line as you do from within the IDE? I only ask because your symptoms sound eerily familiar to a problem I've seen before where linking used a different launcher from the command line compared to the IDE (see the Xcode section of this article).



--
Craig Scott
Melbourne, Australia



--
Craig Scott
Melbourne, Australia

--

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

Re: How is the linker language of a library determined?

Robin Verschueren
Hi Craig,

Thanks for your continued support. I was able to create a small example that you can find here: 


Best regards,
Robin

On Fri, 10 Nov 2017 at 06:32 Craig Scott <[hidden email]> wrote:
Can you create a small, self-contained example that reproduces the problem? A bit more than trivial since imported targets are involved, but give it a go, it will help narrow down the problem. If you're able to do that, please then report this in the issue tracker and attach that example. Also include the build output highlighting where you believe the commands used are incorrect.

On Wed, Nov 8, 2017 at 3:40 PM, Robin Verschueren <[hidden email]> wrote:
I use the "Unix Makefiles" generator (on macOS), with clang and clang++ as compilers (XCode version 9).

On Wed, 8 Nov 2017 at 03:47 Craig Scott <[hidden email]> wrote:

On Wed, Nov 8, 2017 at 7:29 AM, Robin Verschueren <[hidden email]> wrote:
Hi there,

I'm building some C code into a library. The library needs to link to a C++ static library (IMPORTED target). I'm puzzled by the following:
  • with BUILD_SHARED_LIBS=OFF (default), everything works as expected and CMake sees the C library as a "C++ library" (i.e. it uses the C++ compiler/linker to link the two libraries together into a static library).
  • with BUILD_SHARED_LIBS=ON however, CMake tries to link the C library to the C++ library with cc (clang in my case), and I get linker errors.
My questions:

What mechanism does CMake use to determine the linker language, and why is it different in these two cases? Is it because I want to link a shared library against a static library as opposed to two static ones? Or is BUILD_SHARED_LIBS a red herring? Does CMake have a notion of what linker language to use for IMPORTED targets?


Can you confirm which CMake generator type you are using? If it is the Xcode generator, do you get the same behaviour building at the command line as you do from within the IDE? I only ask because your symptoms sound eerily familiar to a problem I've seen before where linking used a different launcher from the command line compared to the IDE (see the Xcode section of this article).



--
Craig Scott
Melbourne, Australia



--
Craig Scott
Melbourne, Australia

--

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/mailman/listinfo/cmake