Autotools and pkg-config will build nicely without modifying the build script even if the target environment is different. I've always used it somehow, so I'll sort out what I'm doing within my own range.
Autotools
Wikipedia Autotools Autotools is a type of tool and framework for developing software packages mainly on Unix-like operating systems (OS). This tool makes it easy to adapt packages to a wide variety of UNIX-compatible environments. Autotools mainly consists of autoconf / automake / libtools.
autoconf
Generate configure from configure.ac. The cross-compiler support is handled by configure.
If you create a cross-development environment with Yocto, after source the toolchain, configure as follows.
./configure ${CONFIGURE_FLAGS}
If you look at the contents of $ {CONFIGURE_FLAGS}, you can see that it seems that you are setting environment variables for the cross compiler.
echo ${CONFIGURE_FLAGS} --target=arm-poky-linux-gnueabi --host=arm-poky-linux-gnueabi --build=x86_64-linux --with-libtool-sysroot=/opt/poky/2.2+snapshot/sysroots/cortexa7hf-neon-vfpv4-poky-linux-gnueabi
automake
Generate Makefile.in from Makefile.am. At the time of Makefile.in, environment-specific settings are not reflected. The final Makefile is generated by configure adding environment-specific settings to Makefile.in.
libtool
I'm not using it, so I'll omit it.
pkg-config
Wikipedia pkg-config pkg-config is a means to provide various flags, paths, etc. required when using the library with a common interface.
In other words, the library is easy to use.
Ubuntu 16.04
hello world using glib
I haven't tried it in a clean environment, but you should have everything you need at ↓!
sudo apt-get install -y build-essential libglib2.0-0 libglib2.0-dev autoconf automake libtool
Build
git clone https://github.com/tomoyuki-nakabayashi/autotools-hello.git
cd autotools-hello
autoreconf -fi
./configure
make
Run
./src/hello
hello world
Except for using glib, I referred to "Hello, World" with GNU Autotools.
configure.ac
Added a line to check in configure.ac if glib is in the build environment.
PKG_CHECK_MODULES(GLIB, [glib-2.0])
PKG_CHECK_MODULES is a macro that interfaces with autoconf and pkg-config. In the first argument, specify the compile-time flag and the prefix used for library reference. In the second argument, specify the module name found in the pkg-config search path. (In my environment, the include path is "/usr/include/glib-2.0/", so "glib" is not good and you need to set it to "glib-2.0")
src/Makefile.am Add compile flags and library references using the prefix specified in PKG_CHECK_MODULES in configure.ac.
hello_CFLAGS = \
@CFLAGS@ \
@GLIB_CFLAGS@
hello_LDADD = \
@GLIB_LIBS@
What does this mean?
Looking at the log when make is executed, it seems that gcc is executed as ↓.
gcc -g -O2 -I/usr/include/glib-2.0 -I/usr/lib/x86_64-linux-gnu/glib-2.0/include -g -O2 -o hello hello-main.o -lglib-2.0
If you make while editing Makefile.am, CFLAGS is "-g -O2" and GLIB_CFLAGS is "-I / usr / lib / x86_64-linux-gnu / glib-2.0 / include". It can be seen that ", GLIB_LIBS works with" -lglib-2.0 ". Looking at the src / Makefile, it looks like this: I see.
GLIB_CFLAGS = -I/usr/include/glib-2.0 -I/usr/lib/x86_64-linux-gnu/glib-2.0/include
GLIB_LIBS = -lglib-2.0
When using the cross-build environment created by Yocto, it is as follows. I see.
GLIB_CFLAGS = -I/opt/poky/2.2+snapshot/sysroots/cortexa7hf-neon-vfpv4-poky-linux-gnueabi/usr/include/glib-2.0 -I/opt/poky/2.2+snapshot/sysroots/cortexa7hf-neon-vfpv4-poky-linux-gnueabi/usr/lib/glib-2.0/include
GLIB_LIBS = -lglib-2.0
By the way, at the time of src / Makefile.in, it is not an environment-specific path. That's what configure reflects environment-specific settings. I see.
GLIB_CFLAGS = @GLIB_CFLAGS@
GLIB_LIBS = @GLIB_LIBS@
I knew what I was doing for a moment.
Recommended Posts