可以单个 eclipse C++项目针对不同平台以不同方式链接不同库?
我有一个 C++ eclipse 项目,我想在 Windows 和 OSX 中轻松编译它。
该项目当前正在使用自动生成的 makefile。
我需要的库因平台而异。
在 osx 中,我使用 CoreMidi、CoreAudio 和 CoreFoundation 框架。 在 Windows 中,我使用 winmm.lib 和多线程库。
根据当前平台链接不同库/框架的最简单方法是什么?
我目前在 OSX 上使用 gcc 工具链。我应该开始使用交叉编译工具链吗?
我应该有两个项目吗?一种用于在 Windows 中工作,一种用于 osx,将它们都检查到版本控制中?
我应该编写自定义 makefile,而不是使用根据平台具有不同 g++ 参数的自动生成选项吗?
I have a C++ eclipse project that I would like to easily compile In Windows and OSX.
The project is currently using an automatically generated makefile.
The libraries that I need vary depending on the platform.
In osx I'm using the CoreMidi, CoreAudio, and CoreFoundation frameworks.
In Windows I'm using the winmm.lib and multithreaded libraries.
What's the simplest way to link different libraries/frameworks depending on the current platform?
I'm currently using the gcc toolchain on OSX. Should I start using the cross compile toolchain?
Should I have two projects. One for working in windows, and one for osx, checking them both in to version control?
Should I write a custom makefile instead of using the automatically generated option that has different g++ arguments depending on the platform?
如果你对这篇内容有疑问,欢迎到本站社区发帖提问 参与讨论,获取更多帮助,或者扫码二维码加入 Web 技术交流群。

绑定邮箱获取回复消息
由于您还没有绑定你的真实邮箱,如果其他用户或者作者回复了您的评论,将不能在第一时间通知您!
发布评论
评论(3)
我个人对一个项目有同样的目标,并得出结论 Qt 框架 是最好的选择我。它可以处理多种语言、unicode 字符串、XML、网络通信、本地用户界面、控制台应用程序:它可以做很多事情。
然而,正如保罗指出的那样,你确实必须从一开始就计划好。
Qt 在抽象平台方面做得很好(在一个名为 QtCore 的模块中),允许您编写普通的 C++ 代码,或者您可以选择包含一些 Qt C++ 语言扩展,这些扩展是由称为 moc(元对象编译器)的 Qt 帮助应用程序创建的vanilla C++,然后可以由最常见的 C++ 编译器进行编译。
它还有一个名为 qmake 的漂亮的跨平台 makefile 生成器,它可以处理项目文件,为其运行的平台创建正常的 make 文件。
我至少想到了 Windows XP 和 Windows 7、目前支持OSX 10.4、10.5、10.6。但请注意,OSX Lion(截至撰写本文时)尚未得到正式支持,但我怀疑它将在下一个版本中得到支持。
I personally had the same goal for a project and came to the conclusion the Qt framework was the best thing for me. It handles multiple languages, unicode strings, XML, network communications, native looking user interfaces, console applications: it can do an AWFUL lot.
However, as Paul pointed out, you really have to plan it from the start.
Qt does a good job of abstracting the platform away (in a module called QtCore) allowing you to write vanilla C++ code, or you can chose to include some Qt C++ language extensions which a Qt helper application called the moc (meta object compiler) creates vanilla C++ from, which can then be compiled by most common C++ compilers.
It also has a nifty cross-platform makefile generator called qmake which works on project files to create normal make files for the platform its running on.
Off the top of my head at least Windows XP & 7, OSX 10.4, 10.5, 10.6 are supported currently. But note that OSX Lion is (as of writing) not officially supported but I suspect it will be in the next release.
根据您的描述,我不确定您是否可以轻松使其跨平台。即使不使用第三方库,您也必须为 osx 和 windows 提供单独的代码。大多数时候,他们首先将系统设计为跨平台。将现有的单平台项目做到跨平台确实很难。如果你有跨平台的需求,最好先这样设计,然后从头开始重写。
Based on your description, I am not sure you can easily make it cross-platform. Even without using third-party library, you have to provide separate code for osx and windows. Most of time, they design the system as cross-platform first. It's really hard to make an existing project on single-platform to cross-one. If you have the cross-platform requirement, you'd better design in that way first and rewrite from scratch.
尽管 Eclipse 可以在 OS X 和 Windows 上正常运行,但它并不是设计用于这种方式使用的。
最好的方法是为每个平台使用单独的 IDE 项目。这是为多个平台拥有独特编译设置的最简单方法。
是的,您可以使用两个 eclipse 项目。另外,OSX 上有一个 X-Code 项目,MS Windows 上有一个 Visual Studio 项目也很常见。
Even though Eclipse can run fine on both OS X and Windows, it is not designed to be used in this way.
The best way to do it is to use separate IDE projects for each platform. This this is the easiest way to have unique compilation settings for multiple platforms.
Yes, you can use two eclipse projects. Alternatively, it's not unusual to have a X-Code project for OSX, and a Visual Studio Project for MS Windows.