The process of porting libjpeg library under LINUX

1. Migration (source code download, decompression, configuration, modification of Makefile, compilation or cross compilation)

1.1 Find, analyze and configure the running script file

    (1) Generally, the first step of the ported library under linux is to configure it, and then it can be compiled. After decompression, you can usually find a similar config script file, and the configuration is to run this script. For example, when the libjpeg library runs a script, it will prompt you to add parameters to configure at runtime./config --XXX and so on.

  (2)  ./configure --prefix=/opt/libdecode --exec-prefix=/opt/libdecode --enable-shared --enable-static -build=i386 -host=arm

        Explanation: Why is this, no one has any experience at the beginning, Baidu, after running and configuring these parameters, the final generated useful things will be stored in the specified prefix ( prefix ) folder, you must ensure these before all configurations The file exists, it was created in advance

    (3) For the libjpeg library, there are many raw materials for generating makefiles, and makefiles will be generated when the above script is executed


1.2 Check, modify, compile Makefile

    (1) Check : open vi to see if there is anything that needs to be modified, generally look at CC=? ARCH=? , because we compile the makefile, the compilation process needs to use the compiled toolchain under the current architecture , generally CC=gcc, the gcc compilation tool under windows is used by default, and under linux, we use the compilation toolchain installed by ourselves, such as arm -none-linux-gnueabi-gcc, for the portability of the program, the makefiles in many projects use CC=arm-linux-gcc, so we have to establish a symbolic link under linux before

    (2) Modify: CC=arm-linux-gcc AR= arm-linux-ar rc and other similar operations

    (3) Compile : Go to make to compile and link the C files in the library into the so, a, and h files we need, and then go to make install-lib, and put the required files in the specified location (why do you need this step later? , Baidu to)


1.3 Deployment

    1.3.1  Deploy dynamic link library location selection (required at runtime, deployed in the root file system)

    (1) There are generally three locations that can be considered (when the Linux system is running, loading dynamic files will search for libraries under some files by default. If it is in any specified place, it needs to be exported to the environment variable to find the dynamic library):

            First: /lib
            Second: /usr/lib
            Third: Specify any directory, such as /opt/mylib in the root directory, after cp comes over, write and use the script ./xxx.sh before running, and finally put it in ~/bashrc.sh

                export LD_LIBRARY_PATH=/opt/mylib:$ LD_LIBRARY_PATH

    1.3.2  The role of deployed files

(1) The dynamic library is required by the runtime environment and is not required when compiling the program.

(2) The static library is only needed when it is statically linked, not when it is dynamically linked.

(3) The header file .h is used when compiling the program and is not required at runtime.

Summary: Static libraries and header files are needed during compilation and linking; dynamic libraries are needed at runtime.


2. Use libjpeg

2.1 Guide the compilation and linking of the main makefile in your own APP project, including the library, which is the first step in using a ported library

   2.1.1 Note the three compile link options: -I -l -L

        (1)-I是编译选项(准确的是说是预处理选项CFLAGS或者CPPFLAGS中指定),用来指定预处理时查找头文件的范围的。

        (2)-l是链接选项(LDFLAGS中指定),用来指定链接额外的库(譬如我们用到了数学函数,就用-lm,链接器就会去链接libm.so;那么我们使用了libjpeg,对应的库名字就叫libjpeg.so,就需要用-ljpeg选项去链接)

        (3)-L是链接选项(LDFLAGS中指定),用来告诉链接器到哪个路径下面去找动态链接库。之前我们放的地方/opt/libdecode/lib

        总结:-l是告诉链接器要链接的动态库的名字,而-L是告诉链接器库的路径        

     2.1.2  修改makefile

        (1)链接器的链接参数设置     LDFLAGS  := -ljpeg -L/opt/libdecode/lib

        (2)顺便说一下,编译这个makefile时,用的交叉编译工具链也是我们自己移植的,并且建立了符号链接


Guess you like

Origin http://43.154.161.224:23101/article/api/json?id=324841278&siteId=291194637