2

I'm using Qt Creator 4.6.1 on Windows 10
Based on Qt 5.10.1 (MSVC 2015, 32 bit)
Built on May 2 2018 04:24:33
qmake with mingw491_32

There is a project from the web which makes use of a botanwrapper with the include Botan.pri

The full code is quite long so not possible to post here but it is available at http://www.voidrealms.com/index.php?r=source/view&id=1 as a zip file.

That all works and encrypts files but when I bring the files into my my project I get a huge number of compile errors such as those below.

botan.h:9380: error: expected identifier before '(' token
          X942_DH_PARAMETERS = ANSI_X9_42,
          ^

and error: expected '}' before '(' token which points to the line

enum Format {
         ANSI_X9_42,
         ANSI_X9_57,
         PKCS_3,

         DSA_PARAMETERS = ANSI_X9_57,
         DH_PARAMETERS = ANSI_X9_42,
         X942_DH_PARAMETERS = ANSI_X9_42, // Error points to here
         PKCS3_DH_PARAMETERS = PKCS_3
      };

Also lots of errors relating to the const such as

error: non-member function 'bool Botan::verify_group(Botan::RandomNumberGenerator&, bool)' cannot have cv-qualifier

bool verify_group(RandomNumberGenerator& rng, bool strong) const;  

Which points to the code below


bool verify_group(RandomNumberGenerator& rng, bool strong) const;

I have checked the .pro files for the includes and I have the same files setup as the project that compiles and runs on the same setup. I have the same botan.pri file included which contains

win32 {
    DEFINES += BOTAN_TARGET_OS_IS_WINDOWS \
        BOTAN_TARGET_OS_HAS_LOADLIBRARY BOTAN_TARGET_OS_HAS_WIN32_GET_SYSTEMTIME \
        BOTAN_TARGET_OS_HAS_WIN32_VIRTUAL_LOCK BOTAN_HAS_DYNAMICALLY_LOADED_ENGINE \
        BOTAN_HAS_DYNAMIC_LOADER BOTAN_HAS_ENTROPY_SRC_CAPI BOTAN_HAS_ENTROPY_SRC_WIN32 \
        BOTAN_HAS_MUTEX_WIN32

    win32-msvc* {
        QMAKE_CXXFLAGS += -wd4251 -wd4290 -wd4250
        DEFINES += BOTAN_BUILD_COMPILER_IS_MSVC BOTAN_TARGET_OS_HAS_GMTIME_S
    } else {
        QMAKE_CFLAGS += -fpermissive -finline-functions -Wno-long-long
        QMAKE_CXXFLAGS += -fpermissive -finline-functions -Wno-long-long
    }
    LIBS += -ladvapi32 -luser32
}

I have read that removing the const will remove 1 or more errors but I don't understand why this is broken on the same setup that happily compiles the botan.h and runs the build and encrypts files. Could someone help with how to start to troubleshoot this. Help appreciated. Thanks in advance.

AleXelton
  • 767
  • 5
  • 27

1 Answers1

1

The problem is Windows API defines a macro X942_DH_PARAMETERS which conflicts with this enum. (In fact the enum was renamed in later releases of Botan, to avoid this issue https://github.com/randombit/botan/issues/482).

You can work around it by using #undef X942_DH_PARAMETERS before including the Botan headers.

Jack Lloyd
  • 8,215
  • 2
  • 37
  • 47
  • Jack thanks for this really appreciated I was getting worn down with that. Now I have a strange `error: undefined reference to `BotanWrapper::DecryptFileW(QString, QString)` a global search doesn't even show that anywhere in the whole QT project? Anyway - thanks again! – UKbasedUser Jul 05 '18 at 21:20
  • Sorry I don't know anything about the Qt wrapper, but one thing to look at is `DecryptFileW` is a Windows API, it is possible Windows header is doing something like `#define DecryptFile DecryptFileW`, so `#undef DecryptFile` may do it. – Jack Lloyd Jul 06 '18 at 14:24
  • Thanks again Jack. I asked on Qt forum but no reply so I posted back to your solution here. I have just tracked it to the DecryptFile definition in winbase.h so I renamed the botanwrapper to DecryptFileW and that worked. I don't know where the original FileW suffix came from though I have lost track to be honest. I need to consider which is the best way undefine or leave as is and post a clash bug on github for wrapper. Wish I could award likes/stars/credits here I would throw a bundle your way. – UKbasedUser Jul 06 '18 at 19:02