未定义符号错误 [英] Undefined Symbol Error

查看:58
本文介绍了未定义符号错误的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我是一名 Java 开发人员,正在编译一些 C++ 代码来构建共享对象以在 Java 中访问它.我可以成功构建我的so"文件,但是当我使用 Java 加载它时,我收到 undefined symbol: _ZTI18TransportFormatter 错误.我在我的代码中为这个符号做了一个 grep,我发现这个符号是 TcpFormatter.o 和 UdpFormatter.o 的一部分.以下是我的make文件.如果我在这里遗漏了什么,请告诉我.

P.S:我正在 ARM 处理器上构建它.当我构建它并在常规 linux x86 上运行时,我没有问题.

提前致谢.

<前>LD_LIBRARY_PATH=/usr/lib/gcc/arm-linux-gnueabi/4.3.3/JDK_HOME=/home/skolli/native/java/includeCC=gccCCFLAGS=-c -O2INCLUDE_DIRS=-I$(JDK_HOME) -I$(JDK_HOME)/linuxLIBS=/usr/lib/libstdc++.so.6OBJ= Clock.o Constants.o IpFullAddress.o IcmpFormatter.o IpHeaderFormatter.o TcpFormatter.o UdpFormatter.o IcmpEchoFormatter.o IcmpErrorFormatter.o NetworkHandler.o IcmpTransfer.o jni_util.o JniConnector.oicmpTransfer: $(OBJ)$(CC) $(INCLUDE_DIRS) $(LIBS) -shared -o libicmpTransfer.so $(OBJ)Clock.o:Clock.cpp Clock.h JniConnector.h$(CC) $(INCLUDE_DIRS) $(CCFLAGS) $*.cppConstants.o:Constants.cpp Constants.h$(CC) $(INCLUDE_DIRS) $(CCFLAGS) $(FLAGS) $*.cppIcmpFormatter.o: IcmpFormatter.cpp IcmpFormatter.h Constants.h$(CC) $(INCLUDE_DIRS) $(CCFLAGS) $*.cppIpHeaderFormatter.o: IpHeaderFormatter.cpp IpHeaderFormatter.h Exception.h JniConnector.h$(CC) $(INCLUDE_DIRS) $(CCFLAGS) $*.cppTcpFormatter.o: TcpFormatter.cpp TcpFormatter.h IpFullAddress.h IcmpFormatter.h$(CC) $(INCLUDE_DIRS) $(CCFLAGS) $*.cppUdpFormatter.o: UdpFormatter.cpp UdpFormatter.h IpFullAddress.h TcpFormatter.h IcmpFormatter.h$(CC) $(INCLUDE_DIRS) $(CCFLAGS) $*.cppIcmpEchoFormatter.o: IcmpEchoFormatter.cpp IpHeaderFormatter.h IcmpFormatter.h IpHeaderFormatter.h$(CC) $(INCLUDE_DIRS) $(CCFLAGS) $*.cppIcmpErrorFormatter.o: IcmpErrorFormatter.cpp IcmpErrorFormatter.h IcmpEchoFormatter.h Exception.h IpHeaderFormatter.h IpFullAddress.h Exception.h JniConnector.h$(CC) $(INCLUDE_DIRS) $(CCFLAGS) $*.cppIpFullAddress.o: IpFullAddress.cpp IpFullAddress.h Exception.h JniConnector.h$(CC) $(INCLUDE_DIRS) $(CCFLAGS) $*.cppNetworkHandler.o: NetworkHandler.cpp NetworkHandler.h Clock.h IpFullAddress.h JniConnector.h$(CC) $(INCLUDE_DIRS) $(CCFLAGS) $*.cppIcmpTransfer.o: IcmpTransfer.cpp IcmpTransfer.h IcmpFormatter.h IcmpEchoFormatter.h IcmpErrorFormatter.h IpHeaderFormatter.h NetworkHandler.h Clock.h TcpFormatter.h JniConnector.h UdpFormatter.h$(CC) $(INCLUDE_DIRS) $(CCFLAGS) $*.cppjni_util.o:/home/skolli/native/share/TaCoreLib/jni_util.c/home/skolli/native/share/TaCoreLib/jni_util.h$(CC) $(INCLUDE_DIRS) $(CCFLAGS) $*.cJniConnector.o: JniConnector.cpp JniConnector.h ../TaCoreLib/jni_util.h com_attune_netally_ta_corelib_IcmpPacketTransfer.h Clock.h IcmpTransfer.h$(CC) $(INCLUDE_DIRS) $(CCFLAGS) $*.cpp干净的:-rm *.o

解决方案

只是一个有根据的猜测,但看起来您的代码使用了 RTTI (_ZTI18TransportFormatter = typeinfo for TransportFormatter),直接通过调用 dynamic_cast 或如果您没有通过 -fno-rtti 选项明确禁用它,typeid 或编译器/链接器无论如何都会包含它,但这在嵌入式平台上通常不可用.

