简体   繁体   English

Linux C ++:链接器输出奇怪的错误

[英]Linux C++: Linker is outputting strange errors

Alright, here is the output I get: 好了,这是我得到的输出:

arm-none-linux-gnueabi-ld --entry=main -dynamic-linker=/system/bin/linker -rpath-link=/home/oem/android-ndk-r3/build/platforms/android-5/arch-arm/usr/lib -L/home/oem/android-ndk-r3/build/platforms/android-5/arch-arm/usr/lib -nostdlib -lstdc++ -lm -lGLESv1_CM -rpath=/home/oem/android-ndk-r3/build/platforms/android-5/arch-arm/usr/lib -rpath=../../YoghurtGum/lib/Android -L./lib/Android intermediate/Alien.o intermediate/Bullet.o intermediate/Game.o intermediate/Player.o ../../YoghurtGum/bin/YoghurtGum.a -o bin/Galaxians.android
intermediate/Game.o: In function `Galaxians::Init()':
/media/YoghurtGum/Tests/Galaxians/src/Game.cpp:45: undefined reference to `__cxa_end_cleanup'
/media/YoghurtGum/Tests/Galaxians/src/Game.cpp:44: undefined reference to `__cxa_end_cleanup'
intermediate/Game.o:(.ARM.extab+0x18): undefined reference to `__gxx_personality_v0'
intermediate/Game.o: In function `Player::Update()':
/media/YoghurtGum/Tests/Galaxians/src/Player.h:41: undefined reference to `__cxa_end_cleanup'
intermediate/Game.o:(.ARM.extab.text._ZN6Player6UpdateEv[_ZN6Player6UpdateEv]+0x0): undefined reference to `__gxx_personality_v0'
intermediate/Game.o:(.rodata._ZTIN10YoghurtGum4GameE[_ZTIN10YoghurtGum4GameE]+0x0): undefined reference to `vtable for __cxxabiv1::__class_type_info'
intermediate/Game.o:(.rodata._ZTI6Player[_ZTI6Player]+0x0): undefined reference to `vtable for __cxxabiv1::__si_class_type_info'
intermediate/Game.o:(.rodata._ZTIN10YoghurtGum6EntityE[_ZTIN10YoghurtGum6EntityE]+0x0): undefined reference to `vtable for __cxxabiv1::__si_class_type_info'
intermediate/Game.o:(.rodata._ZTIN10YoghurtGum6ObjectE[_ZTIN10YoghurtGum6ObjectE]+0x0): undefined reference to `vtable for __cxxabiv1::__class_type_info'
intermediate/Game.o:(.rodata._ZTI6Bullet[_ZTI6Bullet]+0x0): undefined reference to `vtable for __cxxabiv1::__si_class_type_info'
intermediate/Game.o:(.rodata._ZTI5Alien[_ZTI5Alien]+0x0): undefined reference to `vtable for __cxxabiv1::__si_class_type_info'
intermediate/Game.o:(.rodata+0x20): undefined reference to `vtable for __cxxabiv1::__si_class_type_info'
../../YoghurtGum/bin/YoghurtGum.a(Sprite.o):(.rodata._ZTIN10YoghurtGum16SpriteDataOpenGLE[_ZTIN10YoghurtGum16SpriteDataOpenGLE]+0x0): undefined reference to `vtable for __cxxabiv1::__si_class_type_info'
../../YoghurtGum/bin/YoghurtGum.a(Sprite.o):(.rodata._ZTIN10YoghurtGum10SpriteDataE[_ZTIN10YoghurtGum10SpriteDataE]+0x0): undefined reference to `vtable for __cxxabiv1::__class_type_info'
make: *** [bin/Galaxians.android] Fout 1

Here's an error I managed to decipher: 我设法破译了一个错误:

