Compiling Python

I am trying to compile Python csn 3.12 from source, and have run into a couple of issues.
First, running configure produced a valid Makefile, with the following gcc options:

                                                                   
# Compiler options                                                 
OPT=            -DNDEBUG -g -O3 -Wall -m486 -DSCO5                 
BASECFLAGS=      -fno-strict-overflow -Wsign-compare -m486 -DSCO5  
BASECPPFLAGS=                                                      
CONFIGURE_CFLAGS=                                                  

Then make dies with:

gcc: error: unrecognized command line option '-m486'; did you mean '-m16'? 
gcc: error: unrecognized command line option '-m486'; did you mean '-m16'? 

When I remove "-m486" from Makefile, and run make again, it finally dies at:

In file included from Objects/unicodeobject.c:879:0:                            
Objects/stringlib/fastsearch.h: In function 'ucs4lib_find_char':                
Objects/stringlib/ucs4lib.h:26:16: error: implicit declaration of function 'wmem
chr'; did you mean 'memchr'? [-Werror=implicit-function-declaration]            
     (Py_UCS4 *)wmemchr((const wchar_t *)(s), c, n)                             
                ^                                                               
Objects/stringlib/fastsearch.h:58:13: note: in expansion of macro 'STRINGLIB_FAS
T_MEMCHR'                                                                       
         p = STRINGLIB_FAST_MEMCHR(s, ch, n);                                   
             ^~~~~~~~~~~~~~~~~~~~~                                              
cc1: some warnings being treated as errors                                      
make[2]: *** [Objects/unicodeobject.o] Error 1                                  
make[2]: Leaving directory `/tmp/Python-3.12.0'                                 
make[1]: *** [profile-gen-stamp] Error 2                                        
make[1]: Leaving directory `/tmp/Python-3.12.0'                                 
make: *** [profile-run-stamp] Error 2                                           
unix:/tmp/Python-3.12.0#                                                        

gcc:

unix:/tmp/Python-3.12.0# gcc --version                                     
gcc (Xinuos GCC) 7.3.0                                                     
Copyright (C) 2017 Free Software Foundation, Inc.                          

The final purpose of this is to install Wazuh agent.

Hello,

Now, first up, I have to say I'm not an expert on SCO in particular by any means, so there may be others here who are more familiar with the intricacies of this particular environment than myself. However, what this looks like to me is that for some reason the include file that defines the wmemchr function isn't being pulled in prior to this macro expansion being encountered, and so that's why you get the "implicit declaration" warnings.

Looking at the SCO OpenServer 5.x documentation, it looks like the include file that provides this definition is wchar.h, as per this man page:

SCO OpenServer 5 documentation - wchar(M)

So you might want to check that wchar.h is present on your system, and that it is being included by the software that you're compiling prior to this particular point.

The other thing you could do - though I wouldn't recommend this - would be to remove the -Werror=implicit-function-declaration flag from your compilation flags, so that this warning would be treated as a warning once again and not an error. I'd definitely be very reluctant to do that however, since this is flagging up a genuine problem, or what is very likely to be a genuine problem at least, and it's worth trying to identify and fix the issue before attempting this, since if this is a genuine issue then you'll only end up with problems at runtime (plus there could be further issues like this one waiting to be discovered after you fix this first problem anyway).

Hope this helps !

1 Like

wchar.h exists in /usr/include,
In ucs4lib.h,

    24  #if SIZEOF_WCHAR_T == 4                                  
    25  #define STRINGLIB_FAST_MEMCHR(s, c, n)              \    
    26      (Py_UCS4 *)wmemchr((const wchar_t *)(s), c, n)       
    27  #endif                                                   

I commented all 4 lines, and finally:

