Closed benstadin closed 6 years ago
target_include_directories(hdmsql PUBLIC ${HDM_SQL_SRC_DIR}/include/dms/)
target_include_directories(hdmsql PRIVATE ${HDM_SQL_SRC_DIR}/src/)
I don't suppose either of these directories has its own stdlib.h or anything like that?
My trivial example matching yours (the include pattern of string -> list -> stdio.h, though from the error trace I think only the #include <string>
is the relevant part of your example) works fine for me.
I'll need either the failing compile command line or the preprocessed source in order to even guess at what else could be wrong.
After further investigation, the project had indeed a malloc.h (from an altered version of SQLite). Though, it was included as a private header and included different named wrapper functions. This has never been an issue before (though the naming was bad of course).
The reproduce the issue it should be enough to have an empty malloc.h header. The issue was gone after renaming this file. But I still think this issue should not occur.
Why should that work? The project has a malloc.h that is overriding the system's, and that malloc.h says there's no such thing as calloc, free, malloc, or realloc.
FYI, it looks like the only reason the project previously worked with r15 is that it defaulted to gnustl instead of libc++, and gnustl's <string>
doesn't include <cstdlib>
. The following test case fails on both r15c and r19-canary:
// include/malloc.h
// empty
// foo.cpp
#include <cstdlib>
int main() { return 0; }
# CMakeLists.txt
cmake_minimum_required(VERSION 3.6.0)
add_executable(foo foo.cpp)
target_include_directories(foo PRIVATE include)
To be fair, malloc.h is not specified as an official header. However, most Linux implementations have a malloc.h as well. The reason that this works in those cases, though, is that both malloc.h and cstdlib.h declare these functions, at least for the Linux I am using. Thus picking up the wrong "empty" malloc.h is fine.
Hmm. @enh: any reason we shouldn't pull the standard malloc decls out into <bits/malloc.h>
that gets included by both <stdlib.h>
and <malloc.h>
?
lots of code in our tree seems to assume that it can get memalign(3) from <stdlib.h>
, so i'll probably chicken out and include that in the set, but otherwise i'll take the opportunity to clean up too so folks pulling in <stdlib.h>
get less namespace pollution. (because apparently i haven't learned my lesson yet.)
the more i played with this and the more i thought about, the more i think it's a bad idea. it disrupts existing users for a fairly theoretical problem. i'd want to see more than one (already fixed) case to motivate actually making this change...
I just switched from NDK 15 to the one installed with Android Studio (which is currently 17). But now malloc and friends is not found, even though stdlib.h is included.
I've looked everywhere, but found no solution so far. My base class is in c++, which uses a C library. I think this might be relevant. below is the console output.
EDIT: I've removed everything from the C++ class. So it's just an entirely empty C++ file, and a header file. The problem here seems to be in mixing C++ and C with CMAKE with NDK - which is really odd. As an example, the below error for missing malloc/free is thrown when just is included. Thereby ruling out that my own includes are somehow messing things up. Example DeepMapSQL.hppp file:
Build log:
In addition, this is the CMake file for the library:
build.gradle: