您的位置:首页 > 运维架构

交叉编译openssl-0.9.7a出现的问题总结

2010-05-21 20:26 736 查看
在看了openssl-0.9.7a中的README,和 INSTALL后,我按INSTALL所说的:

./Configure
Usage: Configure [no-<cipher> ...] [-Dxxx] [-lxxx] [-Lxxx] [-fxxx] [-Kxxx] [no-engine] [no-hw-xxx|no-hw] [[no-]threads] [[no-]shared] [[no-]zlib|zlib-dynamic] [no-asm] [no-dso] [no-krb5] [386] [--prefix=DIR] [--openssldir=OPENSSLDIR] [--with-xxx[=vvv]] [--test-sanity] os/compiler[:flags]

pick os/compiler from:
BC-16 BC-32 BS2000-OSD Cygwin Cygwin-pre1.3 DJGPP FreeBSD FreeBSD-alpha
FreeBSD-elf FreeBSD-ia64 FreeBSD-sparc64 MPE/iX-gcc Mingw32 NetBSD-m68
NetBSD-sparc NetBSD-x86 OS2-EMX OS390-Unix OpenBSD OpenBSD-alpha OpenBSD-hppa
OpenBSD-i386 OpenBSD-m68k OpenBSD-m88k OpenBSD-mips OpenBSD-powerpc
OpenBSD-sparc OpenBSD-sparc64 OpenBSD-vax OpenUNIX-8 OpenUNIX-8-gcc
ReliantUNIX SINIX SINIX-N UWIN VC-CE VC-MSDOS VC-NT VC-W31-16 VC-W31-32
VC-WIN16 VC-WIN32 aix-cc aix-gcc aix43-cc aix43-gcc aix64-cc alpha-cc
alpha-cc-rpath alpha-gcc alpha164-cc alphaold-cc aux3-gcc bsdi-elf-gcc
bsdi-gcc cc cray-j90 cray-t3e darwin-i386-cc darwin-ppc-cc dgux-R3-gcc
dgux-R4-gcc dgux-R4-x86-gcc dist gcc hpux-brokencc hpux-brokengcc hpux-cc
hpux-gcc hpux-ia64-cc hpux-m68k-gcc hpux-parisc-cc hpux-parisc-cc-o4
hpux-parisc-gcc hpux-parisc1_1-cc hpux-parisc2-cc hpux10-brokencc
hpux10-brokengcc hpux10-cc hpux10-gcc hpux64-ia64-cc hpux64-parisc-cc
hpux64-parisc-gcc hpux64-parisc2-cc hurd-x86 irix-cc irix-gcc irix-mips3-cc
irix-mips3-gcc irix64-mips4-cc irix64-mips4-gcc linux-alpha+bwx-ccc
linux-alpha+bwx-gcc linux-alpha-ccc linux-alpha-gcc linux-aout linux-elf
linux-elf-arm linux-ia64 linux-k6 linux-m68k linux-mips linux-mipsel
linux-parisc linux-pentium linux-ppc linux-ppro linux-s390 linux-s390x
linux-sparcv7 linux-sparcv8 linux-sparcv9 linux-x86_64 linux64-sparcv9
ncr-scde newsos4-gcc nextstep nextstep3.3 purify qnx4 qnx6 rhapsody-ppc-cc
sco3-gcc sco5-cc sco5-gcc solaris-sparc-sc3 solaris-sparcv7-cc
solaris-sparcv7-gcc solaris-sparcv8-cc solaris-sparcv8-gcc solaris-sparcv9-cc
solaris-sparcv9-gcc solaris-sparcv9-gcc27 solaris-x86-cc solaris-x86-gcc
solaris64-sparcv9-cc solaris64-sparcv9-gcc solaris64-sparcv9-gcc31 sunos-gcc
tandem-c89 ultrix-cc ultrix-gcc unixware-2.0 unixware-2.1 unixware-7
unixware-7-gcc vxworks-ppc405 vxworks-ppc750 vxworks-ppc750-debug debug
debug-ben debug-ben-debug debug-ben-openbsd debug-ben-openbsd-debug
debug-ben-strict debug-bodo debug-levitte-linux-elf
debug-levitte-linux-elf-extreme debug-levitte-linux-noasm
debug-levitte-linux-noasm-extreme debug-linux-elf debug-linux-elf-noefence
debug-linux-pentium debug-linux-ppro debug-rse debug-solaris-sparcv8-cc
debug-solaris-sparcv8-gcc debug-solaris-sparcv9-cc debug-solaris-sparcv9-gcc
debug-steve debug-steve-linux-pseudo64 debug-ulf

