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

[Arch Linux] compilation fails with "x" not found, did you mean "y"? #72

Open
Fabxx opened this issue Apr 5, 2023 · 4 comments
Open

Comments

@Fabxx
Copy link

Fabxx commented Apr 5, 2023

log:

[  6%] Building CXX object src/CMakeFiles/GGPO.dir/lib/ggpo/bitvector.cpp.o
[ 13%] Building CXX object src/CMakeFiles/GGPO.dir/lib/ggpo/game_input.cpp.o
/home/fabx/Desktop/ggpo/src/lib/ggpo/game_input.cpp: In member function ‘void GameInput::desc(char*, size_t, bool) const’:
/home/fabx/Desktop/ggpo/src/lib/ggpo/game_input.cpp:44:20: error: ‘sprintf_s’ was not declared in this scope; did you mean ‘sprintf’?
   44 |       remaining -= sprintf_s(buf, buf_size, "(frame:%d size:%d ", frame, size);
      |                    ^~~~~~~~~
      |                    sprintf
/home/fabx/Desktop/ggpo/src/lib/ggpo/game_input.cpp:46:20: error: ‘sprintf_s’ was not declared in this scope; did you mean ‘sprintf’?
   46 |       remaining -= sprintf_s(buf, buf_size, "(size:%d ", size);
      |                    ^~~~~~~~~
      |                    sprintf
/home/fabx/Desktop/ggpo/src/lib/ggpo/game_input.cpp:52:18: error: ‘sprintf_s’ was not declared in this scope; did you mean ‘sprintf’?
   52 |          int c = sprintf_s(buf2, ARRAY_SIZE(buf2), "%2d ", i);
      |                  ^~~~~~~~~
      |                  sprintf
/home/fabx/Desktop/ggpo/src/lib/ggpo/game_input.cpp:53:10: error: ‘strncat_s’ was not declared in this scope; did you mean ‘strncat’?
   53 |          strncat_s(buf, remaining, buf2, ARRAY_SIZE(buf2));
      |          ^~~~~~~~~
      |          strncat
/home/fabx/Desktop/ggpo/src/lib/ggpo/game_input.cpp:57:4: error: ‘strncat_s’ was not declared in this scope; did you mean ‘strncat’?
   57 |    strncat_s(buf, remaining, ")", 1);
      |    ^~~~~~~~~
      |    strncat
/home/fabx/Desktop/ggpo/src/lib/ggpo/game_input.cpp: In member function ‘void GameInput::log(char*, bool) const’:
/home/fabx/Desktop/ggpo/src/lib/ggpo/game_input.cpp:65:9: error: ‘strcpy_s’ was not declared in this scope; did you mean ‘strcpy’?
   65 |         strcpy_s(buf, prefix);
      |         ^~~~~~~~
      |         strcpy
/home/fabx/Desktop/ggpo/src/lib/ggpo/game_input.cpp:67:4: error: ‘strncat_s’ was not declared in this scope; did you mean ‘strncat’?
   67 |    strncat_s(buf, ARRAY_SIZE(buf) - strlen(buf), "\n", 1);
      |    ^~~~~~~~~
      |    strncat

@Fabxx Fabxx changed the title [Arch Linux] compilation failes with "x" not found, did you mean "y"? [Arch Linux] compilation fails with "x" not found, did you mean "y"? Apr 5, 2023
@dario-loi
Copy link

dario-loi commented May 22, 2023

Why the problem is happening

These _s functions come from a C standard addition termed as "Annex K", which introduces bound checking interfaces for common standard library functions, which are subfixed with _s (as in safe, secure).

However, Annex K is weird, Windows implemented it, but botched the API, whereas glibc (gcc's standard library) did not even bother, hence your GCC compiler cannot find those functions, they do not exist!

Possible Solution

In order for the application to be portable on compilers other than MSVC, the _s functions could be substituted with either:

  1. Proper, modern C++ alternatives (might prove to be slower)
  2. Their non _s alternative with a macro/preprocessor directive (some level of bounds checking would still be provided on GCC thanks to compiler hardening flags)
  3. A more widely accepted but still safer alternative, e.g.: strncat instead of strcat, snprintf instead of sprintf, etc...

@Fabxx
Copy link
Author

Fabxx commented May 22, 2023

Why the problem is happening

These _s functions come from a C standard addition termed as "Annex K", which introduces bound checking interfaces for common standard library functions, which are subfixed with _s (as in safe, secure).

However, Annex K is weird, Windows implemented it, but botched the API, whereas glibc (gcc's standard library) did not even bother, hence your GCC compiler cannot find those functions, they do not exist!

Possible Solution

In order for the application to be portable on compilers other than MSVC, the _s functions could be substituted with either:

  1. Proper, modern C++ alternatives (might prove to be slower)
  2. Their non _s alternative with a macro/preprocessor directive (some level of bounds checking would still be provided on GCC thanks to compiler hardening flags)
  3. A more widely accepted but still safer alternative, e.g.: strncat instead of strcat, snprintf instead of sprintf, etc...

Already tried to port it on my own but there is a specific winapi function thati can't use or recreate even via wine libs

@dario-loi
Copy link

Do you have a line number for the func?

@Fabxx
Copy link
Author

Fabxx commented May 23, 2023

Do you have a line number for the func?

poll.cpp:18:32: error: ‘CreateEvent’ was not declared in this scope
   18 |    _handles[_handle_count++] = CreateEvent(NULL, true, false, NULL);
      |                                ^~~~~~~~~~~
/home/fabx/Desktop/ggpo/src/lib/ggpo/poll.cpp: In member function ‘bool Poll::Pump(int)’:
/home/fabx/Desktop/ggpo/src/lib/ggpo/poll.cpp:71:10: error: ‘WaitForMultipleObjects’ was not declared in this scope
   71 |    res = WaitForMultipleObjects(_handle_count, _handles, false, timeout);
      |          ^~~~~~~~~~~~~~~~~~~~~~
      ```

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

No branches or pull requests

2 participants