从安卓NDK15切换到17使得malloc和朋友找不到

Switching from Android NDK 15 to 17 makes malloc and friends not found

本文关键字:malloc 使得 朋友 找不到 NDK15      更新时间:2023-10-16

我刚刚从NDK 15切换到安卓工作室安装的NDK(目前为17(。但是现在找不到malloc和friends,即使stdlib.h也包含在内。

我到处找过,但到目前为止没有找到解决方案。我的基类在c++中,它使用了一个c库。我认为这可能是相关的。下面是控制台输出。

In file included from ../../../../../../../hdm-deepmap-sql/dms/hdm-deepmap-sql/include/dms/DeepMapSQL.hpp:13:
In file included from /Users/ben/Library/Android/sdk/ndk-bundle/sources/cxx-stl/llvm-libc++/include/string:470:
In file included from /Users/ben/Library/Android/sdk/ndk-bundle/sources/cxx-stl/llvm-libc++/include/string_view:169:
In file included from /Users/ben/Library/Android/sdk/ndk-bundle/sources/cxx-stl/llvm-libc++/include/__string:56:
In file included from /Users/ben/Library/Android/sdk/ndk-bundle/sources/cxx-stl/llvm-libc++/include/algorithm:643:
In file included from /Users/ben/Library/Android/sdk/ndk-bundle/sources/cxx-stl/llvm-libc++/include/memory:644:
In file included from /Users/ben/Library/Android/sdk/ndk-bundle/sources/cxx-stl/llvm-libc++/include/typeinfo:61:
In file included from /Users/ben/Library/Android/sdk/ndk-bundle/sources/cxx-stl/llvm-libc++/include/exception:82:
/Users/ben/Library/Android/sdk/ndk-bundle/sources/cxx-stl/llvm-libc++/include/cstdlib:125:9: error: no member named 'calloc' in the global namespace
using ::calloc;
~~^
/Users/ben/Library/Android/sdk/ndk-bundle/sources/cxx-stl/llvm-libc++/include/cstdlib:126:9: error: no member named 'free' in the global namespace
using ::free;
~~^
/Users/ben/Library/Android/sdk/ndk-bundle/sources/cxx-stl/llvm-libc++/include/cstdlib:127:9: error: no member named 'malloc' in the global namespace
using ::malloc;
~~^
/Users/ben/Library/Android/sdk/ndk-bundle/sources/cxx-stl/llvm-libc++/include/cstdlib:128:9: error: no member named 'realloc' in the global namespace
using ::realloc;
~~^
4 errors generated.
ninja: build stopped: subcommand failed.

此外,这是库的CMake文件:

cmake_minimum_required(VERSION 3.6)
include(../../toolchain/macros.cmake)
project(hdmsql)

set(HDM_SQL_SRC_DIR ${CMAKE_CURRENT_SOURCE_DIR}/dms/hdm-deepmap-sql)
file(GLOB_RECURSE SOURCES
${HDM_SQL_SRC_DIR}/*.c
${HDM_SQL_SRC_DIR}/*.cpp
)
list(REMOVE_ITEM SOURCES ${HDM_SQL_SRC_DIR}/src/treeview.c)

add_library(hdmsql STATIC
${SOURCES}
)
target_link_libraries(hdmsql hdmmaputils)
target_include_directories(hdmsql PUBLIC ${HDM_SQL_SRC_DIR}/include/dms/)
target_include_directories(hdmsql PRIVATE ${HDM_SQL_SRC_DIR}/src/)
#############
configure_file(${HDM_SQL_SRC_DIR}/include/dms/DeepMapSQL.hpp "${CMAKE_CURRENT_BINARY_DIR}/DeepMapSQL.hpp")
configure_file(${HDM_SQL_SRC_DIR}/include/dms/dms.h "${CMAKE_CURRENT_BINARY_DIR}/dms.h")
configure_file(${HDM_SQL_SRC_DIR}/include/dms/geometry.h "${CMAKE_CURRENT_BINARY_DIR}/geometry.h")
configure_file(${HDM_SQL_SRC_DIR}/include/dms/vdbeapi.h "${CMAKE_CURRENT_BINARY_DIR}/vdbeapi.h")

我找到了一个解决方法。有一个malloc.h头,它封装了针对各种目标平台的malloc调用。除了有争议地将头命名为malloc.h应该被认为是不好的做法之外,这个问题似乎真的出现在最近版本的NDK中,因为头在CMake中作为私有头包含,不应该与系统malloc.h冲突。

重命名标头解决了问题。