Wednesday, July 6, 2016

Configure static link "expect"

Introduction

Sometime it is useful to create a "static" link "expect" package. This enable us to have a self-contained package without a worry if other tools or libraries are available. A use case is to have expect run on a Juniper router or switch. When you run a "flex" image on a switch with Intel processor such as QFX series, or a EX9200, it is possible that you can install your own utilities written and compiling by using either FreeBSD 6.1, or Junos SDK. In this example, I am using a FreeBSD 6.1 VM to build expect package.

Configuring Expect

Read the README file to understand the general idea and the prerequisites. Since expect is a derivative of TCL it is very likely that you will also need to install Tcl 8.4 also. Please check the TCL code for more information.

The following command is what I use to configure expect.
This will also designate the location of the final directory to install into /var/tmp/expect ./configure --perfix=/var/tmp/expect --disable-load --disable-shared

After run the configure, it is time to run make to compile the software. The make will fail to build expect binary. But this is expected since we need to do a couple more things. I did the following modifications:

  • in Makefile line 397 - added "-lutil -static"
  • link libexpect545.a to libexpect.a using the following command:
    ln -s libexpect.a libexpect545.a
    The above is called soft linking - which will make libexpect545.a an alias of libexpect.a. IMHO, this could be done in the Makefile and I may put my version on github at some point
  • Run make install - this time it should work fine and all needed files installed at /var/tmp/expect

  • Monday, July 4, 2016

    Cannot find -lexpect545 error

    I was trying to compile expect for an old OS today and got stuck with the following error when linking
    ld: Cannot find -lexpect545
    It turns out that the problem with the default Makefile is to just creating libexpect.so.1 which is a dynamic link lib. But there is no recipe to create libexpect545.so.

    Fortunately, The fix is pretty easy. All I had to do is to link libexpect545.so to libexpect.so.1 with the following command:
    ln -s libexpect.so.1 libexpect545.so
    or if you are using static linking... try the following:
    ln -s libexpect.a libexpect545.a
    Yeah, I know. This is super annoying. How come they don't do it correctly. I probably should put mine up on Github just to track it.