gpt4 book ai didi

Android makefile 链接两次

转载 作者:太空宇宙 更新时间:2023-11-04 11:25:14 25 4
gpt4 key购买 nike

我已经在 SDL 中为我的游戏设置了一个 makefile。 SDL中包含的Application.mk文件的模板有三种架构:

APP_ABI := armeabi armeabi-v7a x86

对于 armeabi,一切都编译得很好,但对于 armeabi-v7a,它会失败。对我来说,它看起来像编译完成,但链接器有两个特定文件夹的所有 obj 文件两次。虽然 armeabi 不会发生这种情况。链接器 (ld) 给我一个这样的错误:

/path/to/bin/ld: error: /path/to/myObjFile.obj: multiple definition of 'foo(int, int)'
/path/to/bin/ld: /path/to/myObjFile.obj: previous definition here

路径完全相同,所以这让我假设链接器使用每个文件两次。此类错误的完整示例如下:

/Users/martijncourteaux/Development/android-ndk-r10c/toolchains/arm-linux-androideabi-4.8/prebuilt/darwin-x86_64/lib/gcc/arm-linux-androideabi/4.8/../../../../arm-linux-androideabi/bin/ld: error: /Volumes/Stuff/Projects/GameDev/Gump/GumpAndroid/obj/local/armeabi-v7a/objs/main//Volumes/Stuff/Projects/GameDev/Gump/GumpAndroid/jni/src/__/ThirdParty/Box2D/Collision/b2Distance.o: multiple definition of 'b2Distance(b2DistanceOutput*, b2SimplexCache*, b2DistanceInput const*)'
/Users/martijncourteaux/Development/android-ndk-r10c/toolchains/arm-linux-androideabi-4.8/prebuilt/darwin-x86_64/lib/gcc/arm-linux-androideabi/4.8/../../../../arm-linux-androideabi/bin/ld: /Volumes/Stuff/Projects/GameDev/Gump/GumpAndroid/obj/local/armeabi-v7a/objs/main//Volumes/Stuff/Projects/GameDev/Gump/GumpAndroid/jni/src/__/ThirdParty/Box2D/Collision/b2Distance.o: previous definition here

但是,当我启动 ndk-build 时,双重链接的目标文件也会生成此警告:

/Users/martijncourteaux/Development/android-ndk-r10c/build/core/build-binary.mk:449: warning: ignoring old commands for target `/Volumes/Stuff/Projects/GameDev/Gump/GumpAndroid/obj/local/armeabi-v7a/objs/main//Volumes/Stuff/Projects/GameDev/Gump/GumpAndroid/jni/src/__/ThirdParty/Collision/b2Distance.o'
/Users/martijncourteaux/Development/android-ndk-r10c/build/core/build-binary.mk:449: warning: overriding commands for target `/Volumes/Stuff/Projects/GameDev/Gump/GumpAndroid/obj/local/armeabi-v7a/objs/main//Volumes/Stuff/Projects/GameDev/Gump/GumpAndroid/jni/src/__/ThirdParty/Collision/b2Distance.o'

请注意,我的印象是所有这些 obj - 具有这些 multiple definition 错误的文件也会生成此警告。

这是我的Application.mk:

APP_STL := gnustl_static
APP_ABI := armeabi armeabi-v7a x86
NDK_TOOLCHAIN_VERSION := clang
APP_CPPFLAGS += -std=c++11
APP_PLATFORM := android-10

这是我的 Android.mk:

LOCAL_PATH := $(call my-dir)

include $(CLEAR_VARS)

LOCAL_MODULE := main

SDL_PATH := ../SDL
THIRD_PARTY_FOLDER := $(LOCAL_PATH)/../ThirdParty

LOCAL_CPPFLAGS += -frtti
LOCAL_CPPFLAGS += -fexceptions
LOCAL_CPPFLAGS += -funwind-tables

PCH_FILE := $(LOCAL_PATH)/Gump/Gump-Prefix.pch
#PCH_FILE := Gump/Gump-Prefix.pch
LOCAL_CPPFLAGS += -include $(PCH_FILE)

#LOCAL_PCH := $(PCH_FILE)
#LOCAL_CPPFLAGS += -DPCH

LOCAL_C_INCLUDES := $(LOCAL_PATH)/$(SDL_PATH)/include \
$(LOCAL_PATH)/$(SDL_PATH)_mixer/ \
$(LOCAL_PATH)/$(SDL_PATH)_image/ \
$(LOCAL_PATH)/$(SDL_PATH)_net/ \
$(LOCAL_PATH)/../ThirdParty/ \
$(LOCAL_PATH)/Gump/

# Add your application source files here...
GUMP_SRC_FILES := $(wildcard $(LOCAL_PATH)/Gump/*.cpp)
THIRD_PARTY_SRC_FILES += $(wildcard $(THIRD_PARTY_FOLDER)/tinyxml2/tinyxml2.cpp)

THIRD_PARTY_SRC_FILES += $(wildcard $(THIRD_PARTY_FOLDER)/Box2D/*/*.cpp)
THIRD_PARTY_SRC_FILES += $(wildcard $(THIRD_PARTY_FOLDER)/Box2D/*/*/*.cpp)

THIRD_PARTY_SRC_FILES += $(wildcard $(THIRD_PARTY_FOLDER)/poly2tri/**/*.cc)

LOCAL_SRC_FILES := $(SDL_PATH)/src/main/android/SDL_android_main.c $(THIRD_PARTY_SRC_FILES) $(GUMP_SRC_FILES)

LOCAL_SHARED_LIBRARIES := SDL2_image SDL2_mixer SDL2_net SDL2

LOCAL_LDLIBS := -lGLESv1_CM -lGLESv2 -llog

include $(BUILD_SHARED_LIBRARY)

我的猜测(结果是错误的):

在写完这个问题并仔细查看以尽可能向你们提供关于我的问题的最准确信息之后,我注意到出现错误的 obj 文件是那些我也在文件夹级别使用了通配符的文件。例如:$(ROOT)/*/*.cpp。虽然这些通配符没有问题:$(ROOT)/Gump/*.cpp。我不确定,但我猜通配符在为这些不同的体系结构链接时会有所不同......

更新:

我再次测试了它,不使用文件夹的通配符,并且出现了关于多个定义的相同错误。

最佳答案

每次构建新的 ABI 时,都会附加您的文件列表。 LOCAL_SRC_FILES 通过include $(CLEAR_VARS) 被删除; GUMP_SRC_FILES 每次都被重新定义。但是 THIRD_PARTY_SRC_FILES 只会越来越长。正如您所注意到的,这与通配符无关。只需添加行

THIRD_PARTY_SRC_FILES :=

include $(CLEAR_VARS) 之后,您的构建就没问题了。

关于Android makefile 链接两次,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/26897684/

25 4 0
Copyright 2021 - 2024 cfsdn All Rights Reserved 蜀ICP备2022000587号
广告合作:1813099741@qq.com 6ren.com