如何编译 C++使用 html tidy C++ 的程序

发布于 2024-10-17 07:43:21 字数 1877 浏览 2 评论 0原文

我从 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 技术交流群。

扫码二维码加入Web技术交流群

发布评论

需要 登录 才能够评论, 你可以免费 注册 一个本站的账号。

评论(1

可爱咩 2024-10-24 07:43:22

要包含头文件,您需要使用 #include 预处理器指令。它将在编译器包含路径中查找头文件。

如果 tidyx.h 位于 /usr/include/tidy 中,您可以放入源文件:

#include <tidy/tidyx.h>

然后使用 gcc script.cpp 进行编译,因为 /usr/include 很可能是编译器的默认包含路径。

否则,您也可以放入源文件:

#include <tidyx.h>

然后告诉 GCC 查看 /usr/include/tidygcc -I/usr/include/tidy script.cpp

这时候就可以找到header了。如果您遇到与 tidy 相关的其他错误(例如:未定义某些 tidy 函数),您需要使用 GCC -l 选项将二进制文件链接到某个库。


OP 大量编辑后编辑

这里的问题是 tidyx.h 包含 C++ 代码,而且您的源文件(查看其扩展名)似乎是 C++ 源文件。您需要一个 C++ 编译器来编译它。使用 g++ 代替 gcc

g++ script.cpp

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
~没有更多了~
我们使用 Cookies 和其他技术来定制您的体验包括您的登录状态等。通过阅读我们的 隐私政策 了解更多相关信息。 单击 接受 或继续使用网站,即表示您同意使用 Cookies 和您的相关数据。
原文