当前位置: 技术问答>linux和unix
collect2: ld returned 1 exit status链接错误
来源: 互联网 发布时间:2016-10-30
本文导语: 编译网上下载的开源软件opencapwap,使用make命令成功编译 但是默认的编译器是gcc,而我需要交叉编译,需要编译出能在MIPS下运行的程序。 编译结果如下(输出信息不多,全拷贝出来): [root@SS-SERVER1 capwap-0.93.3]# make...
编译网上下载的开源软件opencapwap,使用make命令成功编译
但是默认的编译器是gcc,而我需要交叉编译,需要编译出能在MIPS下运行的程序。
编译结果如下(输出信息不多,全拷贝出来):
[root@SS-SERVER1 capwap-0.93.3]# make all
/home/yang/openwrt_sdk/OpenWrt-SDK-Linux-i686-1/staging_dir_mipsel/bin/mipsel-linux-gcc -Wall -g -O0 -D_REENTRANT -DBCM -I /home/yang/openwrt_sdk/OpenWrt-SDK-Linux-i686-1/staging_dir_mipsel/usr/include -DCW_DEBUGGING -c -o CWThread.o CWThread.c
CWThread.c: In function `CWThreadTimedSemWait':
CWThread.c:466: warning: implicit declaration of function `sem_timedwait'/home/yang/openwrt_sdk/OpenWrt-SDK-Linux-i686-1/staging_dir_mipsel/bin/mipsel-linux-gcc -Wall -g -O0 -D_REENTRANT -DBCM -I /home/yang/openwrt_sdk/OpenWrt-SDK-Linux-i686-1/staging_dir_mipsel/usr/include -DCW_DEBUGGING -c -o CWBinding.o CWBinding.c
/home/yang/openwrt_sdk/OpenWrt-SDK-Linux-i686-1/staging_dir_mipsel/bin/mipsel-linux-gcc -Wall -g -O0 -D_REENTRANT -DBCM -I /home/yang/openwrt_sdk/OpenWrt-SDK-Linux-i686-1/staging_dir_mipsel/usr/include -DCW_DEBUGGING -c -o WTPBinding.o WTPBinding.c
/home/yang/openwrt_sdk/OpenWrt-SDK-Linux-i686-1/staging_dir_mipsel/bin/mipsel-linux-gcc -Wall -g -O0 -D_REENTRANT -DBCM -I /home/yang/openwrt_sdk/OpenWrt-SDK-Linux-i686-1/staging_dir_mipsel/usr/include -DCW_DEBUGGING -c -o WTPBcmDriverInteraction.o WTPBcmDriverInteraction.c
/home/yang/openwrt_sdk/OpenWrt-SDK-Linux-i686-1/staging_dir_mipsel/bin/mipsel-linux-gcc -Wall -g -O0 -D_REENTRANT -DBCM -I /home/yang/openwrt_sdk/OpenWrt-SDK-Linux-i686-1/staging_dir_mipsel/usr/include -DCW_DEBUGGING -c -o WTPSettingsFile.o WTPSettingsFile.c
/home/yang/openwrt_sdk/OpenWrt-SDK-Linux-i686-1/staging_dir_mipsel/bin/mipsel-linux-gcc -Wall -g -O0 -D_REENTRANT -DBCM -I /home/yang/openwrt_sdk/OpenWrt-SDK-Linux-i686-1/staging_dir_mipsel/usr/include -DCW_DEBUGGING -c -o timerlib.o timerlib.c
/home/yang/openwrt_sdk/OpenWrt-SDK-Linux-i686-1/staging_dir_mipsel/bin/mipsel-linux-gcc -DWRITE_STD_OUTPUT WTP.o WTPBcmFrameReceive.o WTPConfigFile.o WTPProtocol.o WTPProtocol_User.o WTPDiscoveryState.o WTPJoinState.o WTPConfigureState.o WTPDataCheckState.o WTPRunState.o WTPRunStateCheck.o WTPRetransmission.o WTPSulkingState.o CWCommon.o CWConfigFile.o CWErrorHandling.o CWSafeList.o CWList.o CWLog.o CWNetwork.o CWProtocol.o CWRandom.o CWSecurity.o CWOpenSSLBio.o CWStevens.o CWThread.o CWBinding.o WTPBinding.o WTPBcmDriverInteraction.o WTPSettingsFile.o timerlib.o /home/yang/openwrt_sdk/OpenWrt-SDK-Linux-i686-1/staging_dir_mipsel/usr/lib/libssl.a /home/yang/openwrt_sdk/OpenWrt-SDK-Linux-i686-1/staging_dir_mipsel/usr/lib/libcrypto.a /home/yang/openwrt_sdk/OpenWrt-SDK-Linux-i686-1/staging_dir_mipsel/lib/libpthread.a /home/yang/openwrt_sdk/OpenWrt-SDK-Linux-i686-1/staging_dir_mipsel/lib/libdl.a /home/yang/openwrt_sdk/OpenWrt-SDK-Linux-i686-1/staging_dir_mipsel/usr/lib/libpcap.a -D_REENTRANT -o WTP
WTP.o: In function `main':
/home/yang/trunk/capwap-0.93.3/WTP.c:410: undefined reference to `CWWTPReceiveStats'
/home/yang/trunk/capwap-0.93.3/WTP.c:422: undefined reference to `CWWTPReceiveFreqStats'
WTPRunState.o: In function `CWParseVendorMessage':
/home/yang/trunk/capwap-0.93.3/WTPRunState.c:1055: undefined reference to `CWParseVendorPayload'
WTPRunState.o: In function `CWSaveVendorMessage':
/home/yang/trunk/capwap-0.93.3/WTPRunState.c:1275: undefined reference to `CWWTPSaveUCIValues'
/home/yang/trunk/capwap-0.93.3/WTPRunState.c:1285: undefined reference to `CWWTPSaveWUMValues'
collect2: ld returned 1 exit status
make: *** [WTP] Error 1[root@SS-SERVER1 capwap-0.93.3]#
Makefile内容如下:
KAMIKAZEDIR=/home/yang/openwrt_sdk/OpenWrt-SDK-Linux-i686-1
CC = $(KAMIKAZEDIR)/staging_dir_mipsel/bin/mipsel-linux-gcc
LDFLAGS = $(KAMIKAZEDIR)/staging_dir_mipsel/usr/lib/libssl.a $(KAMIKAZEDIR)/staging_dir_mipsel/usr/lib/libcrypto.a $(KAMIKAZEDIR)/staging_dir_mipsel/lib/libpthread.a $(KAMIKAZEDIR)/staging_dir_mipsel/lib/libdl.a $(KAMIKAZEDIR)/staging_dir_mipsel/usr/lib/libpcap.a -D_REENTRANT
CFLAGS = -Wall -g -O0 -D_REENTRANT -DBCM -I $(KAMIKAZEDIR)/staging_dir_mipsel/usr/include #-DCW_NO_DTLS
# Memory leak
#LDFLAGS += ../dmalloc-5.5.0/libdmallocth.a
#CFLAGS += -DDMALLOC
# Capwap Debugging
CFLAGS += -DCW_DEBUGGING
RM = /bin/rm -f
# list of generated object files for WTP.
WTP_OBJS = WTP.o WTPBcmFrameReceive.o WTPConfigFile.o WTPProtocol.o WTPProtocol_User.o WTPDiscoveryState.o WTPJoinState.o WTPConfigureState.o WTPDataCheckState.o WTPRunState.o WTPRunStateCheck.o WTPRetransmission.o WTPSulkingState.o CWCommon.o CWConfigFile.o CWErrorHandling.o CWSafeList.o CWList.o CWLog.o CWNetwork.o CWProtocol.o CWRandom.o CWSecurity.o CWOpenSSLBio.o CWStevens.o CWThread.o CWBinding.o WTPBinding.o WTPBcmDriverInteraction.o WTPSettingsFile.o timerlib.o
WTP_SRCS = $(WTP_OBJS:.o=.c)
WTP_DEPS := $(WTP_OBJS:.o=.d)
# program executables.
WTP_NAME = WTP
.PHONY: deps clean clean_libs libs
# top-level rule, to compile everything.
all: $(WTP_NAME)
$(WTP_NAME): $(WTP_OBJS)
$(CC) -DWRITE_STD_OUTPUT $(WTP_OBJS) $(CC_FLAGS) $(LDFLAGS) -o $(WTP_NAME)
clean:
$(RM) $(WTP_NAME) $(WTP_OBJS) $(WTP_DEPS)
clean_deps:
$(WTP_DEPS)
deps: $(WTP_SRC)
$(CC) -MD -E -DWRITE_STD_OUTPUT $(WTP_SRCS) $(CFLAGS) >/dev/null
-include $(WTP_DEPS)
但是默认的编译器是gcc,而我需要交叉编译,需要编译出能在MIPS下运行的程序。
编译结果如下(输出信息不多,全拷贝出来):
[root@SS-SERVER1 capwap-0.93.3]# make all
/home/yang/openwrt_sdk/OpenWrt-SDK-Linux-i686-1/staging_dir_mipsel/bin/mipsel-linux-gcc -Wall -g -O0 -D_REENTRANT -DBCM -I /home/yang/openwrt_sdk/OpenWrt-SDK-Linux-i686-1/staging_dir_mipsel/usr/include -DCW_DEBUGGING -c -o CWThread.o CWThread.c
CWThread.c: In function `CWThreadTimedSemWait':
CWThread.c:466: warning: implicit declaration of function `sem_timedwait'/home/yang/openwrt_sdk/OpenWrt-SDK-Linux-i686-1/staging_dir_mipsel/bin/mipsel-linux-gcc -Wall -g -O0 -D_REENTRANT -DBCM -I /home/yang/openwrt_sdk/OpenWrt-SDK-Linux-i686-1/staging_dir_mipsel/usr/include -DCW_DEBUGGING -c -o CWBinding.o CWBinding.c
/home/yang/openwrt_sdk/OpenWrt-SDK-Linux-i686-1/staging_dir_mipsel/bin/mipsel-linux-gcc -Wall -g -O0 -D_REENTRANT -DBCM -I /home/yang/openwrt_sdk/OpenWrt-SDK-Linux-i686-1/staging_dir_mipsel/usr/include -DCW_DEBUGGING -c -o WTPBinding.o WTPBinding.c
/home/yang/openwrt_sdk/OpenWrt-SDK-Linux-i686-1/staging_dir_mipsel/bin/mipsel-linux-gcc -Wall -g -O0 -D_REENTRANT -DBCM -I /home/yang/openwrt_sdk/OpenWrt-SDK-Linux-i686-1/staging_dir_mipsel/usr/include -DCW_DEBUGGING -c -o WTPBcmDriverInteraction.o WTPBcmDriverInteraction.c
/home/yang/openwrt_sdk/OpenWrt-SDK-Linux-i686-1/staging_dir_mipsel/bin/mipsel-linux-gcc -Wall -g -O0 -D_REENTRANT -DBCM -I /home/yang/openwrt_sdk/OpenWrt-SDK-Linux-i686-1/staging_dir_mipsel/usr/include -DCW_DEBUGGING -c -o WTPSettingsFile.o WTPSettingsFile.c
/home/yang/openwrt_sdk/OpenWrt-SDK-Linux-i686-1/staging_dir_mipsel/bin/mipsel-linux-gcc -Wall -g -O0 -D_REENTRANT -DBCM -I /home/yang/openwrt_sdk/OpenWrt-SDK-Linux-i686-1/staging_dir_mipsel/usr/include -DCW_DEBUGGING -c -o timerlib.o timerlib.c
/home/yang/openwrt_sdk/OpenWrt-SDK-Linux-i686-1/staging_dir_mipsel/bin/mipsel-linux-gcc -DWRITE_STD_OUTPUT WTP.o WTPBcmFrameReceive.o WTPConfigFile.o WTPProtocol.o WTPProtocol_User.o WTPDiscoveryState.o WTPJoinState.o WTPConfigureState.o WTPDataCheckState.o WTPRunState.o WTPRunStateCheck.o WTPRetransmission.o WTPSulkingState.o CWCommon.o CWConfigFile.o CWErrorHandling.o CWSafeList.o CWList.o CWLog.o CWNetwork.o CWProtocol.o CWRandom.o CWSecurity.o CWOpenSSLBio.o CWStevens.o CWThread.o CWBinding.o WTPBinding.o WTPBcmDriverInteraction.o WTPSettingsFile.o timerlib.o /home/yang/openwrt_sdk/OpenWrt-SDK-Linux-i686-1/staging_dir_mipsel/usr/lib/libssl.a /home/yang/openwrt_sdk/OpenWrt-SDK-Linux-i686-1/staging_dir_mipsel/usr/lib/libcrypto.a /home/yang/openwrt_sdk/OpenWrt-SDK-Linux-i686-1/staging_dir_mipsel/lib/libpthread.a /home/yang/openwrt_sdk/OpenWrt-SDK-Linux-i686-1/staging_dir_mipsel/lib/libdl.a /home/yang/openwrt_sdk/OpenWrt-SDK-Linux-i686-1/staging_dir_mipsel/usr/lib/libpcap.a -D_REENTRANT -o WTP
WTP.o: In function `main':
/home/yang/trunk/capwap-0.93.3/WTP.c:410: undefined reference to `CWWTPReceiveStats'
/home/yang/trunk/capwap-0.93.3/WTP.c:422: undefined reference to `CWWTPReceiveFreqStats'
WTPRunState.o: In function `CWParseVendorMessage':
/home/yang/trunk/capwap-0.93.3/WTPRunState.c:1055: undefined reference to `CWParseVendorPayload'
WTPRunState.o: In function `CWSaveVendorMessage':
/home/yang/trunk/capwap-0.93.3/WTPRunState.c:1275: undefined reference to `CWWTPSaveUCIValues'
/home/yang/trunk/capwap-0.93.3/WTPRunState.c:1285: undefined reference to `CWWTPSaveWUMValues'
collect2: ld returned 1 exit status
make: *** [WTP] Error 1[root@SS-SERVER1 capwap-0.93.3]#
Makefile内容如下:
KAMIKAZEDIR=/home/yang/openwrt_sdk/OpenWrt-SDK-Linux-i686-1
CC = $(KAMIKAZEDIR)/staging_dir_mipsel/bin/mipsel-linux-gcc
LDFLAGS = $(KAMIKAZEDIR)/staging_dir_mipsel/usr/lib/libssl.a $(KAMIKAZEDIR)/staging_dir_mipsel/usr/lib/libcrypto.a $(KAMIKAZEDIR)/staging_dir_mipsel/lib/libpthread.a $(KAMIKAZEDIR)/staging_dir_mipsel/lib/libdl.a $(KAMIKAZEDIR)/staging_dir_mipsel/usr/lib/libpcap.a -D_REENTRANT
CFLAGS = -Wall -g -O0 -D_REENTRANT -DBCM -I $(KAMIKAZEDIR)/staging_dir_mipsel/usr/include #-DCW_NO_DTLS
# Memory leak
#LDFLAGS += ../dmalloc-5.5.0/libdmallocth.a
#CFLAGS += -DDMALLOC
# Capwap Debugging
CFLAGS += -DCW_DEBUGGING
RM = /bin/rm -f
# list of generated object files for WTP.
WTP_OBJS = WTP.o WTPBcmFrameReceive.o WTPConfigFile.o WTPProtocol.o WTPProtocol_User.o WTPDiscoveryState.o WTPJoinState.o WTPConfigureState.o WTPDataCheckState.o WTPRunState.o WTPRunStateCheck.o WTPRetransmission.o WTPSulkingState.o CWCommon.o CWConfigFile.o CWErrorHandling.o CWSafeList.o CWList.o CWLog.o CWNetwork.o CWProtocol.o CWRandom.o CWSecurity.o CWOpenSSLBio.o CWStevens.o CWThread.o CWBinding.o WTPBinding.o WTPBcmDriverInteraction.o WTPSettingsFile.o timerlib.o
WTP_SRCS = $(WTP_OBJS:.o=.c)
WTP_DEPS := $(WTP_OBJS:.o=.d)
# program executables.
WTP_NAME = WTP
.PHONY: deps clean clean_libs libs
# top-level rule, to compile everything.
all: $(WTP_NAME)
$(WTP_NAME): $(WTP_OBJS)
$(CC) -DWRITE_STD_OUTPUT $(WTP_OBJS) $(CC_FLAGS) $(LDFLAGS) -o $(WTP_NAME)
clean:
$(RM) $(WTP_NAME) $(WTP_OBJS) $(WTP_DEPS)
clean_deps:
$(WTP_DEPS)
deps: $(WTP_SRC)
$(CC) -MD -E -DWRITE_STD_OUTPUT $(WTP_SRCS) $(CFLAGS) >/dev/null
-include $(WTP_DEPS)
|
因为没有包含声明该函数的那个头文件,至于是哪一个文件,在命令行下man xxx就知道了,包含之。
另外,undefined reference之类的问题是没有包含相关的库。这个库你去找找README文件或INSTALL文件之类的文档,看一下有没有说明。反正要找到些什么蛛丝马迹的。
PS:看了下Makefile,有几个库,但不知道是不是相关的,不敢肯定。
|
太复杂了,在下不懂了。
本机编译通过,而交叉编译不通过,会不会是交叉编译器的问题?指向的库?库本身?都有可能。
比如./static/uclibc/libssl.a: could not read symbols: File in wrong format
它提示库的符号不能识别,一个可能的原因是这个库不是交叉编译过的版本。
本机编译通过,而交叉编译不通过,会不会是交叉编译器的问题?指向的库?库本身?都有可能。
比如./static/uclibc/libssl.a: could not read symbols: File in wrong format
它提示库的符号不能识别,一个可能的原因是这个库不是交叉编译过的版本。