D
D
DarkByte20152016-12-27 22:11:17
C++ / C#
DarkByte2015, 2016-12-27 22:11:17

How are cross-platform libraries written?

The following question has long been of interest: how are cross-platform libraries generally written? In outline? Those. I can only suggest two options:
either a separate implementation based on the api of the system is written for each OS (Windows, Linux, Apple), and then through macros it is done so that, for example, if Windows is used, the Windows implementation is used, etc.
or somehow it can be written in assembler ... Ie. for example, if a GUI library (such as Qt) then, for example, manually drawing buttons and other interface elements pixel by pixel, etc. Here I can’t even imagine how dreary it is and whether it’s real at all.

Answer the question

In order to leave comments, you need to log in

2 answer(s)
R
Rou1997, 2016-12-28
@DarkByte2015

or a separate implementation based on the system api is written for each OS (Windows, Linux, Apple), and then through macros it is done so that, for example, if Windows is used, the Windows implementation is used, etc.

Something like this, for compilation - preprocessor macros, for execution - there are different ways, you can change the values ​​\u200b\u200bof constants through the same macros.
In access below the application level, the main role is played not by the PL, but by the introduction into the OS, in standard ways (drivers, etc.) or with the help of injections, etc., Assembler is not the main thing here, it's just very flexible and very inconvenient " format" of executable code and no more.
No one draws by pixels, on the other hand, the use of standard WinAPI controls (CreateWindow) "in its pure form" is also avoided, they are not flexible enough and in the end there are simply very few of them, it is better to implement your own "bicycles", but for drawing it is used The highest-level GDI/GDI+/OpenGL/DirectDraw interface that draws images "wired" into the library, and not by pixels at all, but entirely.
And if graphics need to match the system theme, then UxTheme is also used - also a library from WinAPI.
Is it? In Qt Widgets, it seems to be just a system look and feel.
But in Quick (QML) - yes, there the images are "hardwired" into the library itself and it draws them through the system API of each OS.

V
Vitaly, 2016-12-27
@vt4a2h

First option. System API + defines for choosing an implementation.
A different backend can be used to render widgets. You can google (in English, of course) how Qt renders widgets, since there is a lot of material.

Didn't find what you were looking for?

Ask your question

Ask a Question

731 491 924 answers to any question