I am a java developer and compiling some C++ code to build a Shared Object to access it in Java. I can successfully build my 'so' file but when I load it using Java I get undefined symbol: _ZTI18TransportFormatter error. I did a grep for this symbol in my code and I found that the symbol is part of TcpFormatter.o and UdpFormatter.o. Following is my make file. Please tell me if I am missing anything here.

P.S: I am building this on ARM processor. When I build this and run on a regular linux x86, I have no problems.

Thanks in Advance.


LD_LIBRARY_PATH=/usr/lib/gcc/arm-linux-gnueabi/4.3.3/
JDK_HOME=/home/skolli/native/java/include
CC=gcc
CCFLAGS=-c -O2
INCLUDE_DIRS=-I$(JDK_HOME) -I$(JDK_HOME)/linux
LIBS=/usr/lib/libstdc++.so.6
OBJ= Clock.o Constants.o IpFullAddress.o IcmpFormatter.o IpHeaderFormatter.o TcpFormatter.o UdpFormatter.o IcmpEchoFormatter.o IcmpErrorFormatter.o NetworkHandler.o IcmpTransfer.o jni_util.o JniConnector.o

icmpTransfer:   $(OBJ)
    $(CC) $(INCLUDE_DIRS) $(LIBS) -shared -o libicmpTransfer.so $(OBJ)
Clock.o:        Clock.cpp Clock.h JniConnector.h
    $(CC) $(INCLUDE_DIRS) $(CCFLAGS) $*.cpp
Constants.o:        Constants.cpp Constants.h
    $(CC) $(INCLUDE_DIRS) $(CCFLAGS) $(FLAGS) $*.cpp
IcmpFormatter.o:        IcmpFormatter.cpp IcmpFormatter.h Constants.h
    $(CC) $(INCLUDE_DIRS) $(CCFLAGS) $*.cpp
IpHeaderFormatter.o:    IpHeaderFormatter.cpp IpHeaderFormatter.h Exception.h JniConnector.h
    $(CC) $(INCLUDE_DIRS) $(CCFLAGS) $*.cpp
TcpFormatter.o:         TcpFormatter.cpp TcpFormatter.h IpFullAddress.h IcmpFormatter.h
    $(CC) $(INCLUDE_DIRS) $(CCFLAGS) $*.cpp
UdpFormatter.o:     UdpFormatter.cpp UdpFormatter.h IpFullAddress.h TcpFormatter.h IcmpFormatter.h
    $(CC) $(INCLUDE_DIRS) $(CCFLAGS) $*.cpp
IcmpEchoFormatter.o:    IcmpEchoFormatter.cpp IpHeaderFormatter.h IcmpFormatter.h IpHeaderFormatter.h
    $(CC) $(INCLUDE_DIRS) $(CCFLAGS) $*.cpp
IcmpErrorFormatter.o:   IcmpErrorFormatter.cpp IcmpErrorFormatter.h IcmpEchoFormatter.h Exception.h IpHeaderFormatter.h IpFullAddress.h Exception.h JniConnector.h
    $(CC) $(INCLUDE_DIRS) $(CCFLAGS) $*.cpp
IpFullAddress.o:        IpFullAddress.cpp IpFullAddress.h Exception.h JniConnector.h
    $(CC) $(INCLUDE_DIRS) $(CCFLAGS) $*.cpp
NetworkHandler.o:       NetworkHandler.cpp NetworkHandler.h Clock.h IpFullAddress.h JniConnector.h
    $(CC) $(INCLUDE_DIRS) $(CCFLAGS) $*.cpp
IcmpTransfer.o:         IcmpTransfer.cpp IcmpTransfer.h IcmpFormatter.h IcmpEchoFormatter.h IcmpErrorFormatter.h IpHeaderFormatter.h NetworkHandler.h Clock.h TcpFormatter.h JniConnector.h UdpFormatter.h
    $(CC) $(INCLUDE_DIRS) $(CCFLAGS) $*.cpp
jni_util.o:         /home/skolli/native/share/TaCoreLib/jni_util.c /home/skolli/native/share/TaCoreLib/jni_util.h
    $(CC) $(INCLUDE_DIRS) $(CCFLAGS) $*.c
JniConnector.o:         JniConnector.cpp JniConnector.h ../TaCoreLib/jni_util.h com_attune_netally_ta_corelib_IcmpPacketTransfer.h Clock.h IcmpTransfer.h
    $(CC) $(INCLUDE_DIRS) $(CCFLAGS) $*.cpp


clean:
    -rm *.o

解决方案

Just an educated guess but it looks like your code uses RTTI (_ZTI18TransportFormatter = typeinfo for TransportFormatter), either directly by calling dynamic_cast or typeid or the compiler/linker will include it anyway if you don't explicitly disable it via the -fno-rtti option, but that's usually not available on embedded platforms.

这篇关于未定义符号错误的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