How to Build LSB Applications
Finally, we get to the compiler wrapper, lsbcc and lsbc++. These are the same program; they simply are invoked with different names to indicate C or C++ mode. The general idea is you can use lsbcc wherever you would use GCC and lsbc++ wherever you would use g++.
This wrapper tool parses all of the options passed to it and rearranges them slightly. It then inserts a few extra options to cause the LSB-supplied headers and libraries to be used ahead of the normal system libraries. This tool also recognizes non-LSB libraries and forces them to be linked statically.
Because the LSB-supplied headers and libraries are inserted into the head of the search paths, it generally is safe to use things not in the LSB. Make sure, however, that they are not dependent on something that intentionally has been left out of the LSB headers and libraries and that they can be linked statically into the applications. This allows lsbcc to be transparent in most cases.
With the LSB development packages installed, porting a sample application becomes as easy as the normal three-step process, but with a slight difference:
CC=lsbcc ./configure make make install
By telling the configure script to use lsbcc instead of GCC, it conducts its various tests in an LSB environment and configures the software with any adjustments or limitations that may be required. Sometimes this results in a portable replacement for a feature being used. Generally, though, the overall functionality is close to what it would have been if GCC were used instead. As an exercise, try running a configure script both ways and compare the results. Another benefit of telling configure to use lsbcc is that it automatically sets CC to lsbcc in the generated makefiles, so you don't have to remember to pass it in (make CC=lsbcc) every time you run make.
The lsbcc command defaults to calling GCC with the modified arguments, but an environment variable can be used to tell it what compiler to use instead. This should work okay for any other compiler that is command-line option compatible with GCC.
Once the application has been built, use the lsbappchk program to test the program to see if it conforms to the LSB. This program checks the list of shared libraries used by your application; it also checks to make sure you are using only the interfaces permitted by the LSB. Here is an example run:
# /opt/lsbappchk/bin/lsbappchk /bin/ls /opt/lsbappchk/bin/lsbappchk for LSB Specification 1.3.3 Checking binary /bin/ls Incorrect program interpreter: /lib/ld-linux.so.2 Header[ 1] PT_INTERP Failed Found wrong interpreter in .interp section: /lib/ld-linux.so.2 instead of: /lib/ld-lsb.so.1 DT_NEEDED: librt.so.1 is used, but not part of the LSB Symbol clock_gettime used, but not part of LSB
The LSB does not require that the utilities provided by the OS be LSB-conforming themselves. Therefore, there isn't really an expectation that a distribution's own /bin/ls should pass this test. It simply makes for a handy example.
The output of lsbappchk tells us that /bin/ls is not an LSB-conforming application. The first problem is it wasn't linked with the LSB-defined program interpreter /lib/ld-lsb.so.1. The next problem is that the application is looking for the shared library librt.so.1, which is not included in the set of LSB-defined libraries. Lastly, the function clock_gettime() is used but is not linked statically to the application (it would have been found in librt.so.1).
The general approach to fixing an application such as this would be to rebuild the application using lsbcc, which would set the program interpreter correctly and cause librt.a to be used instead of librt.so. Sometimes, statically linking a library can cause new non-LSB symbols to be brought into the application, so this process may have to be repeated a couple of times.
In some larger applications or in sets of related applications, it may be desirable to create shared libraries that are used only by these applications. This is permissible under the LSB as long as the shared library is installed as part of the application and it resides in the application private data area, not in any of the system library locations. The -L option to lsbappchk lets you tell the testing tool the full path to the shared library, which is considered to be a part of the application for the purpose of testing conformance to the LSB. Here is an example of an LSB-conforming build of the Apache Web server, which uses three private shared libraries:
# /opt/lsbappchk/bin/lsbappchk \ -L /opt/lsb-apache/lib/libaprutil.so.0 \ -L /opt/lsb-apache/lib/libexpat.so.0 \ -L /opt/lsb-apache/lib/libapr.so.0 \ /opt/lsb-apache/sbin/httpd /opt/lsbappchk/bin/lsbappchk for LSB Specification 1.3.3 Adding symbols for library /opt/lsb-apache/lib/libaprutil.so.0 Adding symbols for library /opt/lsb-apache/lib/libexpat.so.0 Adding symbols for library /opt/lsb-apache/lib/libapr.so.0 Checking binary /opt/lsb-apache/sbin/httpd
- Promise Theory—What Is It?
- Integrating Trac, Jenkins and Cobbler—Customizing Linux Operating Systems for Organizational Needs
- New Products
- New Products
- RSS Feeds
- Tech Tip: Really Simple HTTP Server with Python
- Raspberry Pi: the Perfect Home Server
- Non-Linux FOSS: Remember Burning ISOs?