libc functions from c++ issues

Chris Johns chrisj at rtems.org
Tue Apr 12 08:05:35 UTC 2022


On 12/4/2022 5:18 pm, Karel Gardas wrote:
> 
> Not sure, but isn't usage of C headers in C++ deprecated for a long time now?
> Shouldn't you use csignal and cstdlib? 

These functions are not defined in a C++ namespace so you are required to use C
functions to use them. I am not what the rational is but I am sure there is one.

> 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,

The issue is not what I want. I would simply manage this issue some other way,
ie a C call that wraps the functions I wish to use. :)

> have you tried to use include_next trick by defining
> _GLIBCXX_INCLUDE_NEXT_C_HEADERS? See include/c++/stdlib.h from tools...

I think there is something else happening here. If I use a 4.11 compiler the
`setenv` call is not seen but `pthread_kill` is. Maybe 6 is more standards
compliant? I do not know.

I am porting a large piece of existing code to RTEMS and that code compiles and
runs on current Linux systems.

Why does Linux build this code and we do not?

Should we be compatible or standards compliant?

Chris

> 
> 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