# VS code: identifier "MODULE\_NAME" is undefined

**URL:** <https://discuss.px4.io/t/vs-code-identifier-module-name-is-undefined/22896>\
**Category:** Uncategorized\
**Created:** [June 18, 2021, 1:03pm UTC](https://discuss.px4.io/t/vs-code-identifier-module-name-is-undefined/22896 "2021-06-18T13:03:43Z")\
**Posts on this page:** 6\
**Page:** 1

<div class="post-metadata">

**Author:** ![robwaat](https://discuss.px4.io/letter_avatar_proxy/v4/letter/r/50afbb/32.png) [@robwaat](https://discuss.px4.io/u/robwaat)\
**Post date:** [June 18, 2021, 1:03pm UTC](https://discuss.px4.io/t/vs-code-identifier-module-name-is-undefined/22896/1 "2021-06-18T13:03:43Z")

</div>

Hi,

I have been able to install the development tool chain / environment and build the `px4_fmu-v5_default` target successfully from the command line, under the `v1.12.0-beta5` git tag.

However, despite the successful build, VS code error highlighting suggests there are problems in calls to the `MODULE_NAME` definition as part of `px4::WorkItem::WorkItem()` in most module initialization calls.  
For example, this occurs within the code snippet from `src/modules/mc_rate_control/MulticopterRateControl.cpp` below:

```auto
MulticopterRateControl::MulticopterRateControl(bool vtol) :
	ModuleParams(nullptr),
	WorkItem(MODULE_NAME, px4::wq_configurations::rate_ctrl),
	_actuators_0_pub(vtol ? ORB_ID(actuator_controls_virtual_mc) : ORB_ID(actuator_controls_0)),
	_loop_perf(perf_alloc(PC_ELAPSED, MODULE_NAME": cycle"))
{
	_vehicle_status.vehicle_type = vehicle_status_s::VEHICLE_TYPE_ROTARY_WING;

	parameters_updated();
}

```

The error message here is:

```auto
identifier "MODULE_NAME" is undefined C/C++(20)

px4::WorkItem::WorkItem(const char *name, const px4::wq_config_t &config)
+4 overloads

```

The problem is also highlighted in calls to the px4 logging functions (i.e. `PX4_ERR()` and `PX4_WARN()`). In this case the error message is:

```auto
identifier "MODULE_NAME" is undefined C/C++(20)
#define PX4_WARN(FMT, __VA_ARGS__...) __px4_log_modulename(_PX4_LOG_LEVEL_WARN, FMT, ##__VA_ARGS__)

Expands to:
__px4_log_modulename(_PX4_LOG_LEVEL_WARN, "%s\n",reason)

```

I believe this is some kind of config problem within the VS code error highlighting or include path settings, but I have not altered the stock configuration.

Does anyone know what might be causing this, or if there is a simple fix that I’m missing?

Thanks for your help,  
Robert.

---

<div class="post-metadata">

**Author:** ![robwaat](https://discuss.px4.io/letter_avatar_proxy/v4/letter/r/50afbb/32.png) [@robwaat](https://discuss.px4.io/u/robwaat)\
**Post date:** [June 18, 2021, 1:33pm UTC](https://discuss.px4.io/t/vs-code-identifier-module-name-is-undefined/22896/2 "2021-06-18T13:33:54Z")

</div>

On re-opening VS code, the CMake tools extension throws the following error message.

> The path to the compiler for one or more source files was not found in the CMake cache.  
> If you are using a toolchain file, this probably means that you need to specify the CACHE option when you set your C and/or C++ compiler path

This may also be part of the issue. I don’t know enough about the developer tool set to resolve it myself.

---

<div class="post-metadata">

**Author:** ![Danduril](https://discuss.px4.io/user_avatar/discuss.px4.io/danduril/32/10295_2.png) [@Danduril](https://discuss.px4.io/u/Danduril)\
**Post date:** [June 18, 2021, 5:45pm UTC](https://discuss.px4.io/t/vs-code-identifier-module-name-is-undefined/22896/3 "2021-06-18T17:45:36Z")

</div>

The module name is generated for the compiler command line from the [c`make/px4_add_module.cmake`](https://github.com/PX4/PX4-Autopilot/blob/b1829e576655916099b7a5ba355ac94183653840/cmake/px4_add_module.cmake#L188) script. I’m not familiar with VS code syntax checker. Does it use the `compile_commands.json` file that CMake creates in the build dir (e.g., `build/px4_sitl_default/compile_commands.json`)? My syntax checker expects it to be in the source root so I have to make link. Perhaps VS code uses `CMakeCache.txt` directly and your config isn’t pointing to it correctly?

---

<div class="post-metadata">

**Author:** ![robwaat](https://discuss.px4.io/letter_avatar_proxy/v4/letter/r/50afbb/32.png) [@robwaat](https://discuss.px4.io/u/robwaat)\
**Post date:** [June 22, 2021, 1:43pm UTC](https://discuss.px4.io/t/vs-code-identifier-module-name-is-undefined/22896/4 "2021-06-22T13:43:48Z")

</div>

Thanks for your reply.

I can see the `cmake/px4_add_module.cmake` script you mention does include references to the `MODULE_NAME` within the `target_compile_definitions()` function. I can also see multiple `#define` mentions of the parameter within the `platforms/common` and `boards` directories.

I can also locate the `CMakeCache.txt` file within `build/px4_fmu-v5_default/CMakeCache.txt`, but I don’t know enough about the tools to say if VS code uses this directly or otherwise.

Likewise, I’m of limited use in answering your other questions about `compile_commands.json`. I have a fair amount of general coding experience, but I am still new to Px4 development and many of the tools are unfamiliar.

Others appear to have encountered a similar issue with the CMake tools extension and Px4, but the [forum post](https://discuss.px4.io/t/cmake-tools-error-path-to-compiler/17995) does not contain a workable solution. I’m still not sure how related this is to my main problem with the `MODULE_NAME` error message.

---

<div class="post-metadata">

**Author:** ![robwaat](https://discuss.px4.io/letter_avatar_proxy/v4/letter/r/50afbb/32.png) [@robwaat](https://discuss.px4.io/u/robwaat)\
**Post date:** [July 1, 2021, 2:09pm UTC](https://discuss.px4.io/t/vs-code-identifier-module-name-is-undefined/22896/5 "2021-07-01T14:09:20Z")

</div>

After a little more poking around, I think this is ultimately a problem with the stock VS code C/C++ extension configuration.

Changing the `C_Cpp.intelliSenseEngine` to `Tag Parser` within `.vscode/settings.json` seems to have helped remove a the error messages observed in my original post relating to the `MODULE_NAME` definition.

However, with this setup intelliSense struggles to locate built uORB message headers such as `#include <uORB/topics/manual_control_setpoint.h>`. In this case it displays the info message as below:

```auto
Include file not found in browse.path.

```

I attempted to solve this by with the addition of the following to `.vscode/settings.json`, but it does not appear to have helped.

```json
"C_Cpp.default.browse.path": ["${workspaceFolder}/ **", "${workspaceFolder}/build/px4_fmu-v5_default/**"]

```

---

<div class="post-metadata">

**Author:** ![robwaat](https://discuss.px4.io/letter_avatar_proxy/v4/letter/r/50afbb/32.png) [@robwaat](https://discuss.px4.io/u/robwaat)\
**Post date:** [July 30, 2021, 2:48pm UTC](https://discuss.px4.io/t/vs-code-identifier-module-name-is-undefined/22896/6 "2021-07-30T14:48:33Z")

</div>

I seem to have resolved this, though I’m still not 100% on what the problem actually was.

It was likely to have been an issue with my configuration of the recommended VS Code extensions.

Moving to checkout the stable `v1.12.0` release and reverting `.vscode/c_cpp_properties.json` to stock settings, I successfully built the `px4_stil` and `px4_fmu-v5_default` targets via the command line as before.

I then set the `CMake build variant` to `px4_sitl` and the `active kit` to `Px4 detect` in the toolbar at the bottom of the VS code window, as pictured.  
 ![image](https://discuss.px4.io/uploads/default/original/2X/8/8af7002f56ac2b47037df6525669eae10e3d11c2.png)

After closing and re-opening VS Code, then allowing the intellisense parser some time to finish working (indicated by the cylinder icon to the right of the bottom toolbar), the errors indicated in my initial post are now gone.

Hopefully this helps someone else in the same situation.
