In this section:
libfoo
designates the library.libfoo.a
is an archive file that contains the compiled object (.o
) files; you must include the header (.h
) files separately.
sandbox/src/lib/libfoo
for the binaries. Optionally, create a separate directory for the header files (for example, sandbox/src/lib/libfoo/include
).
libfoo.a
and libfoo.so.1
to sandbox/src/lib/libfoo
. Create a symbolic link (for example, foo.so
) to libfoo.so.1
.
sandbox/src/lib/libfoo/include
.
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.
.c
files) and header files (.h
files).
.h
files) in sandbox/src/lib/libfoo
.
.h
files) to sandbox/src/lib/libfoo/include
(or include them with the binaries).
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>
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}
sandbox/src/sbin/application
as follows:
CFLAGS += -static DPLIBS += ${LIBFOO}
/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.
sandbox/src/release
to add the following line:
%TOPDIR%/lib/libfoo/libfoo.so.1 store=%INSTALLDIR%/lib/libfoo.so.1 mode=444
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.
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