FreeRTOS, Eclipse IDE, and Syntax Errors - c

I have a slight annoyance when dealing with FreeRTOS code in Eclipse and I'm not sure if it's just me or if other people have this issue too but I see a lot of syntax errors highlighted in my code but it compiles/executes fine. The syntax errors seem to be caused by FreeRTOS specific code like:
signed portCHAR *x;
or
vSemaphoreCreateBinary (semaphore);
or
signed portBASE_TYPE gpsTaskStart (void)
{
return xTaskCreate (vGPSTask, (const signed portCHAR * const) "GPS", configMINIMAL_STACK_SIZE, NULL, (tskIDLE_PRIORITY + 1), &taskHandles [TASKHANDLE_GPS]);
}
I was wondering if there was a way to configure Eclipse to parse this syntax properly.

I think you just have to update your Eclipse project configuration for the incremental checker to be able to find FreeRTOS symbol definitions.
Right click on your project > Properties > C/C++ General > Path and Symbols > Includes.
Add the FreeRTOS folder there.

Go to project settings > directories and include all directories containing .h files (including portable/GCC/%yourplatform%). Once done, make a build. This should work, at least works for me.

Related

Visual Studio Open Folder GCC (Cygwin) Intellisense Errors

I'm trying to configure Visual Studio Community 2019 for use as the IDE for work on an open source C project targeting the Nintendo 64.
The makefile seems to define a gcc-derivative (mips64-elf-gcc) as the compiler and has -std=gnu99 as one of the CFLAGS, so I assume that means this is C99.
I don't know much about C development, so I initially followed a tutorial, which directed me to set up Cygwin. For a time I edited the *.h and *.c files in Notepad++ and then used the Cygwin terminal to compile everything (there's probably a thousand better ways, but I'm a C/*nix nub and just wanted to get something off the ground quickly). Notepad++ was ok just to tinker around with things, but I'm getting more serious about this project and doing any real work in Notepad++ is a real bother. I've used Visual Studio for a long time, so I figured I'd try getting things set up there, since I know it has support for C/C++.
I've successfully gotten VS to run my makefile using the "Open Folder" feature and by wiring up the requisite data within the CppProperties.json and tasks.vs.json files. While attempting to get IntelliSense working, however, I've run into a few errors that I can't resolve.
1. 'duplicate parameter name' in stdio.h & string.h
There are several instances of this error. The problem seems to be lines like this one:
FILE * freopen (const char *__restrict, const char *__restrict, FILE *__restrict);
As you can see, there are multiple "parameters" all named __restrict. I'm still just beginning my C journey, so I'm not entirely sure what this is, but my suspicion was that it wasn't a parameter name, but might be #defineed somehwere. Using the Agent Ransack file search utility, I looked for instances of #define __restrict and did find some. I added those paths to the INCLUDE section of my CppProperties.json file, but that didn't help at all.
According to the VS Open Folder tutorial, IntelliSense can sometimes get hung up on preprocessor directives, so I added the recommended cpp.hint file, closed VS, deleted cached data in the .vs folder, and started VS back up, but the errors still persist.
2. "expected a ')'" in stdio.h
I assume this one is also related to that __restrict issue.
FILE * fopen (const char *__restrict _name, const char *__restrict _type);
^
| expected a ')'
It seems to be unhappy about the _name parameter for some reason.
3. 'expected an expression / identifier "i" is undefined' in my for loops
Any place in the code I've been working on where a for loop is defined, I get these errors. Here's an example of the errors:
void v(void)
{
for (int i = 0; i < 25; i++)
{ ^ ^
| | identifier "i" is undefined
|
| expected an expression
}
}
If, however, I change the loop to the following, everything is fine.
void v(void)
{
int i;
for (i = 0; i < 25; i++)
{
}
}
It's not liking the int type declaration in in the init-expression of the for loop. I'm not sure what I could've done in configuration to break a core language feature. I assume something about the previous errors are affecting this.
None of this affects the build process, since all of that is still being done through the makefile using everything I have set up in Cygwin, so I guess it isn't critical to fix these issues, but the whole point of doing this was to have a nice environment to work in and having 61 errors constantly hanging out is probably gonna put a pretty big damper on that situation.
I've tried everything I can think of to resolve these issues and nothing has worked. This is a particularly difficult issue to google, due to the large number of potential contributing factors required as search terms, so that hasn't proved fruitful.
Any help or advice is appreciated.

Eclipse CDT indexer complains about C build-ins as unresolved symbols

