如何编译 C++使用 html tidy C++ 的程序
我从 ubuntu 存储库安装了 tidy-dev,检查了安装路径 - 没问题(/usr/include/tidy)。
但我找不到真正的标志来编译我的 c++ 脚本,其中包括来自 http://users.rcn.com/creitzel/tidy/tidyx.h
你能帮助我吗?
我的测试脚本文件名为 1.cpp,tidyx.h 我放在附近。 1.cpp内容:
#include "tidyx.h"
int main()
{
}
我尝试了一下,但是不行:
$ 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’
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’
如果你对这篇内容有疑问,欢迎到本站社区发帖提问 参与讨论,获取更多帮助,或者扫码二维码加入 Web 技术交流群。
绑定邮箱获取回复消息
由于您还没有绑定你的真实邮箱,如果其他用户或者作者回复了您的评论,将不能在第一时间通知您!
发布评论
评论(1)
要包含头文件,您需要使用
#include
预处理器指令。它将在编译器包含路径中查找头文件。如果
tidyx.h
位于/usr/include/tidy
中,您可以放入源文件:然后使用
gcc script.cpp
进行编译,因为/usr/include
很可能是编译器的默认包含路径。否则,您也可以放入源文件:
然后告诉 GCC 查看
/usr/include/tidy
:gcc -I/usr/include/tidy script.cpp
这时候就可以找到header了。如果您遇到与 tidy 相关的其他错误(例如:未定义某些 tidy 函数),您需要使用 GCC
-l
选项将二进制文件链接到某个库。OP 大量编辑后编辑。
这里的问题是
tidyx.h
包含 C++ 代码,而且您的源文件(查看其扩展名)似乎是 C++ 源文件。您需要一个 C++ 编译器来编译它。使用g++
代替gcc
: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: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:
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. Useg++
instead ofgcc
: