Compiling and Linking Against a Library
The following is an example of using the library with a GCC compiler. The library is used by including the header filematrix.hand then calling the necessary library functions.
/* main.cpp (pseudocode) */ #include "matrix.h" int main(int argc, char* argv[]) { float *A, *B, *C, *D; float *J, *K, *L; float *X, *Y, *Z; ... mmultadd(A, B, C, D); ... mmult(J, K, L); ... madd(X, Y, Z); ... }
To compile against a library, the compiler needs the header file. The path to the header file is specified using the-I
switch. You can find example files in thesamples/libmatrix/usedirectory.
gcc –I /include –o main.o main.c
To link against the library, the linker needs the library. The path to the library is specified using the-L
switch. Also, ask the linker to link against the library using the-l
switch.
gcc –I /lib –o main.elf main.o -lmatrix
For detailed information on using the GCC compiler and linker switches refer to the GCC documentation.
Use a library at runtime
At runtime, the loader will look for the shared library when loading the executable. After booting the board into a Linux prompt and before executing the ELF file, add the path to the library to theLD_LIBRARY_PATH
environment variable. Thesd_card
created when building the library already has the library, so the path to the mount point for the sd_card must be specified.
For example, if the sd_card is mounted at/mnt
, use this command:
export LD_LIBRARY_PATH=/mnt