NOTE: If in doubt, on Unix-ish systems use './config'.

然后

./Configure linux-elf-arm

之后

./make

谁知,出现了这个错误:

make
making all in crypto...
make[1]: Entering directory `/root/hda1/tempFile/openssl-0.9.7a/crypto'
making all in crypto/md2...
make[2]: Entering directory `/root/hda1/tempFile/openssl-0.9.7a/crypto/md2'
make[2]: Nothing to be done for `all'.
make[2]: Leaving directory `/root/hda1/tempFile/openssl-0.9.7a/crypto/md2'
making all in crypto/md4...
make[2]: Entering directory `/root/hda1/tempFile/openssl-0.9.7a/crypto/md4'
make[2]: Nothing to be done for `all'.
make[2]: Leaving directory `/root/hda1/tempFile/openssl-0.9.7a/crypto/md4'
making all in crypto/md5...
make[2]: Entering directory `/root/hda1/tempFile/openssl-0.9.7a/crypto/md5'
make[2]: Nothing to be done for `all'.
make[2]: Leaving directory `/root/hda1/tempFile/openssl-0.9.7a/crypto/md5'
making all in crypto/sha...
make[2]: Entering directory `/root/hda1/tempFile/openssl-0.9.7a/crypto/sha'
make[2]: Nothing to be done for `all'.
make[2]: Leaving directory `/root/hda1/tempFile/openssl-0.9.7a/crypto/sha'
making all in crypto/mdc2...
make[2]: Entering directory `/root/hda1/tempFile/openssl-0.9.7a/crypto/mdc2'
make[2]: Nothing to be done for `all'.
make[2]: Leaving directory `/root/hda1/tempFile/openssl-0.9.7a/crypto/mdc2'
making all in crypto/hmac...
make[2]: Entering directory `/root/hda1/tempFile/openssl-0.9.7a/crypto/hmac'
make[2]: Nothing to be done for `all'.
make[2]: Leaving directory `/root/hda1/tempFile/openssl-0.9.7a/crypto/hmac'
making all in crypto/ripemd...
make[2]: Entering directory `/root/hda1/tempFile/openssl-0.9.7a/crypto/ripemd'
make[2]: Nothing to be done for `all'.
make[2]: Leaving directory `/root/hda1/tempFile/openssl-0.9.7a/crypto/ripemd'
making all in crypto/des...
make[2]: Entering directory `/root/hda1/tempFile/openssl-0.9.7a/crypto/des'
make[2]: Nothing to be done for `all'.
make[2]: Leaving directory `/root/hda1/tempFile/openssl-0.9.7a/crypto/des'
making all in crypto/rc2...
make[2]: Entering directory `/root/hda1/tempFile/openssl-0.9.7a/crypto/rc2'
make[2]: Nothing to be done for `all'.
make[2]: Leaving directory `/root/hda1/tempFile/openssl-0.9.7a/crypto/rc2'
making all in crypto/rc4...
make[2]: Entering directory `/root/hda1/tempFile/openssl-0.9.7a/crypto/rc4'
make[2]: Nothing to be done for `all'.
make[2]: Leaving directory `/root/hda1/tempFile/openssl-0.9.7a/crypto/rc4'
making all in crypto/rc5...
make[2]: Entering directory `/root/hda1/tempFile/openssl-0.9.7a/crypto/rc5'
make[2]: Nothing to be done for `all'.
make[2]: Leaving directory `/root/hda1/tempFile/openssl-0.9.7a/crypto/rc5'
making all in crypto/idea...
make[2]: Entering directory `/root/hda1/tempFile/openssl-0.9.7a/crypto/idea'
make[2]: Nothing to be done for `all'.
make[2]: Leaving directory `/root/hda1/tempFile/openssl-0.9.7a/crypto/idea'
making all in crypto/bf...
make[2]: Entering directory `/root/hda1/tempFile/openssl-0.9.7a/crypto/bf'
make[2]: Nothing to be done for `all'.
make[2]: Leaving directory `/root/hda1/tempFile/openssl-0.9.7a/crypto/bf'
making all in crypto/cast...
make[2]: Entering directory `/root/hda1/tempFile/openssl-0.9.7a/crypto/cast'
make[2]: Nothing to be done for `all'.
make[2]: Leaving directory `/root/hda1/tempFile/openssl-0.9.7a/crypto/cast'
making all in crypto/bn...
make[2]: Entering directory `/root/hda1/tempFile/openssl-0.9.7a/crypto/bn'
make[2]: Nothing to be done for `all'.
make[2]: Leaving directory `/root/hda1/tempFile/openssl-0.9.7a/crypto/bn'
making all in crypto/ec...
make[2]: Entering directory `/root/hda1/tempFile/openssl-0.9.7a/crypto/ec'
make[2]: Nothing to be done for `all'.
make[2]: Leaving directory `/root/hda1/tempFile/openssl-0.9.7a/crypto/ec'
making all in crypto/rsa...
make[2]: Entering directory `/root/hda1/tempFile/openssl-0.9.7a/crypto/rsa'
make[2]: Nothing to be done for `all'.
make[2]: Leaving directory `/root/hda1/tempFile/openssl-0.9.7a/crypto/rsa'
making all in crypto/dsa...
make[2]: Entering directory `/root/hda1/tempFile/openssl-0.9.7a/crypto/dsa'
make[2]: Nothing to be done for `all'.
make[2]: Leaving directory `/root/hda1/tempFile/openssl-0.9.7a/crypto/dsa'
making all in crypto/dh...
make[2]: Entering directory `/root/hda1/tempFile/openssl-0.9.7a/crypto/dh'
make[2]: Nothing to be done for `all'.
make[2]: Leaving directory `/root/hda1/tempFile/openssl-0.9.7a/crypto/dh'
making all in crypto/dso...
make[2]: Entering directory `/root/hda1/tempFile/openssl-0.9.7a/crypto/dso'
make[2]: Nothing to be done for `all'.
make[2]: Leaving directory `/root/hda1/tempFile/openssl-0.9.7a/crypto/dso'
making all in crypto/engine...
make[2]: Entering directory `/root/hda1/tempFile/openssl-0.9.7a/crypto/engine'
make[2]: Nothing to be done for `all'.
make[2]: Leaving directory `/root/hda1/tempFile/openssl-0.9.7a/crypto/engine'
making all in crypto/aes...
make[2]: Entering directory `/root/hda1/tempFile/openssl-0.9.7a/crypto/aes'
make[2]: Nothing to be done for `all'.
make[2]: Leaving directory `/root/hda1/tempFile/openssl-0.9.7a/crypto/aes'
making all in crypto/buffer...
make[2]: Entering directory `/root/hda1/tempFile/openssl-0.9.7a/crypto/buffer'
make[2]: Nothing to be done for `all'.
make[2]: Leaving directory `/root/hda1/tempFile/openssl-0.9.7a/crypto/buffer'
making all in crypto/bio...
make[2]: Entering directory `/root/hda1/tempFile/openssl-0.9.7a/crypto/bio'
make[2]: Nothing to be done for `all'.
make[2]: Leaving directory `/root/hda1/tempFile/openssl-0.9.7a/crypto/bio'
making all in crypto/stack...
make[2]: Entering directory `/root/hda1/tempFile/openssl-0.9.7a/crypto/stack'
make[2]: Nothing to be done for `all'.
make[2]: Leaving directory `/root/hda1/tempFile/openssl-0.9.7a/crypto/stack'
making all in crypto/lhash...
make[2]: Entering directory `/root/hda1/tempFile/openssl-0.9.7a/crypto/lhash'
make[2]: Nothing to be done for `all'.
make[2]: Leaving directory `/root/hda1/tempFile/openssl-0.9.7a/crypto/lhash'
making all in crypto/rand...
make[2]: Entering directory `/root/hda1/tempFile/openssl-0.9.7a/crypto/rand'
make[2]: Nothing to be done for `all'.
make[2]: Leaving directory `/root/hda1/tempFile/openssl-0.9.7a/crypto/rand'
making all in crypto/err...
make[2]: Entering directory `/root/hda1/tempFile/openssl-0.9.7a/crypto/err'
make[2]: Nothing to be done for `all'.
make[2]: Leaving directory `/root/hda1/tempFile/openssl-0.9.7a/crypto/err'
making all in crypto/objects...
make[2]: Entering directory `/root/hda1/tempFile/openssl-0.9.7a/crypto/objects'
make[2]: Nothing to be done for `all'.
make[2]: Leaving directory `/root/hda1/tempFile/openssl-0.9.7a/crypto/objects'
making all in crypto/evp...
make[2]: Entering directory `/root/hda1/tempFile/openssl-0.9.7a/crypto/evp'
make[2]: Nothing to be done for `all'.
make[2]: Leaving directory `/root/hda1/tempFile/openssl-0.9.7a/crypto/evp'
making all in crypto/asn1...
make[2]: Entering directory `/root/hda1/tempFile/openssl-0.9.7a/crypto/asn1'
make[2]: Nothing to be done for `all'.
make[2]: Leaving directory `/root/hda1/tempFile/openssl-0.9.7a/crypto/asn1'
making all in crypto/pem...
make[2]: Entering directory `/root/hda1/tempFile/openssl-0.9.7a/crypto/pem'
make[2]: Nothing to be done for `all'.
make[2]: Leaving directory `/root/hda1/tempFile/openssl-0.9.7a/crypto/pem'
making all in crypto/x509...
make[2]: Entering directory `/root/hda1/tempFile/openssl-0.9.7a/crypto/x509'
make[2]: Nothing to be done for `all'.
make[2]: Leaving directory `/root/hda1/tempFile/openssl-0.9.7a/crypto/x509'
making all in crypto/x509v3...
make[2]: Entering directory `/root/hda1/tempFile/openssl-0.9.7a/crypto/x509v3'
make[2]: Nothing to be done for `all'.
make[2]: Leaving directory `/root/hda1/tempFile/openssl-0.9.7a/crypto/x509v3'
making all in crypto/conf...
make[2]: Entering directory `/root/hda1/tempFile/openssl-0.9.7a/crypto/conf'
make[2]: Nothing to be done for `all'.
make[2]: Leaving directory `/root/hda1/tempFile/openssl-0.9.7a/crypto/conf'
making all in crypto/txt_db...
make[2]: Entering directory `/root/hda1/tempFile/openssl-0.9.7a/crypto/txt_db'
make[2]: Nothing to be done for `all'.
make[2]: Leaving directory `/root/hda1/tempFile/openssl-0.9.7a/crypto/txt_db'
making all in crypto/pkcs7...
make[2]: Entering directory `/root/hda1/tempFile/openssl-0.9.7a/crypto/pkcs7'
make[2]: Nothing to be done for `all'.
make[2]: Leaving directory `/root/hda1/tempFile/openssl-0.9.7a/crypto/pkcs7'
making all in crypto/pkcs12...
make[2]: Entering directory `/root/hda1/tempFile/openssl-0.9.7a/crypto/pkcs12'
make[2]: Nothing to be done for `all'.
make[2]: Leaving directory `/root/hda1/tempFile/openssl-0.9.7a/crypto/pkcs12'
making all in crypto/comp...
make[2]: Entering directory `/root/hda1/tempFile/openssl-0.9.7a/crypto/comp'
make[2]: Nothing to be done for `all'.
make[2]: Leaving directory `/root/hda1/tempFile/openssl-0.9.7a/crypto/comp'
making all in crypto/ocsp...
make[2]: Entering directory `/root/hda1/tempFile/openssl-0.9.7a/crypto/ocsp'
make[2]: Nothing to be done for `all'.
make[2]: Leaving directory `/root/hda1/tempFile/openssl-0.9.7a/crypto/ocsp'
making all in crypto/ui...
make[2]: Entering directory `/root/hda1/tempFile/openssl-0.9.7a/crypto/ui'
make[2]: Nothing to be done for `all'.
make[2]: Leaving directory `/root/hda1/tempFile/openssl-0.9.7a/crypto/ui'
making all in crypto/krb5...
make[2]: Entering directory `/root/hda1/tempFile/openssl-0.9.7a/crypto/krb5'
make[2]: Nothing to be done for `all'.
make[2]: Leaving directory `/root/hda1/tempFile/openssl-0.9.7a/crypto/krb5'
if [ -n "" ]; then /
(cd ..; make -f Makefile.ssl libcrypto.so.0.9.7); /
fi
make[1]: Leaving directory `/root/hda1/tempFile/openssl-0.9.7a/crypto'
making all in ssl...
make[1]: Entering directory `/root/hda1/tempFile/openssl-0.9.7a/ssl'
if [ -n "" ]; then /
(cd ..; make -f Makefile.ssl libssl.so.0.9.7); /
fi
make[1]: Leaving directory `/root/hda1/tempFile/openssl-0.9.7a/ssl'
making all in apps...
make[1]: Entering directory `/root/hda1/tempFile/openssl-0.9.7a/apps'
rm -f openssl
if [ "linux-shared" = "hpux-shared" -o "linux-shared" = "darwin-shared" ] ; then /
arm-uclibc-linux-gcc -o openssl -DMONOLITH -I.. -I../include -DOPENSSL_THREADS -D_REENTRANT -DDSO_DLFCN -DHAVE_DLFCN_H -DOPENSSL_NO_KRB5 -DL_ENDIAN -DTERMIO -O3 -fomit-frame-pointer -Wall openssl.o verify.o asn1pars.o req.o dgst.o dh.o dhparam.o enc.o passwd.o gendh.o errstr.o ca.o pkcs7.o crl2p7.o crl.o rsa.o rsautl.o dsa.o dsaparam.o x509.o genrsa.o gendsa.o s_server.o s_client.o speed.o s_time.o apps.o s_cb.o s_socket.o app_rand.o version.o sess_id.o ciphers.o nseq.o pkcs12.o pkcs8.o spkac.o smime.o rand.o engine.o ocsp.o ../libssl.a ../libcrypto.a ; /
else /
arm-uclibc-linux-gcc -o openssl -DMONOLITH -I.. -I../include -DOPENSSL_THREADS -D_REENTRANT -DDSO_DLFCN -DHAVE_DLFCN_H -DOPENSSL_NO_KRB5 -DL_ENDIAN -DTERMIO -O3 -fomit-frame-pointer -Wall openssl.o verify.o asn1pars.o req.o dgst.o dh.o dhparam.o enc.o passwd.o gendh.o errstr.o ca.o pkcs7.o crl2p7.o crl.o rsa.o rsautl.o dsa.o dsaparam.o x509.o genrsa.o gendsa.o s_server.o s_client.o speed.o s_time.o apps.o s_cb.o s_socket.o app_rand.o version.o sess_id.o ciphers.o nseq.o pkcs12.o pkcs8.o spkac.o smime.o rand.o engine.o ocsp.o -L.. -lssl -L.. -lcrypto ; /
fi
../libcrypto.a(dso_dlfcn.o): In function `dlfcn_load':
c
dso_dlfcn.c:(.text+0x8c): undefined reference to `dlclose'
dso_dlfcn.c:(.text+0xd8): undefined reference to `dlerror'
../libcrypto.a(dso_dlfcn.o): In function `dlfcn_unload':
dso_dlfcn.c:(.text+0x154): undefined reference to `dlclose'
../libcrypto.a(dso_dlfcn.o): In function `dlfcn_bind_var':
dso_dlfcn.c:(.text+0x21c): undefined reference to `dlsym'
dso_dlfcn.c:(.text+0x264): undefined reference to `dlerror'
../libcrypto.a(dso_dlfcn.o): In function `dlfcn_bind_func':
dso_dlfcn.c:(.text+0x338): undefined reference to `dlsym'
dso_dlfcn.c:(.text+0x380): undefined reference to `dlerror'
collect2: ld returned 1 exit status
make[1]: *** [openssl] 错误 1
make[1]: Leaving directory `/root/hda1/tempFile/openssl-0.9.7a/apps'
make: *** [sub_all] 错误 1

看看上面的错误的地方,仔细分析一下,并打开`/root/hda1/tempFile/openssl-0.9.7a/apps'下的Makefile文件,对照上面的错误,可以知道是执行到 Makefile 中的

