首页 > 代码库 > cygwin下用arm-xscale-linux-gnueabi交叉编译libcgi

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$ lsAUTHORS*  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 --helpUsage: 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 configureDirectory 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 namesHost 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 DIRCLi@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-gccconfigure: warning: CC=arm-xscale-linux-gnueabi-gcc: invalid host typecreating cache ./config.cachechecking for gcc... gccchecking whether the C compiler (gcc  ) works... yeschecking whether the C compiler (gcc  ) is a cross-compiler... nochecking whether we are using GNU C... yeschecking whether gcc accepts -g... yeschecking for a BSD compatible install... /usr/bin/install -cchecking how to run the C preprocessor... gcc -Echecking for ANSI C header files... yesupdating cache ./config.cachecreating ./config.statuscreating Makefilecreating src/config.hsrc/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-gnueabiloading cache ./config.cachechecking for gcc... (cached) gccchecking whether the C compiler (gcc  ) works... yeschecking whether the C compiler (gcc  ) is a cross-compiler... nochecking whether we are using GNU C... (cached) yeschecking whether gcc accepts -g... (cached) yeschecking for a BSD compatible install... (cached) /usr/bin/install -cchecking how to run the C preprocessor... (cached) gcc -Echecking for ANSI C header files... (cached) yescreating ./config.statuscreating Makefilecreating src/config.hsrc/config.h is unchanged

4.然后再去make编译:

CLi@PC-CLI-1 ~/develop/libcgi/libcgi-1.0$ makecc    -c -o src/error.o src/error.ccc    -c -o src/cgi.o src/cgi.ccc    -c -o src/session.o src/session.ccc    -c -o src/base64.o src/base64.ccc    -c -o src/md5.o src/md5.ccc    -c -o src/string.o src/string.ccc    -c -o src/general.o src/general.ccc    -c -o src/list.o src/list.ccc    -c -o src/cookie.o src/cookie.car 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.occ -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.obase64.o     cgi.h        config.h     cookie.c     error.c      error.o      general.o    libcgi.so    list.o       md5.o        session.h    string.cCLi@PC-CLI-1 ~/develop/libcgi/libcgi-1.0$ file src/cgi.osrc/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-gnueabiloading cache ./config.cachechecking for gcc... (cached) gccchecking whether the C compiler (gcc  ) works... yeschecking whether the C compiler (gcc  ) is a cross-compiler... nochecking whether we are using GNU C... (cached) yeschecking whether gcc accepts -g... (cached) yeschecking for a BSD compatible install... (cached) /usr/bin/install -cchecking how to run the C preprocessor... (cached) gcc -Echecking for ANSI C header files... (cached) yescreating ./config.statuscreating Makefilecreating src/config.hsrc/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 cleanfind 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-gnueabiloading cache ./config.cachechecking for gcc... (cached) gccchecking whether the C compiler (gcc  ) works... yeschecking whether the C compiler (gcc  ) is a cross-compiler... nochecking whether we are using GNU C... (cached) yeschecking whether gcc accepts -g... (cached) yeschecking for a BSD compatible install... (cached) /usr/bin/install -cchecking how to run the C preprocessor... (cached) gcc -Echecking for ANSI C header files... (cached) yescreating ./config.statuscreating Makefilecreating src/config.hsrc/config.h is unchanged

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

CLi@PC-CLI-1 ~/develop/libcgi/libcgi-1.0$ make CC=arm-xscale-linux-gnueabi-gccarm-xscale-linux-gnueabi-gcc    -c -o src/error.o src/error.carm-xscale-linux-gnueabi-gcc    -c -o src/cgi.o src/cgi.carm-xscale-linux-gnueabi-gcc    -c -o src/session.o src/session.carm-xscale-linux-gnueabi-gcc    -c -o src/base64.o src/base64.carm-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 installcp src/libcgi.a /home/CLi/develop/crosstool-ng/x-tools/libcgi/libcp src/libcgi.so /home/CLi/develop/crosstool-ng/x-tools/libcgi/libcp src/cgi.h /home/CLi/develop/crosstool-ng/x-tools/libcgi/includecp 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/libcgitotal 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/libcgitotal 0CLi@PC-CLI-1 ~/develop/libcgi/libcgi-1.0$ mkdir /home/CLi/develop/crosstool-ng/x-tools/libcgi/libCLi@PC-CLI-1 ~/develop/libcgi/libcgi-1.0$ mkdir /home/CLi/develop/crosstool-ng/x-tools/libcgi/includeCLi@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/libcgitotal 0drwxr-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/libtotal 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/* -frCLi@PC-CLI-1 ~/develop/libcgi/libcgi-1.0$ ll /home/CLi/develop/crosstool-ng/x-tools/libcgitotal 0CLi@PC-CLI-1 ~/develop/libcgi/libcgi-1.0$ ll /home/CLi/develop/crosstool-ng/x-tools/libcgi^CCLi@PC-CLI-1 ~/develop/libcgi/libcgi-1.0$ make installmkdir -p /home/CLi/develop/crosstool-ng/x-tools/libcgi/libcp src/libcgi.a /home/CLi/develop/crosstool-ng/x-tools/libcgi/libcp src/libcgi.so /home/CLi/develop/crosstool-ng/x-tools/libcgi/libmkdir -p /home/CLi/develop/crosstool-ng/x-tools/libcgi/includecp src/cgi.h /home/CLi/develop/crosstool-ng/x-tools/libcgi/includecp src/session.h /home/CLi/develop/crosstool-ng/x-tools/libcgi/includeCLi@PC-CLI-1 ~/develop/libcgi/libcgi-1.0$ ll /home/CLi/develop/crosstool-ng/x-tools/libcgitotal 0drwxr-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

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