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

defineCMacro not respected in included header file #19839

Closed
actondev opened this issue May 2, 2024 · 2 comments
Closed

defineCMacro not respected in included header file #19839

actondev opened this issue May 2, 2024 · 2 comments
Labels
bug Observed behavior contradicts documented or intended behavior

Comments

@actondev
Copy link

actondev commented May 2, 2024

Zig Version

0.12.0

Steps to Reproduce and Observed Behavior

if in build.zig you define something like exe.defineCMacro("NOCPP", "1");and the header file the youcImport` has something like

#ifndef NOCPP
namespace nsfoo {
  struct CppFoo{};
}
#endif

the compilation will fail. However, if before the cImport you use @cDefine("NOCPP", "1");, it works

Expected Behavior

I'd expect the defineCMacro to be respected

@actondev actondev added the bug Observed behavior contradicts documented or intended behavior label May 2, 2024
@ianprime0509
Copy link
Contributor

The comment I left on #19840 applies here as well: -D is also a per-module option, so it needs to be passed to the module that needs it. In your example project, this means replacing exe.defineCMacro("CFOO", "1"); with binding.addCMacro("CFOO", "1");

@actondev
Copy link
Author

actondev commented May 2, 2024

Thank you again! Still need to debug the compiler crashing on me though heh

@actondev actondev closed this as completed May 2, 2024
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
bug Observed behavior contradicts documented or intended behavior
Projects
None yet
Development

No branches or pull requests

2 participants