How to develop a cross-platform project in C ++?

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 often need to compile on both Windows and Linux.

I have single-platform projects that I still use, KDevelop on Linux and Visual Studio 2012 on Windows.

How can I use two different IDEs in two different operating systems with the same project?

  • Should I use a single cross-platform IDE?
  • Should I learn CMake (or similar) and configure it to work with both IDEs?
  • Could / Should I post my code on the Internet and automatically synchronize it with stand-alone projects?
  • Alternatives?

Thanks in advance to everyone.

EDIT:

Just to clarify, the project will be a simple server for the training protocol. There will be a client requesting the upload / download of some files to / from the server. With training, I mean that, for example, I should use pthreads / win32 threads instead of a higher-level C ++ thread library.

+4
source share
5 answers
  • Maybe - it really depends on what you feel most comfortable with. Since the project is not graphic, the entire IDE gives you file editing and compilation. Thus, you can create a project on one machine using the IDE, and then move the sources to another computer to compile them.

  • I personally would only have two makefiles, one for Linux and one for Widnows. It makes life pretty simple [you may have an โ€œexternalโ€ make file that selects the right one based on some kind of smart method].

  • Yes, you should find a version control system that works for both Windows and Linux (git, mercurial, subversion, bazaar and some others). Thus, you not only have a central repository [you can use any of your machines as a โ€œserverโ€ for any of them], but it also allows you to track your changes. Definitely worth your attention!

  • There are hundreds of different alternatives. But the simpler you keep it, the less complicated your tools are, the more time you spend on actually programming your project, and not, for example, on why CMake does not create the way you want.

Also, make sure that you allocate all your system code for one file for each architecture. Thus, it is easily ported to another architecture later, and this makes the MOST of your code compiled on both systems.

+4
source
  • It is usually easy to configure IDE project / assembly files to add / move / delete source files. Therefore, using a cross-platform IDE is not so important.
  • You can do this, I think CMake can also create project files for some IDEs, which can then be used to create a project.
  • Whether you want to post it online or not, this is your choice. What you must do is use some kind of version control. It is also useful to use a bug tracking system. If you still want to use open source code, using one of the existing hosting objects is yes.
  • Not really.

One comment: you will have more problems porting code to C ++. Building on top of tools like Qt is a huge help. If you want to stay closer to standard C ++, at least consider using Boost for things like threads, smart pointers, file system access. Good luck

+2
source

My recent experience offers a look at Qt. The IDE (QtCreator) is very good and available on all major platforms.

I used for a fairly simple project that uses fairly complex components such as OpenCV and ZBar. I am developing Linux, copying the source code on Windows, and recompiling.

I am having problems setting up OpenCV on both platforms, so I canโ€™t say it is very simple, but it works. Since you already know KDevelop, you should already know Qt.

In a recent trend, I also pay great attention to the fact that Qt5 is a platform for Ubuntu on smartphones. I really hope to see this development.

NTN

+1
source

How can I use two different IDEs in two different operating systems with the same project?

Should I use a single cross-platform IDE?

No. I think this is a question of the wrong question. To build a cross-platform project, your build scripts and the system-neutral nature of your code are important. Sometimes this can help create project files for your preferred development environment, but supporting multiple project files for multiple IDEs will only make it harder and harder for you. Instead, you should focus on finding a build system that minimizes the time spent on project maintenance.

For this, CMake and PreMake seem to be two of the best tools that can happen.

There are dozens of alternatives (such as SCons, Cook, kbuild, Jam and Boost Jam, and many others), but since CMake and PreMake generate project files and create scripts, they may be better solutions.

Your mileage will be different.

Could / Should I post my code on the Internet and automatically synchronize it with stand-alone projects?

You must have a reliable source of control that works wherever you are. Git and Mercurial seem to work best if you use some kind of "cloud" hosting, such as Github or BitBucket, but they by no means require it. Depending on your work environment and team size, you may prefer Subversion or PerForce or something else, but it depends on you and your team.

+1
source
  • this will help, you will most likely have to debug many platforms ... Qt Creator, Netbeans and Eclipse come to mind.

  • Yes. cmake or qmake for Qt is possible

  • Not a technical issue. Just use version control! github and gitorious are an easy choice for an open source project.

  • Qt is a hassle-free choice for a cross-platform C ++ GUI, as well as a decent choice for a network application without a GUI.

0
source

All Articles