serge1 / ELFIO

ELFIO - ELF (Executable and Linkable Format) reader and producer implemented as a header only C++ library
http://serge1.github.io/ELFIO
MIT License
706 stars 152 forks source link

No adhering to ISO C++ #122

Closed pmor13 closed 11 months ago

pmor13 commented 1 year ago

The elfio.pdf says:

Adhering to ISO C++

Well, ISO C++ does not have strnlen.

Hence an ISO C++ compiler (e.g. g++ -std=c++17) won't build ELFIO:

./elfio/elfio_strings.hpp: In instantiation of ‘const char* ELFIO::string_section_accessor_template<S>::get_string(ELFIO::Elf_Word) const [with S = ELFIO::section; ELFIO::Elf_Word = unsigned int]’:
./elfio/elfio.hpp:521:54:   required from here
./elfio/elfio_strings.hpp:49:28: error: ‘strnlen’ was not declared in this scope; did you mean ‘strlen’?
   49 |                     strnlen( data + index, string_section->get_size() - index );
      |                     ~~~~~~~^~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~
      |                     strlen
serge1 commented 1 year ago

Hi,

The function is not a part of C++ standard, but, it is a part of POSIX.

I was not able to get this error when using the following command line: g++-12 -std=c++17 -Wall -Wextra -pedantic -Werror -I../.. elfdump.cpp -o elfdump

The library was checked by g++, clang++ and MSVS C++ compilers on Intel processors. What processor architecture you compile for?

In GNU header file string.h, availability of strnlen() is managed by define __USE_XOPEN2K8. Please see dedicated thread at StackOverflow

serge1 commented 1 year ago

Due to no activity, I'm closing the issue. Feel free to reopen if required.

pmor13 commented 1 year ago

Consider avoiding extensions. An ISO C++ compiler is not required to support extensions.

On Sun, Jul 23, 2023, 3:58 PM Serge Lamikhov-Center < @.***> wrote:

Closed #122 https://github.com/serge1/ELFIO/issues/122 as completed.

— Reply to this email directly, view it on GitHub https://github.com/serge1/ELFIO/issues/122#event-9892735352, or unsubscribe https://github.com/notifications/unsubscribe-auth/ABDAC232KM5SOND6RNOIIZTXRUNX5ANCNFSM6AAAAAAXO7YAOI . You are receiving this because you authored the thread. Message ID: @.***>

serge1 commented 11 months ago

The issue is addressed in commit 089160c