cygwin下用arm-xscale-linux-gnueabi交叉编译libcgi

【背景】

折腾:

【记录】用交叉编译器arm-xscale-linux-gnueabi交叉编译一个基于嵌入式Linux的无线HART的项目

期间,却发现,include的路径中有:

-I xxx/armxscalelibcgi/include

所以,还需要一个库libcgi。

其中,此处已有源码:libcgi-1.0

【折腾过程】

1.先去看看代码和配置:

CLi@PC-CLI-1 ~/develop/libcgi/libcgi-1.0
$ ls
AUTHORS*  autogen.sh*  BUGS*  ChangeLog*  configure*  configure.in*  doc/  examples/  install-sh*  Makefile.in*  README*  src/  THANKS*  TODO*

CLi@PC-CLI-1 ~/develop/libcgi/libcgi-1.0
$ ./configure --help
Usage: configure [options] [host] Options: [defaults in brackets after descriptions] Configuration: --cache-file=FILE cache test results in FILE --help print this message --no-create do not create output files --quiet, --silent do not print `checking...' messages --version print the version of autoconf that created configure Directory and file names: --prefix=PREFIX install architecture-independent files in PREFIX [/usr/local] --exec-prefix=EPREFIX install architecture-dependent files in EPREFIX [same as prefix] --bindir=DIR user executables in DIR [EPREFIX/bin] --sbindir=DIR system admin executables in DIR [EPREFIX/sbin] --libexecdir=DIR program executables in DIR [EPREFIX/libexec] --datadir=DIR read-only architecture-independent data in DIR [PREFIX/share] --sysconfdir=DIR read-only single-machine data in DIR [PREFIX/etc] --sharedstatedir=DIR modifiable architecture-independent data in DIR [PREFIX/com] --localstatedir=DIR modifiable single-machine data in DIR [PREFIX/var] --libdir=DIR object code libraries in DIR [EPREFIX/lib] --includedir=DIR C header files in DIR [PREFIX/include] --oldincludedir=DIR C header files for non-gcc in DIR [/usr/include] --infodir=DIR info documentation in DIR [PREFIX/info] --mandir=DIR man documentation in DIR [PREFIX/man] --srcdir=DIR find the sources in DIR [configure dir or ..] --program-prefix=PREFIX prepend PREFIX to installed program names --program-suffix=SUFFIX append SUFFIX to installed program names --program-transform-name=PROGRAM run sed PROGRAM on installed program names Host type: --build=BUILD configure for building on BUILD [BUILD=HOST] --host=HOST configure for HOST [guessed] --target=TARGET configure for TARGET [TARGET=HOST] Features and packages: --disable-FEATURE do not include FEATURE (same as --enable-FEATURE=no) --enable-FEATURE[=ARG] include FEATURE [ARG=yes] --with-PACKAGE[=ARG] use PACKAGE [ARG=yes] --without-PACKAGE do not use PACKAGE (same as --with-PACKAGE=no) --x-includes=DIR X include files are in DIR --x-libraries=DIR X library files are in DIR CLi@PC-CLI-1 ~/develop/libcgi/libcgi-1.0 $

2.直接去配置:

./configure --prefix=$HOME/develop/crosstool-ng/x-tools/libcgi --build=i686-pc-cygwin --target=arm-xscale-linux-gnueabi --host=arm-xscale-linux-gnueabi CC=arm-xscale-linux-gnueabi-gcc

结果说是不支持这个CC:

CLi@PC-CLI-1 ~/develop/libcgi/libcgi-1.0
$ ./configure --prefix=$HOME/develop/crosstool-ng/x-tools/libcgi --build=i686-pc-cygwin --target=arm-xscale-linux-gnueabi --host=arm-xscale-linux-gnueabi CC=arm-xscale-linux-gnueabi-gcc
configure: warning: CC=arm-xscale-linux-gnueabi-gcc: invalid host type
creating cache ./config.cache
checking for gcc... gcc
checking whether the C compiler (gcc  ) works... yes
checking whether the C compiler (gcc  ) is a cross-compiler... no
checking whether we are using GNU C... yes
checking whether gcc accepts -g... yes
checking for a BSD compatible install... /usr/bin/install -c checking how to run the C preprocessor... gcc -E checking for ANSI C header files... yes updating cache ./config.cache creating ./config.status creating Makefile creating src/config.h src/config.h is unchanged

3.所以,去掉CC:

./configure --prefix=$HOME/develop/crosstool-ng/x-tools/libcgi --build=i686-pc-cygwin --target=arm-xscale-linux-gnueabi --host=arm-xscale-linux-gnueabi

试试:

CLi@PC-CLI-1 ~/develop/libcgi/libcgi-1.0
$ ./configure --prefix=$HOME/develop/crosstool-ng/x-tools/libcgi --build=i686-pc-cygwin --target=arm-xscale-linux-gnueabi --host=arm-xscale-linux-gnueabi
loading cache ./config.cache
checking for gcc... (cached) gcc
checking whether the C compiler (gcc  ) works... yes
checking whether the C compiler (gcc  ) is a cross-compiler... no
checking whether we are using GNU C... (cached) yes
checking whether gcc accepts -g... (cached) yes
checking for a BSD compatible install... (cached) /usr/bin/install -c checking how to run the C preprocessor... (cached) gcc -E checking for ANSI C header files... (cached) yes creating ./config.status creating Makefile creating src/config.h src/config.h is unchanged

4.然后再去make编译:

CLi@PC-CLI-1 ~/develop/libcgi/libcgi-1.0
$ make
cc    -c -o src/error.o src/error.c
cc    -c -o src/cgi.o src/cgi.c
cc    -c -o src/session.o src/session.c
cc    -c -o src/base64.o src/base64.c
cc    -c -o src/md5.o src/md5.c
cc    -c -o src/string.o src/string.c
cc    -c -o src/general.o src/general.c
cc    -c -o src/list.o src/list.c cc -c -o src/cookie.o src/cookie.c ar rc src/libcgi.a src/error.o src/cgi.o src/session.o src/base64.o src/md5.o src/string.o src/general.o src/list.o src/cookie.o cc -shared -o src/libcgi.so src/error.o src/cgi.o src/session.o src/base64.o src/md5.o src/string.o src/general.o src/list.o src/cookie.o +---------------------------------------+ | Thanks for using LibCGI | +---------------------------------------+ | LibCGI is getting better because | | people like you are using it. So, if | | LibCGI is helping you in some way, | | please help us to improve it, sending | | suggestions, bug reports, bug fixes, | | and specially improvment code. | | You can subscribe to the mailing list | | or send a mail to the author. | +---------------------------------------+---------------------------+ | List: http://lists.sourceforge.net/lists/listinfo/libcgi-general | +-------------------------------------------------------------------+

和明显,不是交叉编译。

5.去看了下,.o,也的确只是x86的,不是arm的:

CLi@PC-CLI-1 ~/develop/libcgi/libcgi-1.0
$ file src/
base64.c     cgi.c        cgi.o        config.h.in  cookie.o     error.h      general.c    libcgi.a     list.c       md5.c        session.c    session.o    string.o
base64.o     cgi.h        config.h     cookie.c     error.c      error.o      general.o    libcgi.so    list.o       md5.o        session.h    string.c

CLi@PC-CLI-1 ~/develop/libcgi/libcgi-1.0
$ file src/cgi.o
src/cgi.o: 80386 COFF executable not stripped - version 30821

6.参考:

How to libcgi?

以及去看了:

libcgi-1.0\Makefile

中的:

.c.o: $(CC) $(FLAGS) -c $<

所以,去重新配置一下:

CLi@PC-CLI-1 ~/develop/libcgi/libcgi-1.0
$ ./configure --prefix=$HOME/develop/crosstool-ng/x-tools/libcgi --build=i686-pc-cygwin --target=arm-xscale-linux-gnueabi --host=arm-xscale-linux-gnueabi
loading cache ./config.cache
checking for gcc... (cached) gcc
checking whether the C compiler (gcc  ) works... yes
checking whether the C compiler (gcc  ) is a cross-compiler... no
checking whether we are using GNU C... (cached) yes
checking whether gcc accepts -g... (cached) yes
checking for a BSD compatible install... (cached) /usr/bin/install -c checking how to run the C preprocessor... (cached) gcc -E checking for ANSI C header files... (cached) yes creating ./config.status creating Makefile creating src/config.h src/config.h is unchanged

7.然后再在make的时候加上CC参数

CLi@PC-CLI-1 ~/develop/libcgi/libcgi-1.0
$ make CC=arm-xscale-linux-gnueabi-gcc

结果没东西需要重新编译的:

CLi@PC-CLI-1 ~/develop/libcgi/libcgi-1.0
$ make CC=arm-xscale-linux-gnueabi-gcc



+---------------------------------------+
|       Thanks for using LibCGI         |
+---------------------------------------+
| LibCGI is getting better because      |
| people like you are using it. So, if | | LibCGI is helping you in some way, | | please help us to improve it, sending | | suggestions, bug reports, bug fixes, | | and specially improvment code. | | You can subscribe to the mailing list | | or send a mail to the author. | +---------------------------------------+---------------------------+ | List: http://lists.sourceforge.net/lists/listinfo/libcgi-general | +-------------------------------------------------------------------+

8.所以去clean一把:

CLi@PC-CLI-1 ~/develop/libcgi/libcgi-1.0
$ make clean
find src/ -name *.*o -exec rm -f {} \; find src/ -name *.a -exec rm -f {} \;

再重新配置:

CLi@PC-CLI-1 ~/develop/libcgi/libcgi-1.0
$ ./configure --prefix=$HOME/develop/crosstool-ng/x-tools/libcgi --build=i686-pc-cygwin --target=arm-xscale-linux-gnueabi --host=arm-xscale-linux-gnueabi
loading cache ./config.cache
checking for gcc... (cached) gcc
checking whether the C compiler (gcc  ) works... yes
checking whether the C compiler (gcc  ) is a cross-compiler... no
checking whether we are using GNU C... (cached) yes
checking whether gcc accepts -g... (cached) yes
checking for a BSD compatible install... (cached) /usr/bin/install -c checking how to run the C preprocessor... (cached) gcc -E checking for ANSI C header files... (cached) yes creating ./config.status creating Makefile creating src/config.h src/config.h is unchanged

make加CC,然后可以交叉编译了:

CLi@PC-CLI-1 ~/develop/libcgi/libcgi-1.0
$ make CC=arm-xscale-linux-gnueabi-gcc
arm-xscale-linux-gnueabi-gcc    -c -o src/error.o src/error.c
arm-xscale-linux-gnueabi-gcc    -c -o src/cgi.o src/cgi.c
arm-xscale-linux-gnueabi-gcc    -c -o src/session.o src/session.c
arm-xscale-linux-gnueabi-gcc    -c -o src/base64.o src/base64.c
arm-xscale-linux-gnueabi-gcc    -c -o src/md5.o src/md5.c

9.但是结果出错问题了:

【已解决】cygwin下用arm-xscale-linux-gnueabi交叉编译libcgi出错:src/string.c:587:2: error: incompatible type for argument 2 of ‘__builtin_va_copy’

10.make是编译完了。

现在去试试安装:

CLi@PC-CLI-1 ~/develop/libcgi/libcgi-1.0
$ make install
cp src/libcgi.a /home/CLi/develop/crosstool-ng/x-tools/libcgi/lib
cp src/libcgi.so /home/CLi/develop/crosstool-ng/x-tools/libcgi/lib
cp src/cgi.h /home/CLi/develop/crosstool-ng/x-tools/libcgi/include
cp src/session.h /home/CLi/develop/crosstool-ng/x-tools/libcgi/include

11.本以为OK了,但是突然坑爹的发现,安装目录中lib和include,都是文件,而不是文件夹:

CLi@PC-CLI-1 ~/develop/libcgi/libcgi-1.0
$ ll /home/CLi/develop/crosstool-ng/x-tools/libcgi
total 48K
-rwxr-xr-x 1 CLi Domänen-Benutzer 1.1K Aug  6 12:59 include*
-rw-r--r-- 1 CLi Domänen-Benutzer  44K Aug  6 12:59 lib

所以,删除掉此两个文件,新建两个文件夹,手动重新拷贝试试:

CLi@PC-CLI-1 ~/develop/libcgi/libcgi-1.0
$ rm /home/CLi/develop/crosstool-ng/x-tools/libcgi/*

CLi@PC-CLI-1 ~/develop/libcgi/libcgi-1.0
$ ll /home/CLi/develop/crosstool-ng/x-tools/libcgi
total 0

CLi@PC-CLI-1 ~/develop/libcgi/libcgi-1.0
$ mkdir /home/CLi/develop/crosstool-ng/x-tools/libcgi/lib

CLi@PC-CLI-1 ~/develop/libcgi/libcgi-1.0 $ mkdir /home/CLi/develop/crosstool-ng/x-tools/libcgi/include CLi@PC-CLI-1 ~/develop/libcgi/libcgi-1.0 $ cp src/libcgi.a /home/CLi/develop/crosstool-ng/x-tools/libcgi/lib/ CLi@PC-CLI-1 ~/develop/libcgi/libcgi-1.0 $ cp src/libcgi.so /home/CLi/develop/crosstool-ng/x-tools/libcgi/lib/ CLi@PC-CLI-1 ~/develop/libcgi/libcgi-1.0 $ cp src/cgi.h /home/CLi/develop/crosstool-ng/x-tools/libcgi/include/ CLi@PC-CLI-1 ~/develop/libcgi/libcgi-1.0 $ cp src/session.h /home/CLi/develop/crosstool-ng/x-tools/libcgi/include/ CLi@PC-CLI-1 ~/develop/libcgi/libcgi-1.0 $ ll /home/CLi/develop/crosstool-ng/x-tools/libcgi total 0 drwxr-xr-x+ 1 CLi Domänen-Benutzer 0 Aug 6 13:04 include/ drwxr-xr-x+ 1 CLi Domänen-Benutzer 0 Aug 6 13:03 lib/ CLi@PC-CLI-1 ~/develop/libcgi/libcgi-1.0 $ ll /home/CLi/develop/crosstool-ng/x-tools/libcgi/include/ total 12K -rwxr-xr-x 1 CLi Domänen-Benutzer 4.3K Aug 6 13:04 cgi.h* -rwxr-xr-x 1 CLi Domänen-Benutzer 1.1K Aug 6 13:04 session.h* CLi@PC-CLI-1 ~/develop/libcgi/libcgi-1.0 $ ll /home/CLi/develop/crosstool-ng/x-tools/libcgi/lib total 88K -rw-r--r-- 1 CLi Domänen-Benutzer 43K Aug 6 13:03 libcgi.a -rwxr-xr-x 1 CLi Domänen-Benutzer 44K Aug 6 13:03 libcgi.so*

如此,才算成功:

有了对应的.a和.so的库,有了对应的.h文件。

->

很明显是makefile写错了。

12.去折腾了下,测试结果是,makefile,应该从原先的:

install:
  cp src/libcgi.a $(LIBDIR)
 cp src/libcgi.so $(LIBDIR)  cp src/cgi.h $(INCDIR)  cp src/session.h $(INCDIR)

改为:

install:
  mkdir -p $(LIBDIR)
  cp src/libcgi.a $(LIBDIR)
 cp src/libcgi.so $(LIBDIR)  mkdir -p $(INCDIR)  cp src/cgi.h $(INCDIR)  cp src/session.h $(INCDIR)

就可以了。

其中:

(1)对应的uninstall部分,没去管;

(2)由于makefile文件,也是configure生成的,所以,最终的修改,应该是修改configure文件。此处不熟悉,暂不去深究了。

效果是:

CLi@PC-CLI-1 ~/develop/libcgi/libcgi-1.0
$ rm /home/CLi/develop/crosstool-ng/x-tools/libcgi/* -fr CLi@PC-CLI-1 ~/develop/libcgi/libcgi-1.0 $ ll /home/CLi/develop/crosstool-ng/x-tools/libcgi total 0 CLi@PC-CLI-1 ~/develop/libcgi/libcgi-1.0 $ ll /home/CLi/develop/crosstool-ng/x-tools/libcgi^C CLi@PC-CLI-1 ~/develop/libcgi/libcgi-1.0 $ make install mkdir -p /home/CLi/develop/crosstool-ng/x-tools/libcgi/lib cp src/libcgi.a /home/CLi/develop/crosstool-ng/x-tools/libcgi/lib cp src/libcgi.so /home/CLi/develop/crosstool-ng/x-tools/libcgi/lib mkdir -p /home/CLi/develop/crosstool-ng/x-tools/libcgi/include cp src/cgi.h /home/CLi/develop/crosstool-ng/x-tools/libcgi/include cp src/session.h /home/CLi/develop/crosstool-ng/x-tools/libcgi/include CLi@PC-CLI-1 ~/develop/libcgi/libcgi-1.0 $ ll /home/CLi/develop/crosstool-ng/x-tools/libcgi total 0 drwxr-xr-x+ 1 CLi Domänen-Benutzer 0 Aug 6 13:10 include/ drwxr-xr-x+ 1 CLi Domänen-Benutzer 0 Aug 6 13:10 lib/ CLi@PC-CLI-1 ~/develop/libcgi/libcgi-1.0 $ ll /home/CLi/develop/crosstool-ng/x-tools/libcgi/lib/ total 88K -rw-r--r-- 1 CLi Domänen-Benutzer 43K Aug 6 13:10 libcgi.a -rwxr-xr-x 1 CLi Domänen-Benutzer 44K Aug 6 13:10 libcgi.so* CLi@PC-CLI-1 ~/develop/libcgi/libcgi-1.0 $ ll /home/CLi/develop/crosstool-ng/x-tools/libcgi/include/ total 12K -rwxr-xr-x 1 CLi Domänen-Benutzer 4.3K Aug 6 13:10 cgi.h* -rwxr-xr-x 1 CLi Domänen-Benutzer 1.1K Aug 6 13:10 session.h*

【总结】

此处的过程是:

1.配置:

./configure --prefix=$HOME/develop/crosstool-ng/x-tools/libcgi --build=i686-pc-cygwin --target=arm-xscale-linux-gnueabi --host=arm-xscale-linux-gnueabi

注:此处指定CC的话,无法识别,所以CC的指定,放在make后面了。

2.编译:

准备工作:

(1)修改:

libcgi-1.0\src\string.c

中的587行的:

va_copy(bkp, str);

改为:

//va_copy(bkp, str);
va_copy(bkp, ptr);

编译:

再去指定CC,去make编译:

make CC=arm-xscale-linux-gnueabi-gcc

3.安装:

准备工作:

将makefile中的:

install:
  cp src/libcgi.a $(LIBDIR)
 cp src/libcgi.so $(LIBDIR)  cp src/cgi.h $(INCDIR)  cp src/session.h $(INCDIR)

改为:

install:
  mkdir -p $(LIBDIR)
  cp src/libcgi.a $(LIBDIR)
 cp src/libcgi.so $(LIBDIR)  mkdir -p $(INCDIR)  cp src/cgi.h $(INCDIR)  cp src/session.h $(INCDIR)

就可以了。

安装:

make install

转载于:https://www.cnblogs.com/LxwEmbedded/p/4180020.html

你可能感兴趣的:(cygwin下用arm-xscale-linux-gnueabi交叉编译libcgi)