Python/pytime.c:1145:30: note: each undeclared identifier is reported only once 
for each function it appears in                                                 
Python/pytime.c:1150:9: error: implicit declaration of function 'clock_gettime';
 did you mean 'localtime'? [-Werror=implicit-function-declaration]              
     if (clock_gettime(clk_id, &ts) != 0) {                                     
         ^~~~~~~~~~~~~                                                          
         localtime                                                              
Python/pytime.c:1158:9: error: implicit declaration of function 'pytime_fromtime
spec'; did you mean 'pytime_fromtimeval'? [-Werror=implicit-function-declaration
]                                                                               
     if (pytime_fromtimespec(tp, &ts, raise_exc) < 0) {                         
         ^~~~~~~~~~~~~~~~~~~                                                    
         pytime_fromtimeval                                                     
Python/pytime.c:1167:13: error: implicit declaration of function 'clock_getres' 
[-Werror=implicit-function-declaration]                                         
         if (clock_getres(clk_id, &res) != 0) {                                 
             ^~~~~~~~~~~~                                                       
cc1: some warnings being treated as errors                                      
make[2]: *** [Python/pytime.o] Error 1                                          
make[2]: Leaving directory `/tmp/Python-3.12.0'                                 
make[1]: *** [profile-gen-stamp] Error 2                                        
make[1]: Leaving directory `/tmp/Python-3.12.0'                                 
make: *** [profile-run-stamp] Error 2            

This error has to do with the system clock precision, and according to the Linux definition, already has issues with SMP systems, which all Openserver 6 installations have.
There are separate paragraphs in pytime.c for each cpu/os variation.
How can I tell how far through the compilation this is?

Hi,

I don't think you want to start commenting out definitions in the Python source code itself - if you do that, you're commenting out definitions that Python itself will depend on either later in compilation, or at some point in runtime. That's probably not a road you want to go down.

The fact you're now getting further "error: implicit declaration of function..." errors does still make it seem to me like something isn't right with how it's reading in include files. The weird thing here is that you're even getting these errors referring to functions declared in the Python source code itself (pytime_fromtimespec, for example), which makes very little sense.

Can you post the options you used when running ./configure to generate your Makefiles ? It might also be worth looking in config.log to see if anything unusual happened when configure was running, or if it failed to pick up on any libraries or include paths on your system.

Even though there were no errors displayed running configure, I found problems when I read the config.log. openssl 1.1.1 is required, and I only have .0.9.8,
I tried installing a newer version of openssl, and it requires perl 5.10. and I only have 5.8.
I tried installing a new version of perl, and it fails.

It's a pity the FOSS developers do not avoid dependencies.

I wonder why openssl needs perl at all. Maybe you can change it to require your perl 5.8
But I fear there are more dependencies.

Hello,

Unfortunately, that's not surprising to hear. OpenServer 5.x, at this point in time, is a very old operating system, regardless of whether this is original SCO version, or Xinuos' 2018 Definitive release. Underneath, you're still dealing with an OS from the 20th century, and it's inevitable that as time goes on that pieces of more modern software (and crucially, the dependencies of those pieces of software) simply will not support it any longer.

That's not to say they definitely can't be made to work, but if they can, it could require a lot of porting effort to do so. And unless you have a support arrangement with Xinuos and they can help get these things compiling - or unless you have the resources locally yourselves to do such porting work - then I don't personally think there's a high chance of getting Python 3 running on OpenServer 5 without a lot of effort.

Realistically, this might be one of those times when your best option is to look at migrating this system onto a more modern and currently-supported OS on which you can run Python 3, and everything else you need to besides. You could always still run OpenServer 5 in a VM within a new OS and migrate your applications across one at a time from the guest OS to the host OS, for example. There are various ways of approaching this type of migration.

Anyway, good luck - if you do make any progress let us know, or if you have any other questions or issues we can see what we can do to help.

Hi @jgt,

SSL is only used by some modules like smtplib or urllib, the Python binary itself does not require it. So the fail of openssl linking (checking whether compiling and linking against OpenSSL works) produces a message in the log, but this isn't a problem for compilation, only at runtime when calling e.g. urllib.request('https://...').

As @drysdalk already noted, commenting out code is generally not recommended. Regarding the errors:

  • gcc: error: unrecognized command line option '-m486'
    -m486 is very, very outdated, this should be fixed by the maintainers:
case $ac_sys_system in
         SCO_SV*) OPT="$OPT -m486 -DSCO5"
  • Objects/stringlib/ucs4lib.h:26:16: error: implicit declaration of function 'wmemchr'
    What does grep wmemchr /usr/include/wchar.h say?
  • Python/pytime.c:1158:9: error: implicit declaration of function 'pytime_fromtimespec'
    The definition of pytime_fromtimespec() is enclosed by a #ifdef HAVE_CLOCK_GETTIME block, but the function is called unconditionally later in py_get_monotonic_clock(). This is a bug and should be reported to the developers. Your system obviously doesn't provide clock_gettime(), so HAVE_CLOCK_GETTIME isn't set.

Python 3.12 is still very new, the stable/release version is just a week old. I would recommend trying a slightly older version like 3.11, 3.10 or even better 3.9 (which is still very actual). Compiling resp. installing recent software versions on relatively old systems can be very tedious, as backwards compatibility may not be sufficient.

1 Like

Thanks, for everyone's help. The higher-ups have decided not to pursue installing wazuh on this system.

2 Likes