I have a GCC C based project in Eclipse CDT (Oxygen). In the Problems window, when I go I open C file in the main editor window, it lists bunch of unresolved symbols errors, many for the C and C library built-ins, like __func__.
If I understand it right this is Eclipse' indexer error, as the code compiles & builds fine.
So this is just more of annoyance issue with my Eclipse setup I want to remove. I cannot figure out what is the issue with it however. I've re-indexed N times, double checked includes, compiler / toolchain paths, still doesn't work.
The error(s) would be like:
Symbol '"__func__' could not be resolved
...
Symbol '__asm__ could not be resolved
__func__ is C standard, __asm__ is GCC/GNU keyword..
I tried something from here : https://www.eclipse.org/forums/index.php/t/636348/
no luck.
Anyone knows how to fix the indexer here? Sometimes it also fails to resolve include paths of standard C headers, even though again, the code builds just fine.

Eclipse CDT: Glib headers not parsed correctly

I am developing a C application, and using Eclipse CDT IDE, which I find great. The project uses Glib,Gtk,and GStreamer , so whenever I use some of their features in a file, I need to include:
#include <glib.h>
#include <gtk/gtk.h>
#include <gst/gst.h>
The code compiles without any error, since the PATH variable to search those headers is set correctly in a CMakeLists.txt.
However, while working on the project, I found annoying errors highlighting in my code, regarding type definitions like gchar or GValue or GTKApplication; the error outlined is "symbol **** could not be resolved". These definitions are inside a header file that my Eclipse IDE cannot find (included by glib.h), if not at compile time (indeed the program compiles correctly). Instead, the type GError , defined in gst.h , is not highlighted as an error by the pre-compiler.
I would like then that my Eclipse IDE could search on nested headers (#include inside an #inlcude inside...) to find those type definition, in order so to not have those annoying errors highlighting. How can I do so? I would not like to have to include directly all files where the type definitions are done.
EDIT: As Jonah Graham outlined, the problem is not beacuse Eclispe does a "single-step research" on the headers, since it inspects includes inside other includes like any other IDE. It is a CMake bug with c and Eclipse
Thanks in advance.
The problem you are facing is a CMake bug*. CMake adds __cplusplus into the defined symbols unconditionally, which means that glib headers are not parsed properly when in C mode. You can see this clearly by opening gmacros.h around the definition for G_BEGIN_DECLS:
Because CMake told CDT __cplusplus is defined, it thinks G_BEGIN_DECLS is also defined, which makes code like this from gtypes.h parse incorrectly:
G_BEGIN_DECLS
/* Provide type definitions for commonly used types.
* These are useful because a "gint8" can be adjusted
* to be 1 byte (8 bits) on all platforms. Similarly and
* more importantly, "gint32" can be adjusted to be
* 4 bytes (32 bits) on all platforms.
*/
typedef char gchar;
...
Of course with no gchar defined, everything else is going to go badly.
Luckily there is a quick workaround until the problem is resolved in CMake, remove __cplusplus from the info in CDT.
Open Project Properties
C/C++ Include Paths and Symbols
Remove __cplusplus from the list and press OK
(sometimes necessary) Right-click on project -> Index -> Rebuild
* There may be some other workarounds if you know CMake better. The bug says also it will be fixed for the next release of CMake.

Where is UNS_32 defined?

I'm using Doxygen on a client's source code and Doxygen can't find a symbol UNS_32.
The client's code compiles without errors using the GNU ARM compiler.
I have searched the client's code base and can't find the definition of UNS_32.
I searched the GNU ARM source code tree and can't find it either.
So, where is the symbol UNS_32 defined?
*Note: I'm not looking for the meaning. I want the definition so I can put it in my Doxygen configuration file. *
Example usage:
void lpc_heap_init (void *base_addr, UNS_32 heap_size);
It is defined in lpc_types.h
http://code.google.com/p/32bitmicro/source/browse/trunk/src/nxp/lpc17xx/LPC1700CMSIS/Drivers/include/lpc_types.h?spec=svn226&r=226
/** SMA type for 32 bit unsigned value */
typedef uint32_t UNS_32;
You need also to search and headers in paths specified to the compiler with -I options. You can similarly specify these in Doxygen.
My preferred approach is to use Visual Studio, create a "Makefile Project", add the sources and copy all the project's command line defined macros and include paths to the project settings, then let the Intellisense simplify code navigation - it is a simple case of right-clicking the symbol, and selecting "Goto Definition", or using the "Code Definition" window which shows the defining source for any symbol you place the cursor on. You could even set up the project to actiually build the code too.

Why does Eclipse CDT say: 'syntax error', but compilation no problem

I am working in existing C code which has a couple of lines with statements similar to this one:
struct collect_conn *tc = (struct collect_conn *)
((char *)c - offsetof(struct collect_conn, runicast_conn));
The struct collect_conn goes along the following lines:
struct collect_conn {
struct runicast_conn runicast_conn;
struct announcement announcement;
const struct collect_callbacks *cb;
struct ctimer t;
uint16_t rtmetric;
uint8_t forwarding;
uint8_t seqno;
};
I am using Eclipse CDT, and it marks the line with an orange squiggly line as 'syntax error'. I think it is marked as such by the CDT indexer.
However, compilation (manually in a terminal) is no problem.
This is a bit inconvenient however, since the elements on the line don't get indexed (so the call hierarchy tree isn't always correct, or the highlighting of elements, etc.)
Why does Ecipse not like the line as it is?
Eclipse CDT contains its own preprocessor/parser for analyzing your code and building an index. However, when you invoke a build CDT calls out to your system compiler, like gcc for example. There may be minor differences between the syntax accepted by the CDT parser and the syntax accepted by your compiler. When this happens the CDT parser can get confused.
On my system the offsetof macro expands into an expression that uses the __offsetof__ keyword. This keyword isn't recognized by CDT so that's why there's a syntax error. To deal with this problem the CDT parser has a macro built in to deal with __offsetof__ which looks like this:
#define __offsetof__(x) (x)
This doesn't appear to be correct, at least on my system the result is the removal of the __offsetof__ keyword from the source which still leads to a syntax error.
I was able to get rid of the syntax error by going to the Paths and Symbols property page and adding a macro for __offsetof__ which maps to 'foo'. This tricks the parser into thinking its just a call to a function it hasn't seen before, but not a syntax error.
Alternatively you can turn off syntax error reporting in the editor by going to Window > Preferences > General > Editors > Text Editors > Annotations and unchecking all the checkboxes for C/C++ Indexer Markers.
I've fixed problem in eclipse CDT with Preferences->C/C++->Language Mappings : Add
Content Type : C-header
Language : C++
Sometimes, although the code compiles with no error, eclipse CDT's real-time code analyzer shows some errors in C/C++ files (eg. 'Function xxx could not be resolved). This is because eclipse CDT uses its own preprocessor/parser for analyzing the code and building the indexes instead of the MinGW's one (or any other GNU compiler). In order to fix this globally for all eclipse projects in the workspace, follow these steps:
(In order to fix this only for a specific project, follow steps 1, 2 and 4 in menu 'Project->Preferences')
1-In menu 'Window->Preferences->C/C++->Language Mappings', add the correct mappings as shown in below: (eg. for content types: C++ Source/Header File, use GNU C++ language and so on)
2-In menu 'Window->Preferences->C/C++->Indexer', set full indexing by checking all checkboxes (but not 'Skip' ones) as shown in below:
3-In each project's specific properties, menu 'Project->Properties->C/C++ general->Indexer', Uncheck 'Enable project specific settings' as shown in below:
4-Rebuild the indexing, menu 'Project->C/C++ Index->Rebuild'.
It seems the CDT parser doesn't like the portion offsetof(struct ...).
If you declare collect_conn using a typedef the error goes away. At least for me, the following code works:
typedef struct {
struct runicast_conn runicast_conn;
struct announcement announcement;
const struct collect_callbacks *cb;
struct ctimer t;
uint16_t rtmetric;
uint8_t forwarding;
uint8_t seqno;
} collect_conn;
...
struct collect_conn *tc = (struct collect_conn *)
((char *)c - offsetof(collect_conn, runicast_conn));
If you can't change the original declaration do something like this:
typedef struct collect_conn collect_conn_t;
It might be confused, check if you have a definition of offsetof in-scope, for instance. Otherwise you might try simplifying the expression, breaking it up using e.g. a #define with the offset of, or something.
I'm thinking the compiler might provide a built-in version of offsetof, while Eclipses's compiler/code-parser might not. If so, you would need to make sure you have the definition, for Eclipse to be able to properly parse your code.
try switching the indexer to "Full c/C++ indexer (complete parse)" in Preferences->c/C++ -> indexer
Iv got the same problem. There is 2 definition of offsetof (one for C and one for C++). IMO the problem come from that
For example if i type
#ifndef __cplusplus
#endif
Eclipse will grey it. It mean __cplusplus is defined, but my project is a C
Unfortunatly i dont find a fix.
I fixed similar problem after checking the tab Error Parsers in Makefile Project in New CDT Project Wizard, removing CDT Visual C Error Parser (I am using gcc)
I ended up solving the problem like this. First I opened the project properties, then the C/C++ general->Paths and Symbols category. Under the Symbols tab I added this entry:
Symbol: offsetof(TYPE,MEMBER)
Value: ((ssize_t) &((TYPE *)0)->MEMBER)
These symbols are used by the indexer but not passed to the compiler (at least in Makefile projects, I haven't tried it in the other kind of C project), so it doesn't override GCC's built-in offsetof
I've seen Eclipse do this some times, and I use it for Java. Usually closing and opening the file again fixes it for me (resets whatever is wrong). It usually seems to be an error that WAS there but has been fixed and the "error cache" isn't updated correctly.

Resources