如何创建单独的库以包含在 C++/Eclipse 中
我已经获得了一些与 TinyXML 解析器一起使用的 C++ 代码。 然而,要做到这一点,我必须将 TinyXML 的源代码包含在我的常规源代码中。 我希望将 TinyXML 作为一个单独的库包含在内。 我正在使用 Eclipse 和 Cygwin C++ 编译器。 有什么好的方法可以做到这一点?
I've gotten some C++ code to work with the TinyXML parser. However, to do this I had to include the source code from TinyXML with my regular source code. I'd like to have TinyXML included as a separate library. I'm using Eclipse with the Cygwin C++ compiler. What's a good way to do this?
如果你对这篇内容有疑问,欢迎到本站社区发帖提问 参与讨论,获取更多帮助,或者扫码二维码加入 Web 技术交流群。
绑定邮箱获取回复消息
由于您还没有绑定你的真实邮箱,如果其他用户或者作者回复了您的评论,将不能在第一时间通知您!
发布评论
评论(2)
我假设您想将库与您自己的项目的源代码分开......但是当库不在同一文件夹中时您不知道如何构建。
假设您的库已经预编译了 *.lib 和 *.h 文件:
[脚注 - 1] GUI C/C++ 构建窗格是 gcc 命令行编译器/链接器的包装器...它只是在制作它更容易使用,因为它可以直观地向您展示一切。
[脚注 - 2] “+”图标将告诉编译器您的库 *.h 包含文件所在的位置。 编译器在编译之前需要 *.h 文件来了解您的库具有哪些函数原型。
假设您有实际的(未编译的)*.c 和 *.h:
I assume you want to separate the library from your own project's source code... but you don't know how to build when the library is not in the same folder.
Assuming your library has precompiled *.lib and *.h files:
[Footnote - 1] The GUI C/C++ build pane is a wrapper for gcc's command line compiler/linker... it is just making it easier to use because it shows you everything visually.
[Footnote - 2] The '+' icon is what will tell the compiler where your libraries *.h include files are located. The compiler needs the *.h files to know what function prototypes your library has before it compiles.
Assuming you have the actual ( not compiled ) *.c and *.h:
这基本上很容易。 您编译该库的源代码,并使用ar(1)构建该库。 是的,令人惊讶的是,图书馆只是一个档案馆; UNIX 在这方面很酷。
然后,您可以在构建最终代码时将代码作为静态库包含进来。
我不太使用 Eclipse,所以我无法告诉您 IDE 中的确切过程,但我相信您需要的是设置一个单独的项目来构建它。
现在,如果您想要构建 DLL,那么您需要使用一些特殊标志。 这里有一个不错的页面。
It's basically easy. You compile your source code for the library, and construct the library with ar(1). Yes, surprise, a library is just an archive; UNIX is cool that way.
You can then include the code as a static library when you build the final code.
I don't use Eclipse all that much so I can't tell you the exact process within the IDE, but I believe what you need is to set up a separate project to build it.
Now, if what you want is to build a DLL, then you need to use some special flags. There's a nice page here.