How to compile C++ program with using html tidy C++

1.6k views Asked by At

I installed tidy-dev from ubuntu repository, checked installation path - it's okay (/usr/include/tidy).

But I can not find a true flags to compile my c++ script with include tidy c++ wrapper tidyx.h from http://users.rcn.com/creitzel/tidy/tidyx.h

Can you help me?

My test script file named 1.cpp, tidyx.h I put near. 1.cpp content:

#include "tidyx.h"

int main()
{
}

I try it, but no-good:

$ gcc -I/usr/include/tidy 1.cpp -ltidy

In file included from 1.cpp:1:
tidyx.h: In constructor ‘Tidy::Source::Source()’:
tidyx.h:83: error: invalid conversion from ‘int (*)(ulong)’ to ‘int (*)(void*)’
tidyx.h:84: error: invalid conversion from ‘void (*)(ulong, byte)’ to ‘void (*)(void*, byte)’
tidyx.h:85: error: invalid conversion from ‘Bool (*)(ulong)’ to ‘Bool (*)(void*)’
tidyx.h:86: error: invalid conversion from ‘ulong’ to ‘void*’
tidyx.h: In constructor ‘Tidy::Sink::Sink()’:
tidyx.h:123: error: invalid conversion from ‘void (*)(ulong, byte)’ to ‘void (*)(void*, byte)’
tidyx.h:124: error: invalid conversion from ‘ulong’ to ‘void*’
tidyx.h: In member function ‘void Tidy::Buffer::Attach(void*, uint)’:
tidyx.h:165: error: invalid conversion from ‘void*’ to ‘byte*’
tidyx.h:165: error:   initializing argument 2 of ‘void tidyBufAttach(TidyBuffer*, byte*, uint)’
tidyx.h: In member function ‘int Tidy::Document::Create()’:
tidyx.h:496: error: invalid conversion from ‘ulong’ to ‘void*’
tidyx.h:496: error:   initializing argument 2 of ‘void tidySetAppData(const _TidyDoc*, void*)’
tidyx.h: In member function ‘void Tidy::Document::SetAppData(ulong)’:
tidyx.h:511: error: invalid conversion from ‘ulong’ to ‘void*’
tidyx.h:511: error:   initializing argument 2 of ‘void tidySetAppData(const _TidyDoc*, void*)’
tidyx.h: In member function ‘ulong Tidy::Document::GetAppData()’:
tidyx.h:512: error: invalid conversion from ‘void*’ to ‘ulong’
1

There are 1 answers

8
peoro On

To include a header file you need to use the #include preprocessor directive. It will look for the header file in compiler include paths.

If tidyx.h is in /usr/include/tidy you could put in your source file:

#include <tidy/tidyx.h>

and then compile just with gcc script.cpp, since /usr/include is most likely a default include path for your compiler.

Otherwise you could also put in your source file:

#include <tidyx.h>

And then tell GCC to look in /usr/include/tidy: gcc -I/usr/include/tidy script.cpp

At this point the header will be found. If you'll get other errors related to tidy (eg: some tidy functions are not defined) you'll need to link your binary to some library using GCC -l option.


EDIT after OP's massive edit.

Your problem here is that tidyx.h contains C++ code, and also your source file, looking to its extensions, seems to be a C++ source file. You'll need a C++ compiler in order to compile it. Use g++ instead of gcc:

g++ script.cpp