Adding an Outside Library to Your Application

This section describes how to add your own or a third-party library to an SDK application package.

In this section:

There are two ways to add libraries to your development sandbox:

Note:
You must ensure sure any libraries you add are compatible with the FreeBSD-based Vmware VBE.

Adding Precompiled Libraries

Follow these steps to add a precompiled library.
  1. Create the directory sandbox/src/lib/libfoo for the binaries. Optionally, create a separate directory for the header files (for example, sandbox/src/lib/libfoo/include).

  2. Copy libfoo.a and libfoo.so.1 to sandbox/src/lib/libfoo. Create a symbolic link (for example, foo.so) to libfoo.so.1.

  3. Copy the header files either to the same directory as the binaries or to a separate directory, such as sandbox/src/lib/libfoo/include.

  4. Update the makefile at sandbox/src/build/mk/libnames.mk to add the library name, path to the header files, library dependencies, and so forth. For example:

        LIBFOO = ${SRCTOP}/lib/libfoo/libfoo.a
        INCLUDES_libfoo = -I${SRCTOP}/lib/libfoo/include
        DPLIBS_libfoo = ${LIBFOO-DEPENDENCY}
    

    See Notes on Build Makefile Variables for additional notes on makefile variables.

Adding and Compiling Source Code

The instructions in this section apply both to writing your own library and to adding a third-party library for which you have all the source files (.c files) and header files (.h files).

  1. Create the directories as you did in Adding Precompiled Libraries.

  2. Add or write your source files (.c files) and private header files (.h files) in sandbox/src/lib/libfoo.

  3. Add or write your public header files (.h files) to sandbox/src/lib/libfoo/include (or include them with the binaries).

  4. Create a file named Makefile in sandbox/src/lib/libfoo and use the following as a template for the contents:

        LIB = foo
    
        SHLIB_MAJOR = 1
        SHLIB_MINOR = 0
    
        FOO_SRC = ${SRCTOP}/lib/libfoo
    
        .PATH: ${FOO_SRC}
        SRCS = foo.c
    
        CFLAGS += <flags>
    
        DPLIBS += <dependency>
    
        SHLIB_LDFLAGS.${MACHINE} += -Wl,-rpath=${Junos_SDK_INSTALLDIR}/lib
    
       .include <bsd.lib.mk>
    

  5. Update the makefile at sandbox/src/build/mk/libnames.mk to add the library name, path to the header files, library dependencies and so forth. For example:

        LIBFOO = ${OBJTOP}/lib/libfoo/libfoo.a
        INCLUDES_libfoo = -I${SRCTOP}/lib/libfoo/include
        DPLIBS_libfoo = ${LIBFOO-DEPENDENCY}
    

Linking Static and Shared Libraries

Once you have set up your directories and edited the makefiles, follow these steps to link the libraries.

  1. Link the static libraries: Update the makefile in sandbox/src/sbin/application as follows:

        CFLAGS += -static
        DPLIBS += ${LIBFOO}
    

  2. Link the shared libraries: All SDK user shared libraries are installed into /opt/sdk/provider/lib and you must specify this path when the application is built. To do this, update the makefile in sandbox/src/sbin/application as follows, where provider indicates the provider ID (for details on the provider ID, see Porting an SDK Build Environment from a Release Prior to 9.6):

        DPLIBS += ${LIBFOO}
        LDFLAGS += -Wl,-rpath=${Junos_SDK_INSTALLDIR}/lib
     

    See Notes on Build Makefile Variables for additional notes on makefile variables.

Packaging the Libraries

You must package any shared libraries you are linking and install them in the Junos system. To do this, update the manifest file in sandbox/src/release to add the following line:

%TOPDIR%/lib/libfoo/libfoo.so.1 store=%INSTALLDIR%/lib/libfoo.so.1 mode=444

Notes on Build Makefile Variables

When you write a makefile for a library that will then be used in an SDK application, you sometimes include the variables SRC_LIBS and DPLIBS. The following notes assume you are writing a library named libfoo and using it in your SDK application.

SRC_LIBS: Specifies including header files with another library’s source code. Example: libfoo’s makefile could include the line: SRC_LIBS += ${LIBM} ${LIBZ} to specify including math.h and zlib.h in the libfoo build.

DPLIBS: Specifies which libraries an application links to. This is irrelevant for a library makefile but essential for an application makefile. Example: The makefile for your application includes the line DPLIBS += ${LIBM} ${LIBZ} ${LIBPTHREAD} to specify that the math, zlib, and pthread libraries must be linked to the application build.

For both SRC_LIBS and DP_LIBS, the system automatically adds –I path-to- library-header-files on the gcc line.

Testing Your Application

To test your work, create a test.c file that has a #include with some headers from the library, and add the file to the list of compiled sources in your build makefile. If you are building source code, your library will be compiled as part of the build process, and any compiler errors or warnings in the code will stop the build process.

Porting an SDK Build Environment from a Release Prior to 9.6


© 2007-2009 Juniper Networks, Inc. All rights reserved. The information contained herein is confidential information of Juniper Networks, Inc., and may not be used, disclosed, distributed, modified, or copied without the prior written consent of Juniper Networks, Inc. in an express license. This information is subject to change by Juniper Networks, Inc. Juniper Networks, the Juniper Networks logo, and JUNOS are registered trademarks of Juniper Networks, Inc. in the United States and other countries. All other trademarks, service marks, registered trademarks, or registered service marks are the property of their respective owners.
Generated on Sun May 30 20:26:47 2010 for Juniper Networks Partner Solution Development Platform JUNOS SDK 10.2R1 by Doxygen 1.4.5