V
Virchanza
I have a program that's written primarily in C++, and a small portion
of it in C.
My program uses the wxWidgets application framework, which provides
functionality for stuff like graphical user interfaces and multi-
threading (e.g. it provides classes such as wxThread, wxMutex).
wxWidgets is a cross-platform library; it has ports available for
Linux, MacOS and MS-Windows and others. On Unix-like systems,
wxWidgets implements multi-threading by using the "pthreads" library
under the hood, however on MS-Windows it uses the mult-threading
functions provided by the Win32 API.
Since my own program is cross-platform and may be compiled for
different operating systems, I cannot assume that "pthreads" is being
used under the hood.
The small portion of my program that's written in C doesn't contain
any multi-threading code at all. However, since this C code will be
used in my big multi-threaded C++ program, I've made sure that all of
the functions in my C code are re-entrant.
When I use GCC to compile the portion of my program written in C, I
want to tell it that the Standard C Library must be re-entrant because
my C code will get linked into a big multi-threaded C++ program.
....well ...I've searched the web and I've gone through the GNU
documentation but I haven't found a clear-cut answer on how to tell
the GNU compiler that you need a thread-safe implementation of the
Standard C Library.
I've heard some people specify -D _REENTRANT when compiling, but I see
no mention of this macro in the GNU manual.
I compile my entire program in 3 stages. First I compile the C files
to object files:
gcc -c *.c
Next I compile the C++ files to object files:
g++ -c `wx-config --cppflags` *.cpp
Next I use the linker to create an executable file:
g++ `wx-config --libs` *.o -o prog
The command "wx-config --cppflags" on my Ubuntu Linux machine expands
to:
-D_FILE_OFFSET_BITS=64 -D_LARGE_FILES -D__WXGTK__
The command "wx-config --libs" on my Ubuntu Linux machine expands to:
-pthread -Wl,-Bsymbolic-functions -lwx_gtk2u_richtext-2.8 -
lwx_gtk2u_aui-2.8 -lwx_gtk2u_xrc-2.8 -lwx_gtk2u_qa-2.8 -
lwx_gtk2u_html-2.8 -lwx_gtk2u_adv-2.8 -lwx_gtk2u_core-2.8 -
lwx_baseu_xml-2.8 -lwx_baseu_net-2.8 -lwx_baseu-2.8
(note that these commands give different outputs on different
operating systems).
Anyway, for now I just want to figure out which multi-threading-
related compiler options I should be specifying. Honestly I've been
searching the web for the last hour and I haven't yet found what I'm
looking for.
The GNU compiler has the "-pthread" switch but that wouldn't be
appropriate to use if my program's being compiled for Win32. I can't
find much info on what _REENTRANT actually does.
Any help?
of it in C.
My program uses the wxWidgets application framework, which provides
functionality for stuff like graphical user interfaces and multi-
threading (e.g. it provides classes such as wxThread, wxMutex).
wxWidgets is a cross-platform library; it has ports available for
Linux, MacOS and MS-Windows and others. On Unix-like systems,
wxWidgets implements multi-threading by using the "pthreads" library
under the hood, however on MS-Windows it uses the mult-threading
functions provided by the Win32 API.
Since my own program is cross-platform and may be compiled for
different operating systems, I cannot assume that "pthreads" is being
used under the hood.
The small portion of my program that's written in C doesn't contain
any multi-threading code at all. However, since this C code will be
used in my big multi-threaded C++ program, I've made sure that all of
the functions in my C code are re-entrant.
When I use GCC to compile the portion of my program written in C, I
want to tell it that the Standard C Library must be re-entrant because
my C code will get linked into a big multi-threaded C++ program.
....well ...I've searched the web and I've gone through the GNU
documentation but I haven't found a clear-cut answer on how to tell
the GNU compiler that you need a thread-safe implementation of the
Standard C Library.
I've heard some people specify -D _REENTRANT when compiling, but I see
no mention of this macro in the GNU manual.
I compile my entire program in 3 stages. First I compile the C files
to object files:
gcc -c *.c
Next I compile the C++ files to object files:
g++ -c `wx-config --cppflags` *.cpp
Next I use the linker to create an executable file:
g++ `wx-config --libs` *.o -o prog
The command "wx-config --cppflags" on my Ubuntu Linux machine expands
to:
-D_FILE_OFFSET_BITS=64 -D_LARGE_FILES -D__WXGTK__
The command "wx-config --libs" on my Ubuntu Linux machine expands to:
-pthread -Wl,-Bsymbolic-functions -lwx_gtk2u_richtext-2.8 -
lwx_gtk2u_aui-2.8 -lwx_gtk2u_xrc-2.8 -lwx_gtk2u_qa-2.8 -
lwx_gtk2u_html-2.8 -lwx_gtk2u_adv-2.8 -lwx_gtk2u_core-2.8 -
lwx_baseu_xml-2.8 -lwx_baseu_net-2.8 -lwx_baseu-2.8
(note that these commands give different outputs on different
operating systems).
Anyway, for now I just want to figure out which multi-threading-
related compiler options I should be specifying. Honestly I've been
searching the web for the last hour and I haven't yet found what I'm
looking for.
The GNU compiler has the "-pthread" switch but that wouldn't be
appropriate to use if my program's being compiled for Win32. I can't
find much info on what _REENTRANT actually does.
Any help?