epics-modules / iocStats

EPICS IOC Status and Control
Other
12 stars 40 forks source link

MinGW Cross-build failure #20

Closed anjohnson closed 3 years ago

anjohnson commented 7 years ago

Running a cross-build of the windows-x64-mingw target on RHEL-7 against Base-3.14.12.6 I get the following build failure:

/usr/bin/x86_64-w64-mingw32-gcc -c              -D_MINGW     -O3   -Wall      -m64    -D_DLL   -MMD -I. -I../O.Common -I. -I../os/WIN32 -I../os/default -I.. -I../../include/os/WIN32 -I../../include    -I/home/phoebus/ANJ/epics/modules/soft/sncseq/include -I/home/phoebus/ANJ/epics/base/3-14-dev/include/os/WIN32 -I/home/phoebus/ANJ/epics/base/3-14-dev/include        ../os/WIN32/osdCpuUtilization.c 
../os/WIN32/osdCpuUtilization.c:38:0: warning: ignoring #pragma comment  [-Wunknown-pragmas]
 #pragma comment (lib, "Advapi32.lib")
 ^
../os/WIN32/osdCpuUtilization.c: In function 'devIocStatsInitCpuUtilization':
../os/WIN32/osdCpuUtilization.c:121:5: warning: implicit declaration of function 'GetMaximumProcessorCount' [-Wimplicit-function-declaration]
     pval->noOfCpus = GetMaximumProcessorCount(ALL_PROCESSOR_GROUPS);
     ^
../os/WIN32/osdCpuUtilization.c:121:47: error: 'ALL_PROCESSOR_GROUPS' undeclared (first use in this function)
     pval->noOfCpus = GetMaximumProcessorCount(ALL_PROCESSOR_GROUPS);
                                               ^
../os/WIN32/osdCpuUtilization.c:121:47: note: each undeclared identifier is reported only once for each function it appears in
/home/phoebus/ANJ/epics/base/3-14-dev/configure/RULES_BUILD:211: recipe for target 'osdCpuUtilization.o' failed
make[2]: *** [osdCpuUtilization.o] Error 1
ralphlange commented 7 years ago

See https://sourceforge.net/p/mingw-w64/bugs/404/

This seems to be an issue with the defines that select which Windows version a source is compiled for. @MarkRivers: is iocStats using something too new, or is the setting of the Windows version pointing "too old"?

MarkRivers commented 7 years ago

I have only built for 32-bit mingw so far, so I have not run into this problem.

I think the problem may be related to this in osdCpuUtilization.c

#ifdef _WIN64
    pval->noOfCpus = GetMaximumProcessorCount(ALL_PROCESSOR_GROUPS);
#else

    pval->noOfCpus = strtol(getenv("NUMBER_OF_PROCESSORS"),NULL,10);
#endif    

Is this correct, is the difference in fetching these really a 32/64 bit issue?

ALL_PROCESSOR_GROUPS is not defined anywhere in the mingw include files on Fedora 15.

ralphlange commented 7 years ago

Interesting read: http://stackoverflow.com/questions/31209256/reliable-way-to-programmatically-get-the-number-of-cores-on-windows

MarkRivers commented 7 years ago

It looks difficult to really do this correctly. Since the article Ralph referenced says that getenv("NUMBER_OF_PROCESSORS") does work on 64 and 32 bit Windows we could just change the code to:

pval->noOfCpus = strtol(getenv("NUMBER_OF_PROCESSORS"),NULL,10); 

i.e. no same code for either architecture. It will only return the #processors in this thread's group, and so won't be accurate for very large number of processors, but it's probably OK for our purposes.

Engbretson commented 6 years ago

For whatever it is worth, I just attempted to use the latest mingw under linux to cross compile epics base-3.16.1 and deviocstats-3.1.15 and all I had to do was add 1 define in 2 files.

change

if defined(MINGW32) || defined(MINGW64)

define WINVER 0x0501

endif

to

if defined(MINGW32) || defined(MINGW64)

define WINVER 0x0501

define _WIN32_WINNT 0x0601

endif

in os/WIN32/osdMemusage.c os/WIN32/CpuUtilization.c

and add the psapi library to resolve the references , which I cheated and corrected in CONFIG.linux-x86.windows-x64-mingw

the softioc seems to run without throwing any errors.