VS code: identifier "MODULE_NAME" is undefined

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:

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:

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:

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.

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.

The module name is generated for the compiler command line from the cmake/px4_add_module.cmake 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?

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 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.

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:

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.

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