Compiling DSFLib 0.1 with gcc on Linux

DSFLib 0.1

NOTE: this version of DSFLib, which I am calling "0.1", has been replaced with a new version that I am calling "0.2". Please see the page DSFTool for gcc.

Although there are no "official" tools for editing X-Plane scenery, a C/C++ library called DSFLib has been made available as Free Software for developers to create their own tools. Since I am primarily a Linux user and DSF2Text is available only for Windows, I compiled DSFLib using gcc under Linux. Apparently I was the first one to do so successfully, since modifications had to be made for the library to compile. I have not yet used the library beyond a simple test application.

Download

DSFLib for gcc

Building the Library

After unzipping the archive, the directory called DSFLib contains two subdirectories. Library contains the library code, and test contains the code for examples and test cases. To compile the library:

g++ -fpic -g -c *.cpp gcc -fpic -g -c md5.c

To link the library:

g++ -shared -Wl,-export-dynamic -o libDSF.so *.o

Building the Examples

Copy libDSF.so to the test directory. The two test codes included with the original DSFlib are called DSFLib_Print.cpp and DSFLib_TestGen.cpp. Note that they lack a main function so they will not run as stand-alone programs. I modified DSFLib_Print.cpp to run as a stand-alone program, which is called print.cpp. To build my test program with the example .DSF file:

g++ -g -c print.cpp g++ -L. -lDSF -o print -Wl,-rpath,. print.o

To run my test program:

./print +33-120.dsf test.txt

Explanation of Compiling Options

  • -c Compile but do not link
  • -g add debugging symbols for gdb (optional)
  • -o filename create file with name filename
  • -fpic generate position-independent library code

Explanation of Linking Options

I chose to build DSFLib as a shared library. It would also make sense to link it statically--in that case, adjust the options accordingly.

  • -shared build a shared library rather than an application
  • -Wl,-export-dynamic -Wl followed by a comma passes options directly to the linker. -export-dynamic ensures that all symbols are added to the dynamic symbol table so they will be visible at runtime.
  • -o filename create file with name filename
  • -Wl,-rpath,. -Wl followed by a comma passes options directly to the linker. -rpath,. adds the current directory to the path where the runtime linker looks for shared libraries.
  • -L. Look for a library in the current directory (.)
  • -lDSF Link to a file called libDSF.so