如何开发跨平台的C ++项目? [英] How to develop a cross-platform C++ project?

查看:347
本文介绍了如何开发跨平台的C ++项目?的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我是C ++初学者,并且开始开发我的第一个跨平台C ++项目.我需要使用特定于平台的调用(Win32和POSIX),因此我需要在Windows和Linux中频繁进行编译.

I'm a C++ beginner and I'm starting to develop my first cross-platform C++ project. I need to use platform-specific calls (Win32 and POSIX) so I need to compile frequently both in Windows and Linux.

到目前为止,我正在使用的Whit单平台项目是Linux中的KDevelop和Windows中的Visual Studio 2012.

Whit single-platform projects I'm using, until now, KDevelop in Linux and Visual Studio 2012 in Windows.

如何在同一个项目的两个不同操作系统中使用两个不同的IDE?

How can I use two different IDEs in two different Operating Systems with the same project?

  1. 我应该使用一个跨平台的IDE吗?
  2. 我应该学习CMake(或类似产品)并将其配置为可在两个IDE上同时使用吗?
  3. 我可以/应该将代码托管在网络中并与离线项目自动同步吗?
  4. 替代品?

预先感谢大家.

为澄清起见,该项目将是用于学术协议的简单服务器.会有一个客户端要求向服务器上载/从服务器检索某些文件. 例如,使用 scholastic 意味着我必须使用pthreads/win32线程而不是更高级别的C ++线程库.

Just for clarification, the project will be a simple server for a scholastic protocol. There will be a client asking for upload/retrieve some files to/from the server. With scholastic I mean that, for example, I have to use pthreads/win32 threads instead of an higher level C++ threads library.

推荐答案

  1. 也许-确实取决于您觉得最舒适的情况.由于该项目是非图形项目,因此IDE所提供的只是文件的编辑和编译.因此,您可以在具有IDE的一台计算机上构建项目,然后将源移动到另一台计算机上进行编译.

  1. Maybe - really depends on what you feel most comfortable with. As the project is non-graphical, all the IDE gives you is editing of files and compilation. So you can build the project on one machine with the IDE there, and then move the sources to another machine for compiling there.

我个人只有两个makefile,一个用于Linux,一个用于Widnows.使生活变得相当简单[您可以有一个外部" makefile,它可以基于某种聪明的方法选择正确的文件].

I personally would just have two makefiles, one for Linux and one for Widnows. Makes life fairly simple [you could have a "outer" makefile that picks the right one based on some clever method].

是的,您应该找到一个适用于Windows和Linux的版本控制系统(git,mercurial,subversion,集市和其他几个版本).这样,您不仅拥有一个中央存储库(可以将其中任何一台计算机用作其中任何一个的服务器"),而且还可以跟踪更改.绝对值得做!

Yes, you should find a version control system that works for both Windows and Linux (git, mercurial, subversion, bazaar and several others). That way, not only do you have a central repository [you can use either of your machines as "server" for any of these], but it also allows you to keep track of your changes. Definitely worthwile doing!

有数百种不同的选择.但是,您将其保留得越简单,工具越不复杂,您就会有更多的时间花在实际编程项目上,而不是例如弄清楚为什么CMake并没有按照您的期望来构建.

There are hundreds of different alternatives. But the simpler you keep it, and the less complicated your tools are, the more time you get to spend on actually programming your project, rather than, for example, figure out why CMake isn't building the way you want it to.

此外,请确保您将所有特定于系统的代码分离到每个体系结构的一个文件中.这样,以后很容易移植到另一个体系结构,并且使您的代码的大部分都能在两个系统上编译.

Also, make sure that you separate out all your system-specific code to one file per architecture. That way, it's easy to port to another architecture later, and it makes MOST of your code compile on both systems.

这篇关于如何开发跨平台的C ++项目?的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