Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Build error on GCC 4.8.5 #3048

Closed
maxsharabayko opened this issue Oct 10, 2024 · 6 comments · Fixed by #3060
Closed

Build error on GCC 4.8.5 #3048

maxsharabayko opened this issue Oct 10, 2024 · 6 comments · Fixed by #3060
Labels
[core] Area: Changes in SRT library core Type: Bug Indicates an unexpected problem or unintended behavior
Milestone

Comments

@maxsharabayko
Copy link
Collaborator

Compiler: gcc (GCC) 4.8.5 20150623 (Red Hat 4.8.5-44)

/srt/haicrypt/cryspr.c: In function 'crysprFallback_MsEncrypt':
/srt/haicrypt/cryspr.c:473:6: error: 'for' loop initial declarations are only allowed in C99 mode
      for (size_t i = 0; i < sizeof(aad) / 4; ++i)
      ^
/srt/haicrypt/cryspr.c:473:6: note: use option -std=c99 or -std=gnu99 to compile your code
/srt/haicrypt/cryspr.c: In function 'crysprFallback_MsDecrypt':
/srt/haicrypt/cryspr.c:619:7: error: 'for' loop initial declarations are only allowed in C99 mode
       for (size_t i = 0; i < sizeof(aad) / 4; ++i)

Introduced in PR #2962.

@maxsharabayko maxsharabayko added Type: Bug Indicates an unexpected problem or unintended behavior [core] Area: Changes in SRT library core labels Oct 10, 2024
@maxsharabayko maxsharabayko added this to the v1.5.4 milestone Oct 10, 2024
@maxsharabayko
Copy link
Collaborator Author

A current workaround is to add -DCMAKE_C_FLAGS='-std=c99' to the cmake command.
I think -std=c99 can be made default in the CMake file of srt.
Or take the initialization out of the for loop.

@ethouris
Copy link
Collaborator

As per compiler requirements, gcc 4.8.0 could be the oldest supported from this line and it supports C99. It can be kinda complicated, but I think it's worth it.

Do not use -std=c99. Be more portable, at least for cmake older than 3.1.

@maxsharabayko
Copy link
Collaborator Author

So C_STANDARD if CMake >= 3.1, else set (CMAKE_C_FLAGS .... -std=c99) or list(APPEND SRT_EXTRA_CFLAGS "-std=c99")

@maxsharabayko
Copy link
Collaborator Author

maxsharabayko commented Oct 10, 2024

Hm, CXX_STANDARD seems to be introduced in CMake 3.1, but we use it in this macro without any check for CMake version:

if (CMAKE_MAJOR_VERSION LESS 3)
	set (FORCE_CXX_STANDARD_GNUONLY 1)
endif()

macro(srt_set_stdcxx targetname spec)
	set (stdcxxspec ${spec})
	if (NOT "${stdcxxspec}" STREQUAL "")
		if (FORCE_CXX_STANDARD_GNUONLY)
			target_compile_options(${targetname} PRIVATE -std=c++${stdcxxspec})
			message(STATUS "C++ STD: ${targetname}: forced C++${stdcxxspec} standard - GNU option: -std=c++${stdcxxspec}")
		else()
			set_target_properties(${targetname} PROPERTIES CXX_STANDARD ${stdcxxspec})
			message(STATUS "C++ STD: ${targetname}: forced C++${stdcxxspec} standard - portable way")
		endif()
	else()
		message(STATUS "APP: ${targetname}: using default C++ standard")
	endif()
endmacro()

@maxsharabayko
Copy link
Collaborator Author

maxsharabayko commented Oct 10, 2024

A similar macro to set CSTD standard:

macro(srt_set_stdc targetname spec)
	set (stdcspec ${spec})
	if (NOT "${stdcspec}" STREQUAL "")
		if (CMAKE_MAJOR_VERSION LESS 3)
			target_compile_options(${targetname} PRIVATE -std=c${stdcspec})
			message(STATUS "C STD: ${targetname}: forced C${stdcxxspec} standard - GNU option: -std=c${stdcspec}.")
		else()
			set_target_properties(${targetname} PROPERTIES C_STANDARD ${stdcspec})
			message(STATUS "C STD: ${targetname}: forced C${stdcxxspec} standard - portable way.")
		endif()
	else()
		message(STATUS "APP: ${targetname}: using default C standard.")
	endif()
endmacro()

@ethouris
Copy link
Collaborator

You can make a common version with additional variable to specify whether C or C++.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
[core] Area: Changes in SRT library core Type: Bug Indicates an unexpected problem or unintended behavior
Projects
None yet
Development

Successfully merging a pull request may close this issue.

2 participants