Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

E0020 The identifier ""strcasecmp"" is not defined plugin.h #2670

Open
chris9672 opened this issue Feb 8, 2024 · 2 comments
Open

E0020 The identifier ""strcasecmp"" is not defined plugin.h #2670

chris9672 opened this issue Feb 8, 2024 · 2 comments

Comments

@chris9672
Copy link

chris9672 commented Feb 8, 2024

I hope that the error I'm encountering actually belongs to this area. However, I don't know where else to discuss it.
I tried to compile the OpenBabel source code myself under Visual Studio 2022. After downloading OpenBabel v3.1.1 from Github, I first downloaded the following optional libs and successfully compiled them all with CMake (libxml2, InChI, zlib, Eigen3, RapidJSON, wxWidgets and Cairo).

After setting various paths for optional libraries in CMake, I was able to successfully configure and generate OpenBabel in CMake and open it in Visual Studio 2022. The project was also able to be compiled (Release) in Visual Studio without any errors.

I then created a new console project and configured various paths for the include and .lib files of OpenBabel for it.
Here is the short console programm I found in the net:


#include <openbabel/obconversion.h>
#include <openbabel/mol.h>
#include <iostream>

using namespace std;
using namespace OpenBabel;

int main() {
    // SMILES string
    string smiles = "CCO";

    // Create an OBMol object
    OBMol mol;
    OBConversion conv;
    conv.SetInFormat("smi");
    conv.ReadString(&mol, smiles);

    // Get IUPAC name
    string iupac_name = mol.GetTitle();

    // Output IUPAC name
    cout << "IUPAC name: " << iupac_name << endl;

    return 0;
}

But when I tried to compile this console project, the following errors were displayed:

Error (active) E0020 The identifier ""strcasecmp"" is not defined. OpenBable C:\Libs\OpenBabel\v3.1.1\install\include\openbabel3\openbabel\plugin.h 44
Error C3861 "strcasecmp": Identifier not found. OpenBable C:\Libs\OpenBabel\v3.1.1\install\include\openbabel3\openbabel\plugin.h 44

I know that "strcasecmp" is not included in the C standard, but only in POSIX.
I'm now wondering how I can fix this error? Did I make a mistake when compiling OpenBabel?

Environment Information

Open Babel version: v3.1.1
Used optional Libs: libxml2, InChI, zlib, Eigen3, RapidJSON, Cairo, wxWidgets
Operating system and version: Windows 11 Pro x64
Compiler: Visual Studio C++ 2022
CMake GUI v3.28.1

Thx in advance for trying to help.

Copy link

welcome bot commented Feb 8, 2024

Thanks for opening your first issue here! Be sure to follow the issue template!

@SharanRP
Copy link

your speculations seems to be correct , As you mentioned, strcasecmp is a POSIX function, and its usage on Windows may cause compilation issues.

either we can make changes to local build by adding something similar to following lines of code in plugin.h

struct OBERROR CharPtrLess
{
  bool operator()(const char* p1, const char* p2) const
  {
    #if defined(_MSC_VER)
      return _stricmp(p1, p2) < 0;
    #else
      return strcasecmp(p1, p2) < 0;
    #endif
  }
};

this should work since _srticmp is a valid function under Microsoft Visual C++ or else you can add a custom function

#include <cctype>

struct CharPtrLess
{
  bool operator()(const char* p1, const char* p2) const
  {
    #if defined(_MSC_VER)
      return _stricmp(p1, p2) < 0;
    #else
      while (*p1 && *p2) {
        char ch1 = std::toupper(static_cast<unsigned char>(*p1));
        char ch2 = std::toupper(static_cast<unsigned char>(*p2));

        if (ch1 < ch2) return true;
        if (ch1 > ch2) return false;

        ++p1;
        ++p2;
      }

      return *p1 < *p2;
    #endif
  }
};

please verify and correct me if I am wrong , @ghutchis , @chris9672

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

No branches or pull requests

2 participants