Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Promote build_target linker to C++ if linking to C++ libraries #1653

Closed
nirbheek opened this issue Apr 20, 2017 · 9 comments
Closed

Promote build_target linker to C++ if linking to C++ libraries #1653

nirbheek opened this issue Apr 20, 2017 · 9 comments

Comments

@nirbheek
Copy link
Member

Sometimes people link to C++ libraries that export C APIs, but still link to libstdc++. For example: https://bugzilla.gnome.org/show_bug.cgi?id=781561

Need a test case from @dcbaker for this, and then it can be fixed by adding a special case in build.py:BuildTarget.get_clike_dynamic_linker().

dcbaker added a commit to dcbaker/meson that referenced this issue Apr 20, 2017
…brary

This exercises a regression where the C rather than C++ linker is
chosen, resulting in symbol errors.

Test for mesonbuild#1653
@dcbaker
Copy link
Member

dcbaker commented Apr 20, 2017

I've sent a pull request. Interestingly the test passes on 0.39.1, but not against master, so I think this is actually a regression.

@dcbaker
Copy link
Member

dcbaker commented Apr 20, 2017

@nirbheek I bisected this down to this commit from you:

commit 14d0f381580222f4b4eac376f514fcfcfdb6ee4c
Author: Nirbheek Chauhan <nirbheek@centricular.com>
Date:   Fri Mar 24 18:31:22 2017 +0530

    Try harder to use the C compiler for compiling asm

    Use an ordered dict for the compiler dictionary and sort it according
    to a priority order: fortran, c, c++, etc.

    This also ensures that builds are reproducible because it would be
    a toss-up whether a C or a C++ compiler would be used based on the
    order in which compilers.items() would return items.

    Closes https://github.com/mesonbuild/meson/issues/1370

@nirbheek
Copy link
Member Author

nirbheek commented Apr 21, 2017

Right, I thought that might be responsible for this. We traded one regression for another regression. :)

nirbheek added a commit to dcbaker/meson that referenced this issue Apr 21, 2017
Sometimes you want to link to a C++ library that exports C API, which
means the linker must link in the C++ stdlib, and we must use a C++
compiler for linking. The same is also applicable for objc/objc++ etc,
so we can keep using clike_langs for the priority order.

Closes mesonbuild#1653
@nirbheek
Copy link
Member Author

To see the planning fallacy in action, see how often I add and then remove the "easy" tag on bugs.

@dcbaker
Copy link
Member

dcbaker commented Apr 21, 2017

Since this is a regression this should get fixed before the next release, correct?

dcbaker added a commit to dcbaker/meson that referenced this issue Apr 21, 2017
…brary

This exercises a regression where the C rather than C++ linker is
chosen, resulting in symbol errors.

Test for mesonbuild#1653
dcbaker pushed a commit to dcbaker/meson that referenced this issue Apr 21, 2017
Sometimes you want to link to a C++ library that exports C API, which
means the linker must link in the C++ stdlib, and we must use a C++
compiler for linking. The same is also applicable for objc/objc++ etc,
so we can keep using clike_langs for the priority order.

Closes mesonbuild#1653
@nirbheek
Copy link
Member Author

Hmm true, I thought we released 0.39.1 with that regression, but it seems I broke it after the last release. So we should indeed fix this before release.

dcbaker added a commit to dcbaker/meson that referenced this issue Apr 21, 2017
…brary

This exercises a regression where the C rather than C++ linker is
chosen, resulting in symbol errors.

Test for mesonbuild#1653
dcbaker added a commit to dcbaker/meson that referenced this issue Apr 24, 2017
…brary

This exercises a regression where the C rather than C++ linker is
chosen, resulting in symbol errors.

Test for mesonbuild#1653
dcbaker pushed a commit to dcbaker/meson that referenced this issue Apr 24, 2017
Sometimes you want to link to a C++ library that exports C API, which
means the linker must link in the C++ stdlib, and we must use a C++
compiler for linking. The same is also applicable for objc/objc++ etc,
so we can keep using clike_langs for the priority order.

Closes mesonbuild#1653
@ePirat
Copy link
Contributor

ePirat commented Jun 27, 2019

@nirbheek How do you detect if linking to a C++ lib? For example in VLC we have the following case: the vulkan module links with libplacebo, libplacebo itself is a C library and uses glslang which is a C++ library. This breaks with autotools when statically linked glslang + libplacebo is linked into the shared vulkan module. Can meson somehow detect this case? Or will I need the link_language kwarg in that case?

@dcbaker
Copy link
Member

dcbaker commented Jun 28, 2019

This only works with internal libraries, basically it says "liba was compiled and linked with c++, so libb which link_with's liba also needs to be c++". This internal logic is why I wan't to put the link_language in the find_library() and dependency() function instead of the library, since meson already knows how to handle linking various langauges together.

@ePirat
Copy link
Contributor

ePirat commented Nov 22, 2019

Any update on this? It's a problematic issue for my VLC port and so far I just use a dummy-meson.cpp which is very ugly.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Projects
None yet
Development

No branches or pull requests

3 participants