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

时间:2021-02-14 15:06:28

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. What could cause this?

所以,我觉得有趣的是,第一个新的很好(第43行),但是第二个没有。这可能会导致什么?

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:

另一个新问题:

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.

如有任何帮助,我们将不胜感激。

2 个解决方案

#1


3  

It looks like you are not linking the proper C++ runtime libraries (which can be different then libstdc++). You should try using the C++ compiler to drive the linker rather then invoking the linker directly.

看起来您并没有链接到适当的c++运行时库(它可以与libstdc++不同)。您应该尝试使用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 ...

#2


1  

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.

它使链接器将“运行时类型信息”包含在您可能在代码中使用的二进制文件中。

#1


3  

It looks like you are not linking the proper C++ runtime libraries (which can be different then libstdc++). You should try using the C++ compiler to drive the linker rather then invoking the linker directly.

看起来您并没有链接到适当的c++运行时库(它可以与libstdc++不同)。您应该尝试使用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 ...

#2


1  

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.

它使链接器将“运行时类型信息”包含在您可能在代码中使用的二进制文件中。