mesonbuild / mesonbuild/meson

macos framework paths not found when using clang with -std=C++<ver> or std=gnu++<ver> external CXX args

Open
#13,640 8 comments 0 reactions 0 assignees View on GitHub

Nobody has claimed this yet.

OS:macos
Dominant language
Python
Stars
6.6k
Forks
1.9k
Avg merge
2d 6h
Merged PRs (30d)
33

Description

When building some packages with macports such as gstreamer1-plugins-bad for macos system and using xcode basic systems clang apple compiler or upgraded apple clang compiler sometimes extra CXX compiler args such as for this package -std=gnu++11 is required. When building package it issues a meson configure error:

Called: `/opt/local/bin/pkg-config --modversion CoreFoundation` -> 1
stderr:
Package CoreFoundation was not found in the pkg-config search path.
Perhaps you should add the directory containing `CoreFoundation.pc'
to the PKG_CONFIG_PATH environment variable
No package 'CoreFoundation' found
-----------
Finding framework path by running:  /usr/bin/clang++ -v -E - -pipe -Os -std=gnu++11 -stdlib=libc++ -isysroot/Library/Developer/CommandLineTools/SDKs/MacOSX10.15.sdk -arch x86_64 -I/opt/local/include -L/opt/local/lib -Wno-unused-command-line-argument -isysroot/Library/Developer/CommandLineTools/SDKs/MacOSX10.15.sdk 

CMake binary for host machine is cached.
Preliminary CMake check failed. Aborting.
Run-time dependency corefoundation found: NO (tried pkgconfig, framework and cmake)

sys/applemedia/meson.build:42:21: ERROR: Dependency "CoreFoundation" not found, tried pkgconfig, framework and cmake

Further investigation showed that the issued framework find path command failed. I tried it in terminal on it's own. failure message :

Apple clang version 12.0.0 (clang-1200.0.32.29)
Target: x86_64-apple-darwin19.6.0
Thread model: posix
InstalledDir: /Applications/Xcode.app/Contents/Developer/Toolchains/XcodeDefault.xctoolchain/usr/bin
<whole command ...>
error: invalid argument '-std=gnu++11' not allowed with 'C'

Due to the error which can't be silenced on clang compiler the command issues 1 and is broken result : framework path not found.

When searching further on the net this issue does show up very much in environments where clang and meson is used.
this for -std=c++11,-std=gnu++11,-std=c++17 or -std=gnu++17 ....

The cause is that indeed those args are only allowed for C++/Gobj++ not for 'C'

I did finally found a simple (and do think a clean solution to this issue) :
First :

  • Meson does a very good job at run time by only using the required external args for the type of file to build.
  • The Framework-path find command on the other hand go's for all file type c++,cojb++,c,cobj,cpp and ...
  • that is required also every external arg CXX,CPP,C,COBJ,COBJ.. flags may contain required extra links and ..
  • Making a solution which just ommits the CXX,Cobj flags is not a option.

My solution is just to omit the invalid flags for just the framework find path command how :

changing in file mesonbuild/compilers/mixins/clike.py line 1187-1195 from :

        # TODO: this really needs to be *AppleClang*, not just any clang.
        if self.id != 'clang':
            raise mesonlib.MesonException('Cannot find framework path with non-clang compiler')
        # Construct the compiler command-line
        commands = self.get_exelist(ccache=False) + ['-v', '-E', '-']
        commands += self.get_always_args()
        # Add CFLAGS/CXXFLAGS/OBJCFLAGS/OBJCXXFLAGS from the env
        commands += env.coredata.get_external_args(self.for_machine, self.language)
        mlog.debug('Finding framework path by running: ', ' '.join(commands), '\n')

to :

        # TODO: this really needs to be *AppleClang*, not just any clang.
        if self.id != 'clang':
            raise mesonlib.MesonException('Cannot find framework path with non-clang compiler')
        # Construct the compiler command-line
        commands = self.get_exelist(ccache=False) + ['-v', '-E', '-']
        commands += self.get_always_args()
        # Add CFLAGS/CXXFLAGS/OBJCFLAGS/OBJCXXFLAGS from the env
        # 'std=c++<ver>','std=gnu++<ver>' are valid for C++/ObjC++ but not for 'C'
        commands += [x for x in env.coredata.get_external_args(self.for_machine, self.language) if '-std=c++' not in x and '-std=gnu++' not in x]
        mlog.debug('Finding framework path by running: ', ' '.join(commands), '\n')

Then all the framwork paths are found again and project builds fine .

I will submit in short a pull request with this change. I just added this issue first so I can refer to this issue in pull request commit.

Contributor guide

Open the contributing guide

First steps

  1. Read the whole issue, then the project's contributing guide.
  2. Comment on the issue to say you are picking it up — it saves two people doing the same work.
  3. Fork the repository and make your change on a branch.
  4. Open a pull request that references the issue number.

Research direction

Start in mesonbuild/compilers/mixins/clike.py around lines 1187-1195 and inspect how external compiler arguments are added to the framework-path command. Reproduce the Apple Clang invocation with a C++ standard flag, then verify that framework paths are found and the affected Meson configuration succeeds without the invalid C-language argument error.

Written by the indexing model from the issue text.

Assessment

Tech stack
cpp, macos, python
Domain
build-system, compilers
Issue type
Bug
Difficulty
2/5
Estimated time
1-3 hours
Activity status
Stale
Clarity
Clearly specified
Newbie friendliness
45/100

Get new issues in your inbox

A short digest of beginner-friendly GitHub issues.