How to expose an API in Android kernel? Somehow the following does not work:
I did EXPORT_SYMBOL(module1_func) in module1.c
Did extern module1_func(); in header file module1.h (placed the header file in 'kernel/include/linux')
In module2.c, I did #include <linux/module1.h> and called the function module1_func()
FYI: module1.c is in kernel/security/<clean> AND module2.c is in kernel/mm
After compilation I am getting the following linker error:
kernel/mm/built-in.o: In function `get_param':
:(.text+0x75c0): undefined reference to `module1_func'
make: *** [.tmp_vmlinux1] Error 1
Btw, I did a clean build, still the same.
Instead of extern module1_func(), only declare module1_func() in module1.h.
Refer this basic module for EXPORT_SYMBOL() understanding.
Related
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.
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.
In addition, this is the CMake file for the library:
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")
I found a workaround. There was a malloc.h header which wrapped malloc calls for the various targeted platforms. Besides that debatably naming a header malloc.h should be considered bad practice, the issue really seems to be in recent versions of the NDK, because the header is included as a private header in CMake and should not collide with the system malloc.h.
Renaming the header solved the issue.
Im trying to build an Ubuntu Touch tree, based on an Aosp tree I already correctly built.
It fails with this error
CAPEWrapper.cpp:16: error: undefined reference to '__xlog_buf_printf'
this is the header that file includes
#include "CAPEWrapper.h"
which on cascade includes
#include <cutils/xlog.h>
which in turn defines
#if defined(__cplusplus)
extern "C" {
#endif
int __xlog_buf_printf(int bufid, const struct xlog_record *rec, ...);
#if defined(__cplusplus)
}
#endif
I suspect that my g++ doesn't set __cplusplus macro. Could it be a realistic scenario with this kind of error? If this could be the problem, should I need to specify a standard implementation with "stdc=something" to solve it?
Any other idea is welcome.
Make sure that your project is linking libcutils, and that it's linking it in the correct order (i.e. that -lcutils appears in the linker command line after any module that depends on it).
In the end, I found that the modules was listed inside a macro called LOCAL_WHOLE_STATIC_LIBRARIES, that in Android environment passes its content to the --whole-archive flag of GCC linker.
I'm converting my legacy VC++ project to be compatible with Android NDK and I'm getting a weird error. The message says:
[armeabi] Compile++ thumb: procalc-core <= pcc_arithmetics.cpp
In file included from D:/Dokumenty/Dev/Android/ProCalc//jni/pcc_arithmetics.h:10:0,
from D:/Dokumenty/Dev/Android/ProCalc//jni/pcc_arithmetics.cpp:1:
D:/Dokumenty/Dev/Android/ProCalc//jni/pcc_common.h: In static member function
'static std::string ProCalcCore::CommonTools::ToStringBase(T, int)':
D:/Dokumenty/Dev/Android/ProCalc//jni/pcc_common.h:102:68: error: there are no
arguments to 'ConvertException' that depend on a template parameter, so a
declaration of 'ConvertException' must be available [-fpermissive]
throw ConvertException(PROCALC_ERROR_SYNTAX_INVALID_INTEGER_BASE);
^
D:/Dokumenty/Dev/Android/ProCalc//jni/pcc_common.h:102:68: note: (if you use
'-fpermissive', G++ will accept your code, but allowing the use of an undeclared
name is deprecated)
make.exe: *** [D:/Dokumenty/Dev/Android/ProCalc//obj/local/armeabi/objs/procalc-
core/pcc_arithmetics.o] Error 1
The error is thrown in the following place:
template <typename T>
std::string CommonTools::ToStringBase(T val, int base)
{
if (base < 2)
throw ConvertException(PROCALC_ERROR_SYNTAX_INVALID_INTEGER_BASE);
The caps-named error value is a #defined int value.
ConvertException is declared in another file:
namespace ProCalcCore
{
(...)
class ConvertException : public InternalException
{
public:
ConvertException(const unsigned long int & newErrorCode);
};
When I try to change ConvertException to ProCalcCore::ConvertException, I get another error:
D:/Dokumenty/Dev/Android/ProCalc//jni/pcc_common.h:102:10: error: 'ConvertException'
is not a member of 'ProCalcCore'
All dependencies are resolved correctly - in VS the project compiles without problems.
How can I solve it? What causes this error?
"In visual studio the project compiles without problems" is weak evidence that your dependencies are correct.
The problem is that ConvertException is not visible at the point where the template is declared. Some versions of Visual Studio only try to bind such "free" types and expressions at the point where the template is instantiated, which is not correct under the C++ standard.
So your compiler is pointing out that it cannot work out what type ConvertException refers to. In order for it to know what type it refers to, you need to either forward declare it (which can have its own problems), or #include the header file prior to using it.
If you think you are already #includeing it, often your problem is that the header file that contains ConvertException ends up #includeing CommonTools::ToStringBase. The header file guards (or #pragma once) then eliminate the infinite loop.
Annoyingly, how the infinite loop is eliminated depends on which header file you include first! If you include the ConvertException header file, it then includes ToStringBase, which includes ConvertException back. That second #include "ConvertException.h" is eliminated by header-file #define guards.
If you instead included ToStringBase first, it would include ConvertException, which then includes ToStringBase, which is eliminated by the header guards.
So whatever header file is included first ends up being parsed second.
I am trying to build a C++ code using NDK in android. I have a method which has a parameter vector < vector <float> > coordinates
Everything builds fine until I write this line inside my method
vector<float> firstPoint = coordinates.at(0);
I start getting this error
D:/eclipseworkspace/myLibProject/obj/local/armeabi/libmyLibProject.a(FileName.o): In function `std::priv::_Vector_base<std::vector<float, std::allocator<float> >, std::allocator<std::vector<float, std::allocator<float> > > >::_M_throw_out_of_range() const':
D:/androidndk/sources/cxx-stl/stlport/stlport/stl/_vector.c:45: undefined reference to `std::__stl_throw_out_of_range(char const*)'
collect2: ld returned 1 exit status
make: *** [/cygdrive/d/eclipseworkspace/myLibProject/obj/local/armeabi/libOutputName.so] Error 1
I have no clue why this is happening and Google is not helping either.
Thanks.
I think you are using two different implementation of the standard library in the same project.
It looks like you are compiling your files with (the headers of) an stlport implementation of the standard library in D:/android..., and you link against your local library.
You have to configure the linker in your ide (or Makefile) to use also the lib file of the same implementation (somewhere in D:/android... I guess).
This is a linking error. You need to add APP_STL := stlport_static to your Apllication.mk file. Also make sure that you use -fno-exceptions flag, since STLport is not compatible with C++ exceptions and RTTI.
You can get more info in APPLICATION-MK.HTML which is availavle in the docs folder of the NDK. CPLUSPLUS-SUPPORT.HTML is also worth to read.
this looks like a linker error. You probably forgot to add STL library reference to your build. Or it can't be found
Did you do this ?
#include <stdexcept>
#include <vector>
using namespace std;
When I changed
vector<float> firstPoint = coordinates.at(0);
to
vector<float> firstPoint = coordinates[0];
it started compiling..... :s y?
Currently I am working with the Android NDK and JNI. I am trying to build a C++ code with NDK.
But I got the following errors:
E:/Android/Tranining_workspace/BackUpMigrant/jni/ReadBackupArc5/ReadBackupArc5.cpp:10:19: error: fstream: No such file or directory
E:/Android/Tranining_workspace/BackUpMigrant/jni/ReadBackupArc5/ReadBackupArc5.cpp:20: error: 'ifstream' does not name a type
E:/Android/Tranining_workspace/BackUpMigrant/jni/ReadBackupArc5/ReadBackupArc5.cpp:21: error: 'ofstream' does not name a type
E:/Android/Tranining_workspace/BackUpMigrant/jni/ReadBackupArc5/ReadBackupArc5.cpp:22: error: 'ofstream' does not name a type
E:/Android/Tranining_workspace/BackUpMigrant/jni/ReadBackupArc5/ReadBackupArc5.cpp:34: error: 'string' was not declared in this scope
Can anyone please help me out?
I just encountered the same problem. Seems the STL is not automatically included in NDK projects by default. That also means iostream, fstream, string etc can't be used straight away. To enable them, you'll need to modify your Application.mk file. If you don't have one (it's in the <project>/jni directory), then just create a new, blank one. Add the line:
APP_STL := stlport_static
Also, also remember to include using namespace std; or equivalent, along with the usual #include <iostream> etc.
Did you remember your:
#include <iostream>
using namespace std;
definitions at the top of the file?
("using namespace std" isn't always a good idea, but that's a separate issue.)