intermediate/Game.o: In function `Galaxians::Init()':
/media/YoghurtGum/Tests/Galaxians/src/Game.cpp:45: undefined reference to `__cxa_end_cleanup'
/media/YoghurtGum/Tests/Galaxians/src/Game.cpp:44: undefined reference to `__cxa_end_cleanup'

This is line 43 through 45: 这是第43至45行:

Assets::AddSprite(new Sprite("media\\ViperMarkII.bmp"),     "ship");
Assets::AddSprite(new Sprite("media\\alien.bmp"),           "alien");
Assets::AddSprite(new Sprite("media\\bat_ball.bmp"),        "bullet");

So, what seems funny to me is that the first new is fine (line 43), but the second one isn't. 因此,对我来说有趣的是,第一个new的很好(第43行),但是第二个不是。 What could cause this? 是什么原因造成的?

intermediate/Game.o: In function `Player::Update()':
/media/YoghurtGum/Tests/Galaxians/src/Player.h:41: undefined reference to `__cxa_end_cleanup'

Another issue with new : new另一个问题:

Engine::game->scene_current->AddObject(new Bullet(m_X + 10, m_Y));

I have no idea where to begin with the other issues. 我不知道从其他问题开始。

These are my makefiles, They're a giant mess because I'm just trying to get it to work. 这些是我的makefile,它们是一团糟,因为我只是想使其工作。

Static library: 静态库:

# ====================================== #
#                                        #
#       YoghurtGum static library        #
#                                        #
# ====================================== #

include ../YoghurtGum.mk

PROGS = bin/YoghurtGum.a
SOURCES = $(wildcard src/*.cpp)

#$(YG_PATH_LIB)/libGLESv1_CM.so \
#$(YG_PATH_LIB)/libEGL.so \

YG_LINK_OPTIONS = -shared
YG_LIBRARIES = \
  $(YG_PATH_LIB)/libc.a \
  $(YG_PATH_LIB)/libc.so \
  $(YG_PATH_LIB)/libstdc++.a \
  $(YG_PATH_LIB)/libstdc++.so \
  $(YG_PATH_LIB)/libm.a \
  $(YG_PATH_LIB)/libm.so \
  $(YG_PATH_LIB)/libui.so \
  $(YG_PATH_LIB)/liblog.so \
  $(YG_PATH_LIB)/libGLESv2.so \
  $(YG_PATH_LIB)/libcutils.so \

YG_OBJECTS = $(patsubst src/%.cpp, $(YG_INT)/%.o, $(SOURCES))

YG_NDK_PATH_LIB = /home/oem/android-ndk-r3/build/platforms/android-5/arch-arm/usr/lib

all: $(PROGS)

rebuild: clean $(PROGS)

# remove all .o objects from intermediate and all .android objects from bin
clean:
    rm -f $(YG_INT)/*.o $(YG_BIN)/*.a

copy:
    acpy ../$(PROGS)   

$(PROGS): $(YG_OBJECTS)
    $(YG_ARCHIVER) -vq $(PROGS) $(YG_NDK_PATH_LIB)/crtbegin_static.o $(YG_NDK_PATH_LIB)/crtend_android.o $^ && \
  $(YG_ARCHIVER) -vr $(PROGS) $(YG_LIBRARIES) 

$(YG_OBJECTS): $(YG_INT)/%.o : $(YG_SRC)/%.cpp
    $(YG_COMPILER) $(YG_FLAGS) -I $(GLES_INCLUDES) -c $< -o $@

Test game project: 测试游戏项目:

# ====================================== #
#                                        #
#               Galaxians                #
#                                        #
# ====================================== #

include ../../YoghurtGum.mk

PROGS = bin/Galaxians.android

YG_COMPILER = arm-none-linux-gnueabi-g++
YG_LINKER = arm-none-linux-gnueabi-ld
YG_PATH_LIB = ./lib/Android
YG_LIBRARIES = ../../YoghurtGum/bin/YoghurtGum.a

YG_PROGS = bin/Galaxians.android
GLES_INCLUDES = ../../YoghurtGum/src

ANDROID_NDK_ROOT = /home/oem/android-ndk-r3
NDK_PLATFORM_VER = 5
YG_NDK_PATH_LIB = $(ANDROID_NDK_ROOT)/build/platforms/android-$(NDK_PLATFORM_VER)/arch-arm/usr/lib

YG_LIBS = -nostdlib -lstdc++ -lm -lGLESv1_CM

#YG_COMPILE_OPTIONS = -g -rdynamic -Wall -Werror -O2 -w
YG_COMPILE_OPTIONS = -g -Wall -Werror -O2 -w
YG_LINK_OPTIONS = --entry=main -dynamic-linker=/system/bin/linker -rpath-link=$(YG_NDK_PATH_LIB) -L$(YG_NDK_PATH_LIB) $(YG_LIBS)

SOURCES = $(wildcard src/*.cpp)
YG_OBJECTS = $(patsubst src/%.cpp, intermediate/%.o, $(SOURCES))

all: $(PROGS)

rebuild: clean $(PROGS)

clean:
    rm -f intermediate/*.o bin/*.android

$(PROGS): $(YG_OBJECTS)
    $(YG_LINKER) $(YG_LINK_OPTIONS) -rpath=$(YG_NDK_PATH_LIB) -rpath=../../YoghurtGum/lib/Android -L$(YG_PATH_LIB) $^ $(YG_LIBRARIES) -o $@

$(YG_OBJECTS): intermediate/%.o : src/%.cpp
    $(YG_COMPILER) $(YG_COMPILE_OPTIONS) -I ../../YoghurtGum/src/GLES -I ../../YoghurtGum/src -c $< -o $@

Any help would be appreciated. 任何帮助,将不胜感激。

It looks like you are not linking the proper C++ runtime libraries (which can be different then libstdc++). 看来您没有链接正确的C ++运行时库(与libstdc ++可能不同)。 You should try using the C++ compiler to drive the linker rather then invoking the linker directly. 您应该尝试使用C ++编译器来驱动链接器,而不是直接调用链接器。

If you need to pass linker specific options via the compiler, you can use -Wl: 如果需要通过编译器传递链接器特定的选项,则可以使用-Wl:

arm-none-linux-gnueabi-g++ -Wl,--entry=main -Wl,-dynamic-linker=/system/bin/linker ...

I just had very similar problem, and I got the answer from colleagues. 我只是遇到了非常类似的问题,并且得到了同事的答案。

   LOCAL_CFLAGS += -frtti

It makes linker to include the "Runtime type info" into the binaries which you may use in your code. 它使链接器将“运行时类型信息”包含在您可以在代码中使用的二进制文件中。

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM