This discussion is archived
8 Replies Latest reply: Aug 28, 2012 1:02 AM by 802031 RSS

Compilation of OpenCV failed

802031 Newbie
Currently Being Moderated
Hi,

i'm trying to compile the OpenCV library 2.4.2 with Oracle Studio in Solaris 10 x86 9/10.
I get the following error:


[ 13%] Building CXX object modules/ts/CMakeFiles/opencv_ts.dir/src/ts_gtest.cpp.o
".../OpenCV-2.4.2/modules/ts/src/ts_gtest.cpp", line 8994: Error: Could not find a match for PrintAsStringLiteralTo needed in testing::internal::PrintCharsAsStringTo<char>(const char*, unsigned long, std::ostream *).
"...o/OpenCV-2.4.2/modules/ts/src/ts_gtest.cpp", line 9041: Where: While instantiating "testing::internal::PrintCharsAsStringTo<char>(const char*, unsigned long, std::ostream *)".
".../OpenCV-2.4.2/modules/ts/src/ts_gtest.cpp", line 9041: Where: Instantiated from non-template code.
1 Error(s) detected.

The file ts_gtest.cpp is part of the google c++ testing framework.



Around line 8994:
// Prints the given array of characters to the ostream.  CharType must be either
// char or wchar_t.
// The array starts at begin, the length is len, it may include '\0' characters
// and may not be NUL-terminated.
template <typename CharType>
static void PrintCharsAsStringTo(
    const CharType* begin, size_t len, ostream* os) {
  const char* const kQuoteBegin = sizeof(CharType) == 1 ? "\"" : "L\"";
  *os << kQuoteBegin;
  bool is_previous_hex = false;
  for (size_t index = 0; index < len; ++index) {
    const CharType cur = begin[index];
    if (is_previous_hex && IsXDigit(cur)) {
      // Previous character is of '\x..' form and this character can be
      // interpreted as another hexadecimal digit in its number. Break string to
      // disambiguate.
      *os << "\" " << kQuoteBegin;
    }
    is_previous_hex = PrintAsStringLiteralTo(cur, os) == kHexEscape; // => THIS IS LINE 8994
  }
  *os << "\"";
}
Around Line 9041:
void PrintTo(const char* s, ostream* os) {
  if (s == NULL) {
    *os << "NULL";
  } else {
    *os << ImplicitCast_<const void*>(s) << " pointing to ";
    PrintCharsAsStringTo(s, strlen(s), os); // => THIS IS LINE 9041
  }
}
Around line 8911:
// Prints a wchar_t c as if it's part of a string literal, escaping it when
// necessary; returns how c was formatted.
static CharFormat PrintAsStringLiteralTo(wchar_t c, ostream* os) {
  switch (c) {
    case L'\'':
      *os << "'";
      return kAsIs;
    case L'"':
      *os << "\\\"";
      return kSpecialEscape;
    default:
      return PrintAsCharLiteralTo<wchar_t>(c, os);
  }
}

// Prints a char c as if it's part of a string literal, escaping it when
// necessary; returns how c was formatted.
static CharFormat PrintAsStringLiteralTo(char c, ostream* os) {
  return PrintAsStringLiteralTo(
      static_cast<wchar_t>(static_cast<unsigned char>(c)), os);
}
$ CC -V
CC: Sun C++ 5.11 SunOS_i386 Patch 145731-08 2012/06/26

Does anybody know where the problem is?

Thanks for any help

