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

Compile bug: Compilation fails due to -D_XOPEN_SOURCE=600: error: use of undeclared identifier 'strnlen' #11095

Open
yurivict opened this issue Jan 6, 2025 · 3 comments

Comments

@yurivict
Copy link
Contributor

yurivict commented Jan 6, 2025

Git commit

4418

Operating systems

BSD

GGML backends

CPU

Problem description & steps to reproduce

This -D_XOPEN_SOURCE=600 argument breaks compilation:

In file included from /usr/ports/misc/llama-cpp/work/llama.cpp-b4418/ggml/src/ggml-vulkan/ggml-vulkan.cpp:8:
/usr/local/include/vulkan/vulkan.hpp:145:41: error: use of undeclared identifier 'strnlen'
  145 |       return std::string( this->data(), strnlen( this->data(), N ) );
      |                                         ^

The same argument is set in cmake scripts as well.

Please don't fix POSIX support at random ancient levels.

In general it shouldn't be necessary to ever set _XOPEN_SOURCE.

FreeBSD 14.2

First Bad Commit

n/a

Relevant log output

n/a
@ggerganov
Copy link
Owner

Can you check if #11103 fixes the build using CMake?

@noirsabb
Copy link

noirsabb commented Jan 7, 2025

Hi. I had the same compilation problem under FreeBSD 14.2. #11103 did not correct the compilation error for me. Following the suggestions the following did (for me)

File

[llama.cpp]/ggml/src/CMakeLists.txt

# Somehow in OpenBSD whenever POSIX conformance is specified # some string functions rely on locale_t availability, # which was introduced in POSIX.1-2008, forcing us to go higher if (NOT (CMAKE_SYSTEM_NAME MATCHES "FreeBSD")) if (CMAKE_SYSTEM_NAME MATCHES "OpenBSD") add_compile_definitions(_XOPEN_SOURCE=700) else() add_compile_definitions(_XOPEN_SOURCE=600) endif() endif()

Of course your style may vary.

File

[llama.cpp]//Makefile

setup MK_CPPFLAGS similarly to the above so that may require review, too.

NS

@yurivict
Copy link
Contributor Author

yurivict commented Jan 7, 2025

You should just remove all _XOPEN_SOURCE options, and let the broken systems be fixed instead.

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

No branches or pull requests

3 participants