2

我编译了一个 c tidy 程序我收到一个错误,这是他们给出的示例程序

#include "tidy/tidy.h"
#include <stdio.h>
#include <errno.h>


int main(int argc, char **argv )
{
  const char* input = "<title>Foo</title><p>Foo!";
  TidyBuffer output = {0};
  TidyBuffer errbuf = {0};
  int rc = -1;
  Bool ok;

  TidyDoc tdoc = tidyCreate();                     // Initialize "document"
  printf( "Tidying:\t%s\n", input );

  ok = tidyOptSetBool( tdoc, TidyXhtmlOut, yes );  // Convert to XHTML
  if ( ok )
    rc = tidySetErrorBuffer( tdoc, &errbuf );      // Capture diagnostics
  if ( rc >= 0 )
    rc = tidyParseString( tdoc, input );           // Parse the input
  if ( rc >= 0 )
    rc = tidyCleanAndRepair( tdoc );               // Tidy it up!
  if ( rc >= 0 )
    rc = tidyRunDiagnostics( tdoc );               // Kvetch
  if ( rc > 1 )                                    // If error, force output.
    rc = ( tidyOptSetBool(tdoc, TidyForceOutput, yes) ? rc : -1 );
  if ( rc >= 0 )
    rc = tidySaveBuffer( tdoc, &output );          // Pretty Print

  if ( rc >= 0 )
  {
    if ( rc > 0 )
      printf( "\nDiagnostics:\n\n%s", errbuf.bp );
    printf( "\nAnd here is the result:\n\n%s", output.bp );
  }
  else
    printf( "A severe error (%d) occurred.\n", rc );

  tidyBufFree( &output );
  tidyBufFree( &errbuf );
  tidyRelease( tdoc );
  return rc;
}

错误

为项目 cr 构建配置调试 **

做所有

Building file: ../src/a.cpp
Invoking: GCC C++ Compiler
g++ -O0 -g3 -Wall -c -fmessage-length=0 -MMD -MP -MF"src/a.d" -MT"src/a.d" -o"src/a.o" "../src/a.cpp"
../src/a.cpp: In function ‘int main(int, char**)’:
../src/a.cpp:9: error: variable ‘TidyBuffer output’ has initializer but incomplete type
../src/a.cpp:10: error: variable ‘TidyBuffer errbuf’ has initializer but incomplete type
../src/a.cpp:40: error: ‘tidyBufFree’ was not declared in this scope
make: *** [src/a.o] Error 1
4

1 回答 1

5

TidyBuffer 结构在 Tidy library header 中声明buffio.h,所以如果你也包含它,它应该可以工作。

顶部的包含应如下所示:

#include <tidy.h>
#include <buffio.h>
#include <errno.h>
于 2011-02-18T21:35:52.503 回答