linux - 错误: undefined reference

标签 linux gcc linker makefile installation

我正在使用 linux-mint 11 并尝试在我的计算机上安装来自紫色项目的“sendip”工具。

我对 makefile 和 linux 内部了解不多。

但是当尝试安装它时,出现这些错误。请帮助我解决这个问题。

这次对我来说最重要的是尽快在我的机器上安装这个工具。

它完美地安装在红帽机器上,没有任何错误。

我在互联网上搜索并找到了很多解决方案,但没有一个能够解决问题,甚至有些看起来与我无关,但为了安全起见,我尝试了所有这些......

1. LDFLAGS='-ldl' make install
2. sudo apt-get install glibc*
3. make CFLAGS="${CFLAGS} -ldl"
4. sudo apt-get install libjpeg62-dev
5.  sudo apt-get install libdb-devel
6. sudo apt-get install libdbl

错误:

  udit@udit-Notebook ~/Desktop/sendip-2.5-mec-0 $ make
   for subdir in mec ; do \
    cd $subdir ;\
    make  ;\
    cd ..  ;\
    done
make[1]: Entering directory `/home/udit/Desktop/sendip-2.5-mec-0/mec'
make[1]: Nothing to be done for `all'.
make[1]: Leaving directory `/home/udit/Desktop/sendip-2.5-mec-0/mec'
sh -c "if [ `uname` = Linux ] ; then \
gcc -o sendip -g  -rdynamic -ldl -lm -fPIC -fsigned-char -pipe -Wall -Wpointer-arith  
-Wwrite-strings -Wstrict-prototypes -Wnested-externs -Winline -Werror -g -Wcast-align  
-DSENDIP_LIBS=\"/usr/local/lib/sendip\" sendip.o gnugetopt.o gnugetopt1.o compact.o ; \
elif [ `uname` = SunOS ] ; then \
gcc -o sendip -g -lsocket -lnsl -lm -ldl -fPIC -fsigned-char -pipe -Wall  
-Wpointer-arith -Wwrite-strings -Wstrict-prototypes -Wnested-externs -Winline -Werror 
-g -Wcast-align -DSENDIP_LIBS=\"/usr/local/lib/sendip\" sendip.o gnugetopt.o  
gnugetopt1.o compact.o ;\
else \
gcc -o sendip -g -rdynamic -lm -fPIC -fsigned-char -pipe -Wall -Wpointer-arith -Wwrite- 
strings -Wstrict-prototypes -Wnested-externs -Winline -Werror -g -Wcast-align   
-DSENDIP_LIBS=\"/usr/local/lib/sendip\" sendip.o gnugetopt.o gnugetopt1.o compact.o ; \
fi"
sendip.o: In function `unload_modules':
/home/udit/Desktop/sendip-2.5-mec-0/sendip.c:211: undefined reference to `dlclose'
sendip.o: In function `load_module':
/home/udit/Desktop/sendip-2.5-mec-0/sendip.c:240: undefined reference to `dlopen'
/home/udit/Desktop/sendip-2.5-mec-0/sendip.c:241: undefined reference to `dlerror'
/home/udit/Desktop/sendip-2.5-mec-0/sendip.c:243: undefined reference to `dlopen'
/home/udit/Desktop/sendip-2.5-mec-0/sendip.c:244: undefined reference to `dlerror'
/home/udit/Desktop/sendip-2.5-mec-0/sendip.c:246: undefined reference to `dlopen'
/home/udit/Desktop/sendip-2.5-mec-0/sendip.c:247: undefined reference to `dlerror'
/home/udit/Desktop/sendip-2.5-mec-0/sendip.c:249: undefined reference to `dlopen'
/home/udit/Desktop/sendip-2.5-mec-0/sendip.c:250: undefined reference to `dlerror'
/home/udit/Desktop/sendip-2.5-mec-0/sendip.c:265: undefined reference to `dlsym'
/home/udit/Desktop/sendip-2.5-mec-0/sendip.c:266: undefined reference to `dlerror'
/home/udit/Desktop/sendip-2.5-mec-0/sendip.c:268: undefined reference to `dlclose'
/home/udit/Desktop/sendip-2.5-mec-0/sendip.c:272: undefined reference to `dlsym'
/home/udit/Desktop/sendip-2.5-mec-0/sendip.c:273: undefined reference to `dlerror'
/home/udit/Desktop/sendip-2.5-mec-0/sendip.c:275: undefined reference to `dlclose'
/home/udit/Desktop/sendip-2.5-mec-0/sendip.c:279: undefined reference to `dlsym'
/home/udit/Desktop/sendip-2.5-mec-0/sendip.c:280: undefined reference to `dlsym'
/home/udit/Desktop/sendip-2.5-mec-0/sendip.c:281: undefined reference to `dlerror'
/home/udit/Desktop/sendip-2.5-mec-0/sendip.c:282: undefined reference to `dlclose'
/home/udit/Desktop/sendip-2.5-mec-0/sendip.c:286: undefined reference to `dlsym'
/home/udit/Desktop/sendip-2.5-mec-0/sendip.c:287: undefined reference to `dlerror'
/home/udit/Desktop/sendip-2.5-mec-0/sendip.c:288: undefined reference to `dlclose'
/home/udit/Desktop/sendip-2.5-mec-0/sendip.c:292: undefined reference to `dlsym'
/home/udit/Desktop/sendip-2.5-mec-0/sendip.c:293: undefined reference to `dlerror'
/home/udit/Desktop/sendip-2.5-mec-0/sendip.c:294: undefined reference to `dlclose'
/home/udit/Desktop/sendip-2.5-mec-0/sendip.c:298: undefined reference to `dlsym'
/home/udit/Desktop/sendip-2.5-mec-0/sendip.c:299: undefined reference to `dlerror'
/home/udit/Desktop/sendip-2.5-mec-0/sendip.c:300: undefined reference to `dlclose'
collect2: ld returned 1 exit status
make: *** [sendip] Error 1

MakeFile 内容:

#configureable stuff
PREFIX ?= /usr/local
BINDIR ?= $(PREFIX)/bin
MANDIR ?= $(PREFIX)/share/man/man1
LIBDIR ?= $(PREFIX)/lib/sendip
#For most systems, this works
INSTALL ?= install
#For Solaris, you may need
#INSTALL=/usr/ucb/install

CFLAGS= -fPIC -fsigned-char -pipe -Wall -Wpointer-arith -Wwrite-strings \
        -Wstrict-prototypes -Wnested-externs -Winline -Werror -g   
-Wcast-align \
        -DSENDIP_LIBS=\"$(LIBDIR)\"
#-Wcast-align causes problems on solaris, but not serious ones
LDFLAGS=    -g -rdynamic -lm
#LDFLAGS_SOLARIS= -g -lsocket -lnsl -lm
LDFLAGS_SOLARIS= -g -lsocket -lnsl -lm -ldl
LDFLAGS_LINUX= -g  -rdynamic -ldl -lm
LIBCFLAGS= -shared
CC= gcc

PROGS= sendip
BASEPROTOS= ipv4.so ipv6.so
IPPROTOS= icmp.so tcp.so udp.so
UDPPROTOS= rip.so ripng.so ntp.so
TCPPROTOS= bgp.so
PROTOS= $(BASEPROTOS) $(IPPROTOS) $(UDPPROTOS) $(TCPPROTOS)
LIBS= libsendipaux.a
LIBOBJS= csum.o compact.o protoname.o headers.o parseargs.o
SUBDIRS= mec

all:    $(LIBS) subdirs sendip $(PROTOS) sendip.1 sendip.spec

#there has to be a nice way to do this
sendip: sendip.o    gnugetopt.o gnugetopt1.o compact.o
sh -c "if [ `uname` = Linux ] ; then \
$(CC) -o $@ $(LDFLAGS_LINUX) $(CFLAGS) $+ ; \
elif [ `uname` = SunOS ] ; then \
$(CC) -o $@ $(LDFLAGS_SOLARIS) $(CFLAGS) $+ ;\
else \
$(CC) -o $@ $(LDFLAGS) $(CFLAGS) $+ ; \
fi"

libsendipaux.a: $(LIBOBJS)
ar vr $@ $?

subdirs:
for subdir in $(SUBDIRS) ; do \
    cd $$subdir ;\
    make  ;\
    cd ..  ;\
    done

protoname.o:    mec/protoname.c
$(CC) -o $@ -c -I. $(CFLAGS) $+

headers.o:  mec/headers.c
$(CC) -o $@ -c -I. $(CFLAGS) $+

 parseargs.o:   mec/parseargs.c
$(CC) -o $@ -c -I. $(CFLAGS) $+

 sendip.1:  ./help2man $(PROGS) $(PROTOS) subdirs VERSION
        ./help2man -n "Send arbitrary IP packets" -N >sendip.1

 sendip.spec:   sendip.spec.in VERSION
        echo -n '%define ver ' >sendip.spec
        cat VERSION >>sendip.spec
        cat sendip.spec.in >>sendip.spec

 %.so: %.c $(LIBS)
        $(CC) -o $@ $(CFLAGS) $(LIBCFLAGS) $+ $(LIBS)

 .PHONY:    clean install

 clean:
        rm -f *.o *~ *.so $(PROTOS) $(PROGS) $(LIBS) core gmon.out
        for subdir in $(SUBDIRS) ; do \
            cd $$subdir ;\
            make clean ;\
            cd ..  ;\
            done

  veryclean:
        make clean
        rm -f sendip.spec sendip.1

  install:      all
        [ -d $(LIBDIR) ] || mkdir -p $(LIBDIR)
        [ -d $(BINDIR) ] || mkdir -p $(BINDIR)
        [ -d $(MANDIR) ] || mkdir -p $(MANDIR)
        $(INSTALL) -m 755 $(PROGS) $(BINDIR)
        $(INSTALL) -m 644 sendip.1 $(MANDIR)
        $(INSTALL) -m 755 $(PROTOS) $(LIBDIR)
        for subdir in $(SUBDIRS) ; do \
            cd $$subdir ;\
            make install ;\
            cd ..  ;\
            done

最佳答案

在 Linux Mint 13 和 Ubuntu 12.04 中遇到了同样的问题。以下是我为解决此问题所做的操作:

安装gcc-4.4

sudo apt-get install gcc-4.4

在 Makefile 中,将“cc”设置为指向 gcc-4.4。

CC= gcc-4.4

关于linux - 错误: undefined reference,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/11016493/

相关文章:

c++ - Node-gyp 无法编译 nodejs 扩展 ('fatal error, thread' 找不到文件)

c++ - 在 GCC 中使用 -O3 有什么缺点吗?

c - libev 循环在空闲时使用 99% 的 CPU

c++ - 如何确定符号链接(symbolic link)指向的文件路径?

linux - 仅更改其他人的权限

c++ - 获取导致 g++ 中链接器错误的文件

c++ - 为什么主可执行文件和 dlopen 加载的共享库共享一个命名空间静态变量的拷贝?

c - 何时在驱动程序代码中使用 stdint.h 的标量

gcc - 函数序言中的 sub esp、eax 的作用是什么?

delphi - 初始化部分没有被调用