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

spdlog is packaged in such a way that including <spdlog/spdlog.h> gives a macro redefinition warning of the macro SPDLOG_FMT_EXTERNAL #88896

Closed
2 tasks done
mortie opened this issue Nov 6, 2021 · 5 comments
Labels
bug Reproducible Homebrew/homebrew-core bug outdated PR was locked due to age stale No recent activity

Comments

@mortie
Copy link
Contributor

mortie commented Nov 6, 2021

brew gist-logs <formula> link OR brew config AND brew doctor output

$ brew gist-logs spdlog
Error: No logs.

$ brew config
HOMEBREW_VERSION: 3.3.2
ORIGIN: https://github.com/Homebrew/brew
HEAD: 9daf5e2d28396c7a4379605e89e029d9fccb41e6
Last commit: 6 days ago
Core tap ORIGIN: https://github.com/Homebrew/homebrew-core
Core tap HEAD: ff99cddaad3c870dac74d7be6b8da4bdbc2bce18
Core tap last commit: 56 minutes ago
Core tap branch: master
HOMEBREW_PREFIX: /opt/homebrew
HOMEBREW_CASK_OPTS: []
HOMEBREW_CORE_GIT_REMOTE: https://github.com/Homebrew/homebrew-core
HOMEBREW_EDITOR: nvim
HOMEBREW_MAKE_JOBS: 8
Homebrew Ruby: 2.6.8 => /System/Library/Frameworks/Ruby.framework/Versions/2.6/usr/bin/ruby
CPU: octa-core 64-bit arm_firestorm_icestorm
Clang: 13.0.0 build 1300
Git: 2.30.1 => /Applications/Xcode.app/Contents/Developer/usr/bin/git
Curl: 7.77.0 => /usr/bin/curl
macOS: 12.0.1-arm64
CLT: 13.1.0.0.1.1633545042
Xcode: 13.1
Rosetta 2: false

$ brew doctor
Please note that these warnings are just used to help the Homebrew maintainers
with debugging if you file an issue. If everything you use Homebrew for is
working fine: please don't worry or file an issue; just ignore this. Thanks!

Warning: You have installed Bitdefender. The "Traffic Scan" option interferes with
Homebrew's ability to download packages. See:
  https://github.com/Homebrew/brew/issues/5558

I can't disable Bitdefender because this is a work machine. But I'm very confident that the issue isn't related to Bitdefender, since Homebrew's ability to download packages doesn't seem affected at all.

  • I ran brew update and am still able to reproduce my issue.
  • I have resolved all warnings from brew doctor and that did not fix my problem.

What were you trying to do (and why)?

I was using the spdlog package in a program.

What happened (include all command output)?

The pkgconfig file for spdlog specifies a cflags field which contains -DSPDLOG_FMT_EXTERNAL. The file spdlog/1.9.2/include/spdlog/tweakme.h (included by the main spdlog.h) also contains #define SPDLOG_FMT_EXTERNAL (not guarded by an #ifdef). So if you install the brew package for spdlog, then #include <spdlog/spdlog.h>, and compile the file using the flags suggested by pkg-config, the compiler complains that SPDLOG_FMT_EXTERNAL is being redefined.

$ cat test.cc
#include <spdlog/spdlog.h>

$ clang -c $(pkg-config --cflags spdlog) test.cc
In file included from test.cc:1:
In file included from /opt/homebrew/Cellar/spdlog/1.9.2/include/spdlog/spdlog.h:12:
In file included from /opt/homebrew/Cellar/spdlog/1.9.2/include/spdlog/common.h:6:
/opt/homebrew/Cellar/spdlog/1.9.2/include/spdlog/tweakme.h:74:9: warning: 'SPDLOG_FMT_EXTERNAL' macro r
edefined [-Wmacro-redefined]
#define SPDLOG_FMT_EXTERNAL
        ^
<command line>:3:9: note: previous definition is here
#define SPDLOG_FMT_EXTERNAL 1
        ^
1 warning generated.

What did you expect to happen?

I expected to be able to compile the source file without warnings with the compilation options suggested by the package's pkgconfig file.

Step-by-step reproduction instructions (by running brew commands)

$ brew install spdlog
$ echo '#include <spdlog/spdlog.h>' > test.cc
$ clang -c $(pkg-config --cflags spdlog) test.cc
In file included from test.cc:1:
In file included from /opt/homebrew/Cellar/spdlog/1.9.2/include/spdlog/spdlog.h:12:
In file included from /opt/homebrew/Cellar/spdlog/1.9.2/include/spdlog/common.h:6:
/opt/homebrew/Cellar/spdlog/1.9.2/include/spdlog/tweakme.h:74:9: warning: 'SPDLOG_FMT_EXTERNAL' macro r
edefined [-Wmacro-redefined]
#define SPDLOG_FMT_EXTERNAL
        ^
<command line>:3:9: note: previous definition is here
#define SPDLOG_FMT_EXTERNAL 1
        ^
1 warning generated.
@mortie mortie added the bug Reproducible Homebrew/homebrew-core bug label Nov 6, 2021
@carlocab
Copy link
Member

carlocab commented Nov 6, 2021

Is the warning causing you any real issues other than it being emitted?

We'll review a pull request to fix this. See #79629.

@mortie
Copy link
Contributor Author

mortie commented Nov 8, 2021

It's not causing any issues other than the warning, no. But the existence of a warning I can't do anything to fix is a real issue in itself, since generally you want to develop with -Werror or at the very least keep the build warning-free while developing, so it's a fairly significant inconvenience.

My workaround currently is to add -USPDLOG_FMT_EXTERNAL to the compiler flags when compiling under macOS, which works well until the issue is fixed.

@carlocab
Copy link
Member

carlocab commented Nov 8, 2021

Well, as mentioned: we'd be happy to review a pull request that fixes this.

As for -Werror, I'm not a fan. But I know it's a common pattern.

@mortie
Copy link
Contributor Author

mortie commented Nov 9, 2021

I agree that there's a lot of abuse of -Werror out there, I've argued against it a lot and even submitted issues about -Werror causing build failures. However, I do think it has a place in one particular context: CI. My preferred way of developing software would be to avoid compiler warnings while developing locally, and then have a CI setup which compiles with -Werror to ensure nothing with warnings gets in.

@github-actions
Copy link
Contributor

github-actions bot commented Dec 1, 2021

This issue has been automatically marked as stale because it has not had recent activity. It will be closed if no further activity occurs.

@github-actions github-actions bot added the stale No recent activity label Dec 1, 2021
@github-actions github-actions bot closed this as completed Dec 9, 2021
@github-actions github-actions bot added the outdated PR was locked due to age label Jan 9, 2022
@github-actions github-actions bot locked as resolved and limited conversation to collaborators Jan 9, 2022
Sign up for free to subscribe to this conversation on GitHub. Already have an account? Sign in.
Labels
bug Reproducible Homebrew/homebrew-core bug outdated PR was locked due to age stale No recent activity
Projects
None yet
Development

No branches or pull requests

2 participants