if [ "$(SHLIB_TARGET)" = "hpux-shared" -o "$(SHLIB_TARGET)" = "darwin-shared" ] ; then /
$(CC) -o $(PROGRAM) $(CFLAGS) $(PROGRAM).o $(E_OBJ) $(PEX_LIBS) $(DLIBSSL) $(LIBKRB5) $(DLIBCRYPTO) $(EX_LIBS) ; /
else /
$(CC) -o $(PROGRAM) $(CFLAGS) $(PROGRAM).o $(E_OBJ) $(PEX_LIBS) $(LIBSSL) $(LIBKRB5) $(LIBCRYPTO) $(EX_LIBS) ; /

的else分支出的错,查看上面的出错情况,是因为

dso_dlfcn.c:(.text+0x2c): undefined reference to `dlopen' ,那就有可能是没有#include 到相关的头文件或是没有链接到该库造成的,说白了就是缺少链接 libdl.a库造成的,加多一个 -ldl 就OK了,因为上面的

else /
arm-uclibc-linux-gcc -o openssl -DMONOLITH -I.. -I../include -DOPENSSL_THREADS -D_REENTRANT -DDSO_DLFCN -DHAVE_DLFCN_H -DOPENSSL_NO_KRB5 -DL_ENDIAN -DTERMIO -O3 -fomit-frame-pointer -Wall openssl.o verify.o asn1pars.o req.o dgst.o dh.o dhparam.o enc.o passwd.o gendh.o errstr.o ca.o pkcs7.o crl2p7.o crl.o rsa.o rsautl.o dsa.o dsaparam.o x509.o genrsa.o gendsa.o s_server.o s_client.o speed.o s_time.o apps.o s_cb.o s_socket.o app_rand.o version.o sess_id.o ciphers.o nseq.o pkcs12.o pkcs8.o spkac.o smime.o rand.o engine.o ocsp.o -L.. -lssl -L.. -lcrypto ; /

对应于 `/root/hda1/tempFile/openssl-0.9.7a/apps/Makefile 的

