Skip to main content

W0057 - Undefined macro

Error

-module(example).

foo() ->
?UNDEFINED_MACRO.
%% ^^^^^^^^^^^^^^^^ error: W0057: undefined macro 'UNDEFINED_MACRO'

bar(X) ->
?UNDEFINED_WITH_ARGS(X, 42).
%% ^^^^^^^^^^^^^^^^^^^^ error: W0057: undefined macro 'UNDEFINED_WITH_ARGS/2'

This diagnostic is triggered when a macro usage cannot be resolved in ELP native diagnostic processing. The macro is referenced in the code but has not been defined in the current file or any included header files.

Important: This diagnostic corresponds to Erlang service diagnostics E1507 (for macros without arguments) and E1508 (for macros with arguments). W0057 only appears when the corresponding Erlang service diagnostic does not appear. If you see W0057 in a Buck project, it is likely a sign that the project is not defined properly in your TARGETS/BUCK file.

Common Causes

  1. Missing macro definition: The macro has not been defined with -define().
  2. Missing include file: The macro is defined in a header file that has not been included.
  3. Typo in macro name: The macro name is misspelled.
  4. Conditional compilation: The macro is defined within a conditional block (e.g., -ifdef()) that is not active.

Fix

Define the macro

If the macro is not defined anywhere, add a -define() directive:

-module(example).

-define(UNDEFINED_MACRO, 42).
-define(UNDEFINED_WITH_ARGS(X, Y), X + Y).

foo() ->
?UNDEFINED_MACRO.

bar(X) ->
?UNDEFINED_WITH_ARGS(X, 42).

Include the header file

If the macro is defined in a header file, add the appropriate -include() or -include_lib() directive:

-module(example).

-include("macros.hrl").

foo() ->
?UNDEFINED_MACRO.

Fix typos

If the macro name is misspelled, correct it to match the definition:

-module(example).

-define(DEFINED_MACRO, 42).

foo() ->
?DEFINED_MACRO. % Fixed typo

Relationship to Erlang Service Diagnostics

W0057 is filtered out when the Erlang service reports the corresponding diagnostics:

  • E1507: undefined macro (without arguments)
  • E1508: undefined macro (with arguments)

When both diagnostics detect the same issue, only the Erlang service diagnostic will be shown to avoid duplication.

Buck Project Configuration

If you see W0057 in a Buck project, this typically indicates that your TARGETS file is not properly configured. The Erlang service relies on Buck to understand the project structure, dependencies, and include paths. Check that:

  • All application dependencies are declared in the deps attribute
  • Include paths are properly configured
  • The macro definition is in an accessible dependency