libc functions from c++ issues

Karel Gardas karel at functional.vision
Tue Apr 12 07:18:21 UTC 2022


Not sure, but isn't usage of C headers in C++ deprecated for a long time 
now? Shouldn't you use csignal and cstdlib? Newlib provided for RTEMS 
looks to push that even a bit further by providing C++ specific stdlib.h 
(in include/c++ and in include/c++/tr1) which just includes cstdlib and 
exports symbols out from std name space and this way basically hides C 
specific stdlib.h

I'd bet newlib is more correct here, but I'm no expert...

Anyway in the c++/newlib case and if you really insist on c++ compiler 
here, have you tried to use include_next trick by defining 
_GLIBCXX_INCLUDE_NEXT_C_HEADERS? See include/c++/stdlib.h from tools...

Karel

On 4/12/22 08:44, Chris Johns wrote:
> Hi,
> 
> The following code:
> 
> // aarch64-rtems6-g++ -std=c++98 -c test.o test.cpp
> // aarch64-rtems6-g++ -std=c++03 -c test.o test.cpp
> // aarch64-rtems6-g++ -std=c++11 -c test.o test.cpp
> // aarch64-rtems6-g++ -std=c++17 -c test.o test.cpp
> #include <signal.h>
> #include <stdlib.h>
> void t1(pthread_t thread) {
>    ::setenv("ABC", "123", 0);
>    ::pthread_kill(thread, SIGINT);
> }
> 
> produces:
> 
> $ arm-rtems6-g++ -std=c++17 -c -o test.o test.cpp
> 
> 
> 
> 
> 
> 
> test.cpp: In function 'void t1(pthread_t)':
> test.cpp:8:5: error: '::setenv' has not been declared; did you mean 'getenv'?
>      8 |   ::setenv("ABC", "123", 0);
>        |     ^~~~~~
>        |     getenv
> test.cpp:9:5: error: '::pthread_kill' has not been declared; did you mean
> 'pthread_key_t'?
>      9 |   ::pthread_kill(thread, SIGINT);
>        |     ^~~~~~~~~~~~
>        |     pthread_key_t
> 
> The same code compiles fine on FreeBSD:
> 
> $ c++ -std=c++17 -c -o ../test.o ../test.cpp
> 
> 
> 
> 
> 
> 
> $ c++ --version
> FreeBSD clang version 6.0.0 (tags/RELEASE_600/final 326565) (based on LLVM 6.0.0)
> Target: x86_64-unknown-freebsd11.2
> Thread model: posix
> InstalledDir: /usr/bin
> 
> and Linux:
> 
> $ g++ -std=c++17 -c -o test.o test.cpp
> $ g++ --version
> g++ (Ubuntu 11.2.0-7ubuntu2) 11.2.0
> Copyright (C) 2021 Free Software Foundation, Inc.
> This is free software; see the source for copying conditions.  There is NO
> warranty; not even for MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.
> 
> Is there something broken in our newlib?
> 
> Thanks
> Chris
> _______________________________________________
> devel mailing list
> devel at rtems.org
> http://lists.rtems.org/mailman/listinfo/devel



More information about the devel mailing list