Removing illegal characters from #include

I am new to this forum.I am getting an error in SonarQube- “Remove the illegal characters from this #include.”
For example, I have included a header like :slight_smile:
#include …\a\b.h"

I am not sure if the slash, … etc are causing the issue. How can I remove this error? I tried putting double slash characters

Hi @suresh,

Welcome to the community! :smiley:

When you’re posting an error like this, it helps us get to the root cause more easily if you can give some information like the language you’re using, whether you’re seeing an error in the scan itself or whether SonarQube is raising an issue on your code. But let me try and extrapolate anyway. It looks like you’ve had this C++ rule or its C equivalent raised on an #include statement – is that right?

If so, the rule documentation will lead you in the right direction: you need to remove the slashes and other non-standard characters from your #includes and use your compiler’s include path to tell it where to find the files.

Or if I haven’t guessed correctly :slight_smile: feel free to provide some more information (and log files if appropriate) and let’s see if we can track down the problem.

Regards,

Cameron.

Thank you Cameron for the reply. In my case, SonarQube is raising the issue in code.
The #include in my case is like below for example:

#include …/MyDir/MyInclude.h"

I am including this in one of my source files(c++) . MyInclude.h is placed in a directory called MyDir which is one step back of the original (c++) file that has the include. SonarQube is considering the slash as illegal. That is the is the issue. Is there any workaround?

Hi @suresh,

Can you post the exact line of your include? Because if you’re using backslashes (\) instead of forward slashes (/) this is probably what’s causing the problem. There are a couple of workarounds:

  • Disable the rule in your Quality Profile
  • Mark just this issue as “Won’t fix” in the SonarQube UI

But the most elegant way to handle it is to fix the problem (edit: updated following some input from my C++ expert-level colleagues!): point your compiler include directive (e.g. -I for GCC) to the root of your project and get to the include file top-down using forward slashes:

#include "MyDir/MyInclude.h"

Regards,

Cameron.