Tag Archives: C&C++

[Solved] Linux Compile Error: error: ‘for’ loop initial declarations are only allowed in C99 mode

1. Problem description

During the development of embedded Linux, compile and report the following errors

src/util/Vector.c:94:9: error: ‘for’ loop initial declarations are only allowed in C99 mode
         for (int j = V->length++; j > i; j--)
         ^
src/util/Vector.c:94:9: note: use option -std=c99 or -std=gnu99 to compile your code
src/util/Vector.c: In function ‘Vector_remove’:
src/util/Vector.c:123:9: error: ‘for’ loop initial declarations are only allowed in C99 mode
         for (int j = i; j < V->length; j++)
         ^

2. Problem analysis

GCC compilation is based on compilation lower than C99 standard. Defining variables within a for loop is not allowed in standards lower than C99.

3. Solution

Method 1

Modify code

int j;
for (j = i; j < V->length; j++)

Method 2

GCC specifies compiling using the C99 standard

gcc -std=c99

Method 3

Specify the C99 standard for compilation in makefile

CFLAGS += -std=c99

In windows, “cmake” is not an internal or external command, nor a runnable program or batch file.

1、 Problem description.

An error is reported when cmake is performed under Windows: ‘cmake’ is not an internal or external command, nor is it a runnable program or batch file.

2、 Problem analysis.

Lack of tool cmake.

3、 Solutions.

Install cmake. website: https://cmake.org/download/

When installing cmake, choose to add environment variables.

 

Error c3861: “strcasecmp”: identifier not found

1、 Problem description.

The C/C + + program compiles normally in Linux, and an error is reported in Windows: error c3861: “strcasecmp”:   Identifier not found.

2、 Problem analysis.

There is no library function related to strcasecmp in windows.

3、 Solutions.

Declare the library function of strcasecmp under windows.

#ifdef _WIN32
	//#define strcasecmp _stricmp
	//#define strncasecmp _strnicmp
#endif
#ifdef _MSC_VER
	#define strcasecmp _stricmp
	#define strncasecmp _strnicmp
#endif

 

How to Fix Error sal.h(2367)

Error:

1>C:\Program Files (x86)\Microsoft Visual Studio 11.0\VC\include sal.h(2367): error C2143: syntax error: missing ‘;’ before ‘string’

C:\Program Files (x86)\Microsoft Visual Studio 11.0\VC\include\sal.h(2367): error C2059:Syntax error: ‘string’

C:\Program Files (x86)\Microsoft Visual Studio 11.0\VC\include sal.h(2367): error C2143: syntax error: missing ‘;’ before ‘{‘

C:\Program Files (x86)\Microsoft Visual Studio 11.0\VC\include sal.h(2367): error C2447: ‘{‘: missing function header(Old Formal List?)

I can’t believe you forgot the semicolon after the class statement;