C ++ Programming on Linux

I am a software engineer, and I work in VC ++, C ++ on WIndows OS.

Are there any significant differences when it comes to coding in C ++ on a Linux environment.

Or are these just some of the adjustments we need to make when we need to code in C ++ on Linux.

+4
source share
9 answers

This will depend on the types of projects you have been working on and which Windows APIs. For example, if you used the native Windows API for everything, you would have a rather big task for you, it would be advisable for your projects to work beautifully with Vin.

On Linux, you have man pages, fairly detailed documentation about almost everything :). As mentioned above, take a look at POSIX, and although I recommend Qt - it provides a lot of abstractions for things you might want to learn on the Linux path (e.g. sockets, file system ...)

+9
source
  • Use the POSIX API instead of the Win32 API.
  • Use gtkmm, Qt or wxWidgets instead of MFC.
+5
source

The world of Linux programming is very different from how you know each other in the Windows world. You must understand this and get used to it. Once you understand, you will not want to return.

  • You have many small / good tools that work with each other, and not with the all-in-one MSVC solution. For instance:

    On Linux, you have the compiler as a standalone tool (the Gnu compiler compilation), you have the build system as a standalone tool (autotools, CMake). You have the GNU debugger as a standalone tool, and you have very good editors as a standalone tool (like the hard core vim / emacs).

    There are integrated development environments such as Eclipse, Netbeans, KDevelop, Anjuta but still you need to understand how the material works.

    You must understand that each individual tool is very powerful and integrates with others.

  • The OS level API is designed for simplicity. You rarely find calls like CreateProcessEx with bizzilion parameters, and you have a simple fork() + exec() . man - you are a true friend in everything related to the system API and the C standard library.

  • GUI You have two large Qt / GTK GUI libraries. Qt is a great C ++ library that makes working with a graphical interface enjoyable (unlike MFC). GTK has both the C and C ++ API GTK and GTKmm (no experience with them). A.

  • i18n / l10n / unicode is where Linux programming makes life easier. Almost all UTF-8. There is no extensive API, no problems opening Chinese file names with a simple fopen or ifstream, there is no 3rd part library that cannot open a file called Unicode. Great built-in tools like gettext, and good translation tools like KBabel.

  • Libraries are where Linux programming makes you hate Windows. Almost every free library is already installed or available with simple apt-get or yum install . there is no incompatibility crap for debugging / release, no DLL_EXPORT-ing, simple reliable, creating shared objects is as simple as working with static libraries (and most of them don't use static libraries at all).

My $ 0.02

(I am a Linux programmer who has a lot to do with Windows development) ...

+5
source

It depends on how many windows you used. The standard part of C ++ is the same, but using it will not give you much more than command line applications.

There's also the whole makefile-instead-letting-VS-build-for-you file. Depending on which tool (or IDE) you decide to use on Linux, this can be a big difference.

+2
source

I worked quite a bit on both platforms and, like both of them, but overall I found that most developers liked one thing and hate the other.

I would describe * nix as "geek friendly": many excellent and very flexible tools at your disposal. Some of them introduce a rigid learning curve, and some are simply broken, but still popular for some reason (make), but if you are willing to spend some time on the right training, the reward is high. In fact, I use many * nix tools even when working on Windows: vim, grep, perl, etc.

On the other hand, the Windows platform offers the Win32 API, which has more functionality than POSIX, is very well documented and supported by very good tools. Windows debuggers (especially windbg) are generally more powerful than any * nix debugger I've tried, although gdb is usually good enough for most tasks. Deploying executables is also easier than in the Linux world β€” in fact, the only really reliable way to deploy software on Linux is to send the source code and build it on client computers via config / make.

+1
source

I would suggest using Buildsystem as SCons, which works great on both Linux and Win32.

0
source

Take a look at the source for some open source project that runs on both Linux and Windows. As a rule, more than 80% of the code is identical, and the larger the project, the less it tends to be part of the system. Unfortunately, the system code may contain hard parts (streaming, non-blocking network IO, GUI details).

0
source

There are some significant differences that I can think of:

  • Instruments. Good and bad points. If you are used to Visual Studio, there is nothing like it. Each Linux IDE has some problems. On the other hand, especially debugging tools are very good. But in general, you must create your own working environment from the available ones.
  • API The documentation varies greatly. Some components are well documented, but often you end up reading the source code to figure out how something should work. On the other hand, you have the source code, so in the end, you have every opportunity to understand why something is not working.
  • The Linux community of programmers is usually very good, until you remember to behave and you find the right places. Some problems are not so bad, but sometimes you need to find other places.
  • It's not as simple as you might find out in the Windows world. Yes, some tools allow you to create projects without knowledge of the Makefile, but in fact you should learn to use them. On Windows, it’s far more common that you never edit project files (such as Make files) manually.
  • If you want to work in kernel space (drivers, etc.), C is better than C ++ because the kernel is written with this.
  • And I agree with the people offering Qt. Very nice widget set. Beat at least Swing (yes, I know, this is Java) is compressed. And Qt Creator is not so bad.
  • Don't underestimate the power of shell scripts! Very few Windows programmers have figured out something, but you can do a lot with them to help your work.
0
source

A typical Windows programmer that is used for Visual C ++ may find the following aspects of Linux C ++ programming or difficult:

  • Linux programming is not Linux programming, it is Unix programming. The basics of Unix programming go back much further than the roots of MS-DOS Windows, and this is evident in many places.

  • Windows programmers tend to think about the environment, they usually think about the IDE tools (your GUI editor, compiler, debugger). Unix programmers are usually hosted by different tribes, many Unix (Linux) C ++ programmers are very comfortable working from the command line without an IDE, and some, I am sure, use the IDE on Visual Studio Studio on Linux, a lot.

  • I personally found that I need to learn to read (and possibly write) a makefile, create standard Linux / Unix applications from standard sources (and understand how to enter my path through steps such as "autoconfiguration" and various "command options lines "that you can choose there) before I get the sensations and aroma of the environment.

  • Unless you are an experienced Linux system administrator, you might want to stick with Linux-friendly Linux distributions (like Ubuntu).

0
source

Source: https://habr.com/ru/post/1309307/


All Articles