Julian
  • 1. Re: Compilation of OpenCV failed
    Steve_Clamage Pro
    Currently Being Moderated
    Most likely the problem is due to a compiler bug. Possibly it has been fixed in a later release.
    Please try Studio 12.3 and see if the problem goes away.
    http://www.oracle.com/technetwork/server-storage/solarisstudio/downloads/index.html

    If you have a service contract for Studio, you can also download compiler patches at MyOracleSupport, or file a bug report via your support channel. I see you have the current patch for C++ 5.11, but patches for Studio 12.3 (C++ 5.12) are also available.
  • 2. Re: Compilation of OpenCV failed
    802031 Newbie
    Currently Being Moderated
    Thanks for your reply.

    I updated to Studio 12.3 (latest patches), but still the same error.

    CC: Sun C++ 5.12 SunOS_i386 Patch 148509-03 2012/06/12

    I don't have a service contract for Studio, just one for Solaris+Software. Is there anything else I can do?
  • 3. Re: Compilation of OpenCV failed
    Steve_Clamage Pro
    Currently Being Moderated
    If you can provide a reduced test case that doesn't require installing OpenCV to compile, you can file a bug report at bugs.sun.com. That service will eventually disappear, but it is currently active. We are currently working on improving the compiler's template processing.
  • 4. Re: Compilation of OpenCV failed
    802031 Newbie
    Currently Being Moderated
    I tried to provide a test case, and followed what you wrote me long time ago
    (Re: trying to compile cern root framework
    And I'm glad that you help me again ;)

    Here is what i did:

    $ CC -I../include -I../../../include -I../../core/include -c ts_gtest.cpp
    "ts_gtest.cpp", line 8994: Error: Could not find a match for PrintAsStringLiteralTo needed in testing::internal::PrintCharsAsStringTo<char>(const char*, unsigned, std::ostream *).
    "ts_gtest.cpp", line 9041: Where: While instantiating "testing::internal::PrintCharsAsStringTo<char>(const char*, unsigned, std::ostream *)".
    "ts_gtest.cpp", line 9041: Where: Instantiated from non-template code.
    1 Error(s) detected.

    $ CC -I../include -I../../../include -I../../core/include -E ts_gtest.cpp > test.i
    $ CC -I../include -I../../../include -I../../core/include -c test.i
    "/opt/solarisstudio12.3/prod/include/CC/Cstd/algorithm.cc", line 724: Error: "," expected instead of "long".
    1 Error(s) detected.

    Now, i'm a confused

    BTW, if (i'm not absolutely, but relatively sure) i remember correctly, i didn't get the error before installing some patches to studio12.2.
    Here are the last ones i installed.

    119961-11
    145357-05
    119964-26
    145731-08
    148503-01

    My first attempts to compile OpenCV were in July. If the error was introduced with a patch, it must be a patch released in July or August.

    Additionally I tried to "reduce" the file manually, which compiles just fine.

    #include <stdio.h>
    #include <stdlib.h>
    #include <wchar.h>
    #include <wctype.h>
    #include <sstream>
    #include <vector>
    #include <unistd.h>  // NOLINT
    #include <ctype.h>
    #include <stdio.h>
    #include <ostream>  // NOLINT
    #include <string>
    
    using namespace std;
    
    namespace testing {
    
    
    namespace internal {
    
    
    
    enum CharFormat {
      kAsIs,
      kHexEscape,
      kSpecialEscape
    };
    
    
    template <typename UnsignedChar, typename Char>
    static CharFormat PrintAsCharLiteralTo(Char c, ostream* os) {
      switch (static_cast<wchar_t>(c)) {
        case L'\0':
          *os << "\\0";
          break;
        default:
            return kHexEscape;
      }
      return kSpecialEscape;
    }
    
    
    
    static CharFormat PrintAsStringLiteralTo(wchar_t c, ostream* os) {
      switch (c) {
        case L'\'':
          *os << "'";
          return kAsIs;
        case L'"':
          *os << "\\\"";
          return kSpecialEscape;
        default:
          return PrintAsCharLiteralTo<wchar_t>(c, os);
      }
    }
    
    
    
    static CharFormat PrintAsStringLiteralTo(char c, ostream* os) {
      return PrintAsStringLiteralTo(
          static_cast<wchar_t>(static_cast<unsigned char>(c)), os);
    }
    
    
    
    template <typename CharType>
    static void PrintCharsAsStringTo(
        const CharType* begin, size_t len, ostream* os) {
      const char* const kQuoteBegin = sizeof(CharType) == 1 ? "\"" : "L\"";
      *os << kQuoteBegin;
      bool is_previous_hex = false;
      for (size_t index = 0; index < len; ++index) {
        const CharType cur = begin[index];
        if (is_previous_hex && IsXDigit(cur)) {
          *os << "\" " << kQuoteBegin;
        }
        is_previous_hex = PrintAsStringLiteralTo(cur, os) == kHexEscape;
      }
      *os << "\"";
    }
    
    
    
    template <typename CharType>
    static void UniversalPrintCharArray(
        const CharType* begin, size_t len, ostream* os) {
      if (len > 0 && begin[len - 1] == '\0') {
        PrintCharsAsStringTo(begin, len - 1, os);
        return;
      }
      PrintCharsAsStringTo(begin, len, os);
      *os << " (no terminating NUL)";
    }
    
    
    
    
    
    }  // namespace internal
    
    }  // namespace testing
    Should I submit a bug report with test.i attached? But test.i has about 52 000 lines of code...
  • 5. Re: Compilation of OpenCV failed
    Steve_Clamage Pro
    Currently Being Moderated
    Oracle C++ by default uses the "definitions separate" template compilation model, where template declarations are in a header file, and the definitions are in an associated .cc file. When the compiler needs a definition for a declaration in a header, it looks for the associated .cc file and includes it automatically. When you compile a .i file, the link between the header and the .cc file is broken, and the definitions don't get included. As a result, the compiler might not see the code that results in an error message.

    Re-run the "-E" command line, but add the option -template=no%extdef
    The .cc files for the standard library will be included automatically, and you should see the same error you got originally. (The example you provided does not result in any errors, so it won't be helpful in finding the original problem.)

    You can read more about template compilation models and the -template option in the C++ Users Guide.
    http://docs.oracle.com/cd/E24457_01/index.html

    The bugs.sun.com interface does not allow attaching files, but someone (probably me) will ask for the file.
  • 6. Re: Compilation of OpenCV failed
    user13277775 Newbie
    Currently Being Moderated
    Hi,
    OpenCV 2.3.1.a is buildable on Solaris 11 using Studio 12.3 and stdcxx4.
    You'll need the below patches:
    http://solaris.bionicmutton.org/hg/kde4-specs-470/file/a06f36607f59/specs/patches/OpenCV

    Haven't tried 2.4

    HTH

    P.
  • 7. Re: Compilation of OpenCV failed
    802031 Newbie
    Currently Being Moderated
    Hi,

    thank you both for your answers.
    I just created a bug report - internal review ID 2321808.

    I will have a look at theses patches when I have time.

    Julian
  • 8. Re: Compilation of OpenCV failed
    802031 Newbie
    Currently Being Moderated
    and here is the bug id: 7194307

    Julian

Legend

  • Correct Answers - 10 points
  • Helpful Answers - 5 points