libc functions from c++ issues

Joel Sherrill joel at rtems.org
Wed Apr 13 20:58:35 UTC 2022


When you use -std= with gcc, it says to strictly enforce that standard. C++
is NOT POSIX so pthread.h prototypes aren't visible.  There are some edge
cases where gcc isn't that strict until -pedantic is turned on. Use of long
long in C++03 is an example of that.

-D_POSIX_C_SOURCE=200809 is precisely the answer I think but -D_GNU_SOURCE
enables almost everything I think.

Anyway, here's a small Makefile with some comments to help:

===========================

CXX=sparc-rtems6-g++
CXXFLAGS=-pthread -O2 -g

# When you turn on a -std=c++, it disables everything not strictly in
# the standard
CXXFLAGS += -std=c++11
# And you need to turn it back on -- either of these will work
#CXXFLAGS += -D_POSIX_C_SOURCE=200809
CXXFLAGS += -D_GNU_SOURCE

all: t.o

t.o: t.cc Makefile

clean:
rm -rf t *.o
===========================

On Tue, Apr 12, 2022 at 3:24 AM Karel Gardas <karel at functional.vision>
wrote:

> On 4/12/22 10:05, Chris Johns wrote:
> > 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?
>
> This is million dollar question.
>
> But I can offer just simple advice: try to compile the code in question
> on Solaris (11 or even better 10). In the past it was much more strict
> about standard than both Linux and BSD camp hence I usually used that
> for detecting: is the code Linux specific or is it written to be more
> portable and standards compliant? It'll just give you a sign although in
> this particular case of C/C++ integration it may not work that well...
>
> Good luck!
> Karel
> _______________________________________________
> devel mailing list
> devel at rtems.org
> http://lists.rtems.org/mailman/listinfo/devel
>


More information about the devel mailing list