C++ – How do I get the version of a program in linux

How do I get the version of a program in linux… here is a solution to the problem.

How do I get the version of a program in linux

In Windows you can do this:

CSystemInfo info;
this->m_strVersion = info. GetFileVersion( CFileSystemHelper::GetApplicationPath() + _T("/test.exe") );

Gets the version number.

How do I implement it in C++ on Linux?

Solution

Windows uses a version resource system with standard API support, and Linux and UNIX do not have such advanced concepts for a variety of reasons, from legacy to redundancy.

The best option is to query the local packaging system (RPM, APT, etc.), or try execution with the --version command-line argument, which is recommended GNU standard .

Sample RPM query on the Samba tool smbget command line:

# rpm -q -f /usr/bin/smbget --queryformat '%{version}\n'
3.0.33

Related Problems and Solutions