else /
$(CC) -o $(PROGRAM) $(CFLAGS) $(PROGRAM).o $(E_OBJ) $(PEX_LIBS) $(LIBSSL) $(LIBKRB5) $(LIBCRYPTO) $(EX_LIBS) ; /

我只要把 `/root/hda1/tempFile/openssl-0.9.7a/Makefile 中对 EX_LIBS 的变量赋值 -ldl就可以了。

修改前如下:

CC= arm-uclibc-linux-gcc
#CFLAG= -DL_ENDIAN -DTERMIO -O3 -fomit-frame-pointer -m486 -Wall -Wuninitialized -DSHA1_ASM -DMD5_ASM -DRMD160_ASM
CFLAG= -DOPENSSL_THREADS -D_REENTRANT -DDSO_DLFCN -DHAVE_DLFCN_H -DOPENSSL_NO_KRB5 -DL_ENDIAN -DTERMIO -O3 -fomit-frame-pointer -Wall
DEPFLAG=
PEX_LIBS=
EX_LIBS=
EXE_EXT=
ARFLAGS=
AR=arm-uclibc-linux-ar $(ARFLAGS) r
RANLIB= /usr/bin/ranlib
PERL= /usr/bin/perl
TAR= tar
TARFLAGS= --no-recursion
MAKEDEPPROG= gcc

修改后如下:

CC= arm-uclibc-linux-gcc
#CFLAG= -DL_ENDIAN -DTERMIO -O3 -fomit-frame-pointer -m486 -Wall -Wuninitialized -DSHA1_ASM -DMD5_ASM -DRMD160_ASM
CFLAG= -DOPENSSL_THREADS -D_REENTRANT -DDSO_DLFCN -DHAVE_DLFCN_H -DOPENSSL_NO_KRB5 -DL_ENDIAN -DTERMIO -O3 -fomit-frame-pointer -Wall
DEPFLAG=
PEX_LIBS=
EX_LIBS= -ldl
EXE_EXT=
ARFLAGS=
AR=arm-uclibc-linux-ar $(ARFLAGS) r
RANLIB= /usr/bin/ranlib
PERL= /usr/bin/perl
TAR= tar
TARFLAGS= --no-recursion
MAKEDEPPROG= gcc

其实,linux在什么情况下只要包含头文件就可以了(在编译时不用加编译的选项,这方面的例子如#include "string.h"),什么情况下不仅要包含头文件,还要在编译时加一些编译的选项(这方面的例子如#include "pthread.h"),我也不是很清楚,fedora man 手册页上也没有这方面的说明,而且-l 的后缀名大家也不是很清楚,或者说十分确定,于是上网搜到了下的一些东西,第3点对刚才那个问题有帮助,呵呵,小记一下。以免忘了.

1. 头文件
象conio.h应该变成curses.h

2. 没有itoa函数
itoa?不对吧,标准C/C++里根本没有这个函数。即使在Windows平台下某些编译器提供了该函数[3],没有任何移植性不说,还只能解决int类型(也许其他函数还可以解决long、unsigned long等类型),浮点类型又怎么办?当然,办法还是有,那就是:sprintf。

char s[100];
sprintf(s, "%f", 123.123456);

3. 关于sqrt,sin和cos函数
就算是引入math.h头文件,也不会找到sqrt,sin和cos函数。应该用链接库来解决。
有时候我们使用了某个函数,但是我们不知道库的名字,这个时候怎么办呢?很抱歉,对于这个问题我也不知道答案,我只有一个傻办法.首先, 我到标准库路径下面去找看看有没有和我用的函数相关的库,我就这样找到了线程(thread)函数的库文件(libpthread.a). 当然,如果找不到,只有一个笨方法.比如我要找sin这个函数所在的库. 就只好用 nm -o /lib/*.so|grep sin>~/sin 命令,然后看~/sin文件,到那里面去找了. 在sin文件当中,我会找到这样的一行libm-2.1.2.so:00009fa0 W sin 这样我就知道了sin在 libm-2.1.2.so库里面,我用 -lm选项就可以了(去掉前面的lib和后面的版本标志,就剩下m了所以是 -lm).

4. Makefile出现missing separator的错误
原因是目标声明行下面的命令行必须用Tab键分开(而不是空格)

PG: PG.o
[ Tab键 ]gcc -o PG -O -O2 -lm /lib/ld-2.2.93.so PG.o
PG.o: PG.c pointgroup.h
[ Tab键 ]gcc -c -O -O2 PG.c
clean:
[ Tab键 ]rm -f *.o

5. 注意文件的DOS格式字符
调试的时候应该注意文件可能有DOS格式字符,必须先用如下命令去掉文件中的DOS格式字符:
tr -d <file> tmp_file
mv tmp_file <file>

-o FILE
指定输出文件名,在编译为目标代码时,这一选项不是必须的。如果FILE没有指定,缺省文件名是a.out.

-c
只编译不链接

-DFOO=BAR
在命令行定义预处理宏FOO,其值为BAR

-IDIRNAME
将DIRNAME加入到头文件的搜索目录列表中

-LDIRNAME
将DIRNAME加入到库文件的搜索目录列表中,缺省情况下gcc 只链接共享库

-static
链接静态库,即执行静态链接

-lFOO
链接名为libFOO的函数库

-g
在可执行程序中包含标准调试信息

-ggdb
在可执行程序中包含只有GNU debugger才能使别的达两条是信息

-O
优化编译过的代码

-ON
指定代码优化的级别为N,o<=N<=3

-ansi
支持ANSI/ISO C的标准语法,取消GNU的语法扩展中与该标准有冲突的部分
(但这一选项并不能保证生成ANSI兼容的代码)

-pedantic
允许发出ANSI/ISO C标准所列出的所有警告

-pedantic -errors
允许发出ANSI/ISO C标准所列出的所有错误

-traditional
支持Kernighan & Ritchie C语法(如用旧式语法定义函数);如果不知道这个选项的含义,也没有关系

-w
关闭所有警告,建议不要使用此项

.Wall
允许发出gcc能提供的所有有用的警告,也可以用-W(warning)来标记指定的警告

-werror
把所有警告转换为错误,以在警告发生时中止编译过程

-MM
输出一个make兼容的相关列表

-v
显示在编译过程的每一步中用到的命令
内容来自用户分享和网络整理,不保证内容的准确性,如有侵权内容,可联系管理员处理 点击这里给我发消息
标签: