问题描述
几个月来,我写了一些很好的泛型足够的功能,我想建立一个库和链接动态,而不是导入50多个头/源文件。
Over the months I've written some nice generic enough functionality that I want to build as a library and link dynamically against rather than importing 50-odd header/source files.
该项目是在Xcode和Dev-C ++(我明白,我可能必须去命令行做我想要的),并必须链接到OpenGL和SDL(动态在SDL的情况下)。目标平台是Windows和OS X。
The project is maintained in Xcode and Dev-C++ (I do understand that I might have to go command line to do what I want) and have to link against OpenGL and SDL (dynamically in SDL's case). Target platforms are Windows and OS X.
我在看什么?
- 如果需要,
库将会是什么入口点? - 我的代码需要更改什么?
(调用约定?) - 如何发布?我的理解
是标题和编译的
库(.dll,.dylib(,.framework),
无论它会是什么)需要
可用于项目 -
特别是作为模板功能
不能通过
性质包括在库中。 - 还需要注意什么? >
- What will be the entry point of mylibrary if it needs one?
- What do I have to change in my code?(calling conventions?)
- How do I release it? My understandingis that headers and the compiledlibrary (.dll, .dylib(, .framework),whatever it'll be) need to beavailable for the project -especially as template functionalitycan not be included in the library bynature.
- What else I need to be aware of?
推荐答案
我建议建立一个statc库而不是DLL。如果你这样做的话,导出C ++函数和类的很多问题都会消失,前提是你只打算链接由你构建库的同一个编译器生成的代码。
I'd recommend building as a statc library rather than a DLL. A lot of the issues of exporting C++ functions and classes go away if you do this, provided you only intend to link with code produced by the same compiler you built the library with.
构建静态库非常容易,因为它只是.o / .obj文件的集合 - 有点像ZIP文件,但没有压缩。没有必要导出任何东西 - 只需将库包含在应用程序链接的文件列表中。要访问特定的函数或类,只需包括相关的头文件。注意,你不能摆脱头文件 - C ++编译模型,特别是对于模板,取决于它们。
Building a static library is very easy as it is just an collection of .o/.obj files - a bit like a ZIP file but without compression. There is no need to export anything - just include the library in the list of files that your application links with. To access specific functions or classes, just include the relevant header file. Note you can't get rid of header files - the C++ compilation model, particularly for templates, depends on them.
这篇关于将C ++源代码构建为库 - 从哪里开始?的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持!