epics-modules / caPutLog

Channel Access Put Logger, from DESY/BESSY

Geek Repo:Geek Repo

Github PK Tool:Github PK Tool

caPutJsonLogTask.cpp fails to compile on Windows

dirk-zimoch opened this issue · comments

Some warnings:

caputlog\caputlogapp\caputjsonlogtask.cpp(43): warning C4273: 'instance': inconsistent dll linkage
caputlog\caputlogapp\caputjsonlogtask.h(148): note: see previous definition of 'private: static CaPutJsonLogTask * __ptr64 __ptr64 CaPutJsonLogTask::instance'
caputlog\caputlogapp\caputjsonlogtask.cpp(43): error C2491: 'CaPutJsonLogTask::instance': definition of dllimport static data member not allowed

Same for all other CaPutJsonLogTask members!

Compiler errors:

caputlog\caputlogapp\caputjsonlogtask.cpp(592): error C2589: '(': illegal token on right side of '::'
caputlog\caputlogapp\caputjsonlogtask.cpp(592): error C2062: type 'unknown-type' unexpected
caputlog\caputlogapp\caputjsonlogtask.cpp(592): error C2059: syntax error: ')'

repeats several times for lines 595,598,602,...657.

More errors:

caputlog\caputlogapp\caputjsonlogtask.cpp(47): error C2491: 'CaPutJsonLogTask::instance': definition of dllimport static data member not allowed

and

caputlog\caputlogapp\caputjsonlogtask.cpp(351): error C2131: expression did not evaluate to a constant
caputlog\caputlogapp\caputjsonlogtask.cpp(351): note: failure was caused by a read of a variable outside its lifetime
caputlog\caputlogapp\caputjsonlogtask.cpp(351): note: see usage of 'interBufferSize'

Windows needs #define NOMINMAX in order to not provide min and max as macros and then requires #include <algorithm> for std::min() and 'std::max()`.

Which is best done in a Makefile through a Windows-only compiler option.
(Avoids adding yet another #ifdef clause.)

No #ifdef needed. Neither #define NOMINMAX nor #include <algorithm> hurts anyone.

The linker errors are caused by missing #define epicsExportSharedSymbols.

That leaves us with this problem:

caPutJsonLogStatus CaPutJsonLogTask::buildJsonMsg(const VALUE *pold_value, const LOGDATA *pLogData,
                                bool burst, const VALUE *pmin, const VALUE *pmax)
{
    // Intermediate message build buffer
    // The longest message for the buffer can occur in the lso/lsi records which
    // is defined with MAX_ARRAY_SIZE_BYTES, if this is less then 40 then
    // stringin / stringout are the limits
    size_t interBufferSize = MAX_STRING_SIZE + 1 > MAX_ARRAY_SIZE_BYTES + 1
                            ? MAX_STRING_SIZE + 1
                            : MAX_ARRAY_SIZE_BYTES + 1;
    unsigned char interBuffer[interBufferSize];

Windows cannot define an array with a seemingly variable length.

Solution: const size_t interBufferSize = ...

Linker error:

caPutJsonLogShellCommands.obj : error LNK2001: unresolved external symbol _caPutLogJsonMsgQueueSize

I guess caPutLogJsonMsgQueueSize needs some epicsShareSomething decoration.

epicsShareExtern int caPutLogJsonMsgQueueSize;

And need to link tests with ws2_32, too:

PROD_SYS_LIBS_WIN32 += ws2_32

Or add this to the code?

#pragma comment(lib, "Ws2_32.lib")

As anything that uses htonl or similar or any networking stuff in Windows needs to link with ws2_32, shouldn't that be a standard linker option in EPICS base?