On 29.02.2016 08:46 schrieb Edzard Egberts wrote:
> Albrecht Schlosser wrote:
>
>> #include <X11/Xlib.h>
>
> #undef Status
#undef Status is not possible because Status is a typedef introduced by
#include <X11/Xlib.h>
Maybe I should have been more explicit.
>> int main (int argc, char **argv) {
>> Status x = "abc";
>> }
>
> ../main.cpp:7: error: »Status« was not defined
Is this from your code, i.e. from '#undef Status'?
>> Here is a quick fix:
>>
>> --- patch -p1 ... ---
>> diff --git a/FL/fl_utf8.h b/FL/fl_utf8.h
>> index 1551991..0ce1f49 100644
>> --- a/FL/fl_utf8.h
>> +++ b/FL/fl_utf8.h
>> @@ -60,8 +60,10 @@
>> #else /* X11 */
>> # include <sys/types.h>
>> # include <sys/stat.h>
>> +#ifdef FL_LIBRARY
>> # include <X11/Xlocale.h>
>> # include <X11/Xlib.h>
>> +#endif /* FL_LIBRARY */
>> # include <locale.h>
>> # define xchar unsigned short
>> #endif
>> --- end of patch ---
>
> Does this fix also make usage of "Status" possible, or did I miss the
> problem at all? First I also thought it regards to namespaces, but the
> problem comes from a C definition.
Yes (usage of Status will be possible), and yes (it comes from a C
definition (typedef)).
The patch avoids including X11 headers in user code (the macro
FL_LIBRARY must only be defined when the library is built). Hence X11
specific definitions (Window, Status, ...) will not pollute your user
code, and you will be able to use it.
My test ("proof") shows when compiled with gcc:
(1) if #include <X11/Xlib.h> is active, you see:
status.cxx:5:13: error: invalid conversion from ‘const char*’ to ‘int’
[-fpermissive]
Status x = "abc";
^
This means that Status is defined (typedef int Status) so the conversion
from ‘const char*’ to ‘int’ is invalid.
(2) If you don't #include the X11 header, then "Status x" is not
defined, and you'll get another error message.
The conclusion: if we avoid to #include <X11/*> in the FLTK header files
when compiled for user code, then Status will not be defined and you can
use it freely.
A usable patch for FLTK will be more involved though. There are other
platform includes in the same and other files, and we must avoid to
#include all platform specific headers in user code. Some users might
have "relied" on the inclusion of - for instance - <Windows.h> (under
Windows) or <X11/Xlib.h> (under Linux), and this change would have a
(very unlikely?) side effect to break the code of these users. But this
is easy to fix, so I tend to change the FLTK headers, as suggested by
the posted patch.
Could you please open an STR that shows the issue with your code (or my
short test program below) and refer to this thread? Google link:
https://groups.google.com/forum/#!topic/fltkgeneral/gzmdRk2LvAk
Please use HIGH priority for the STR.
Here is "my" test program:
$ cat status.cxx
#include <FL/Fl.H>
int main (int argc, char **argv) {
enum Status { Good, Bad };
return Good;
}
$ fltk-config --compile status.cxx && ./status ; echo $?
g++ -I/home/albrecht/git/fltk -I/usr/include/freetype2
-D_LARGEFILE_SOURCE -D_LARGEFILE64_SOURCE -D_THREAD_SAFE -D_REENTRANT -o
'status' 'status.cxx' /home/albrecht/git/fltk/lib/libfltk.a -lXrender
-lXcursor -lXfixes -lXext -lXft -lfontconfig -lXinerama -lpthread -ldl
-lm -lX11
status.cxx: In function ‘int main(int, char**)’:
status.cxx:5:3: error: expected primary-expression before ‘enum’
enum Status { Good, Bad };
^
status.cxx:5:3: error: expected ‘;’ before ‘enum’
status.cxx:6:10: error: ‘Good’ was not declared in this scope
return Good;
^
1
--- end of test ---
With the patch it works as expected:
$ fltk-config --compile status.cxx && ./status ; echo $?
g++ -I/home/albrecht/git/fltk -I/usr/include/freetype2
-D_LARGEFILE_SOURCE -D_LARGEFILE64_SOURCE -D_THREAD_SAFE -D_REENTRANT -o
'status' 'status.cxx' /home/albrecht/git/fltk/lib/libfltk.a -lXrender
-lXcursor -lXfixes -lXext -lXft -lfontconfig -lXinerama -lpthread -ldl
-lm -lX11
0
The same is true if you remove the inclusion of <FL/Fl.H>, and it also
works flawlessly under Windows.