android 与c的调用函数,如何从C文件调用CPP文件中的函数,反之亦然在ANDROID NDK中?...

2023-05-16

我无法从c文件中调用cpp文件中的函数,也无法从ndk中的cpp文件中调用c文件中的函数。如何从C文件调用CPP文件中的函数,反之亦然在ANDROID NDK中?

我尝试使用extern“C”{}。

粘贴代码我在这里试过以供参考。

CFileCallingCpp.c:

#include "CFileCallingCpp.h"

//#include "custom_debug.h"

#include "CppFile.h"

void tempFunc() {

}

void printTheLogs() {

//Its not possible to make use of the CPP class in c file

// CCustomDebug cls;

// cls.printErrorLog("This is the error log %d %s", 54321, "aaaaaaaaaaaaaaaaaa");

// cls.printErrorLog("EXAMPLE", "This is the error log %d %s", 54321, "aaaaaaaaaaaaaaaaaa");

printTheLogs1();

// tempFunc();

}

CFileCallingCpp.h:

#ifndef _CFILECALLINGCPP_H_

#define _CFILECALLINGCPP_H_

void printTheLogs();

#endif

CppFile.cpp:

#include "CppFile.h"

#include "custom_debug.h"

#include "CFileCallingCpp.h"

void printTheLogs1() {

CCustomDebug::printErrorLog("This is the error log %d %s", 54321, "aaaaaaaaaaaaaaaaaa");

CCustomDebug::printErrorLog("EXAMPLE", "This is the error log %d %s", 54321, "aaaaaaaaaaaaaaaaaa");

}

#if defined(__cplusplus)

extern "C" {

#endif

void callCFileFunc() {

printTheLogs();

// printTheLogs1();

}

#if defined(__cplusplus)

}

#endif

CppFile.h:

#ifndef _CPPFILE_H_

#define _CPPFILE_H_

void printTheLogs1();

#endif 个

错误我得到:

sh-4.1$ /cygdrive/c/Android/android-ndk/ndk-build

SharedLibrary : libJNIExInterface.so

D:/EclipseWorkspace/NativeExample/obj/local/armeabi/objs-debug/JNIExInterface/CppFile.o: In function `callCFileFunc':

D:/EclipseWorkspace/NativeExample/jni/CppFile.cpp:15: undefined reference to `printTheLogs()'

D:/EclipseWorkspace/NativeExample/obj/local/armeabi/objs-debug/JNIExInterface/CFileCallingCpp.o: In function `printTheLogs':

D:/EclipseWorkspace/NativeExample/jni/CFileCallingCpp.c:18: undefined reference to `printTheLogs1'

collect2: ld returned 1 exit status

make: *** [/cygdrive/d/EclipseWorkspace/NativeExample/obj/local/armeabi/libJNIExInterface.so] Error 1

sh-4.1$

请让我知道,如果有人知道如何从Android的NDK的C代码调用一段cpp的代码。

问候,

SSuman185

2011-11-24

Suman

本文内容由网友自发贡献,版权归原作者所有,本站不承担相应法律责任。如您发现有涉嫌抄袭侵权的内容,请联系:hwhale#tublm.com(使用前将#替换为@)

android 与c的调用函数,如何从C文件调用CPP文件中的函数,反之亦然在ANDROID NDK中?... 的相关文章

  • 开发一个Nginx模块hello

    开发一个Nginx模块 用C语言写一个ngx http hello module c的文件 C代码 ngx http hello module c Created on Apr 25 2015 Author lizhenbin includ
  • 升级 GCC 支持C++11

    一 错误发生情景 xff1a 使用sh setup sh安装软件时 xff0c 报以下错误 xff1a configure error A compiler with support for C 43 43 11 language feat
  • C++ 访问http接口

    添加头文件 include lt wininet h gt 附加库 xff1a pragma comment lib 34 Wininet lib 34 发送 int GetURLInternal LPCSTR lpszUrl std st
  • go module go.mod

    这一次 xff0c 彻底掌握go mod 1 版本号规范 go mod 对版本号的定义是有一定要求的 xff0c 它要求的格式为 v lt major gt lt minor gt lt patch gt xff0c 如果 major 版本
  • protobuf数据类型

    四 限定符 required optional repeated 的基本规则 1 在每个消息中必须至少留有一个required类型的字段 2 每个消息中可以包含0个或多个optional类型的字段 3 repeated表示的字段可以包含0个
  • gdb如何保存和读取断点

    刚开始在linux下学编程使用gdb的同学可能会发现 xff0c 每次用gdb设置断点调试程序 xff0c 但下次打开的时候所有断点都没有了 xff0c 很不方便 下面介绍保存和读取断点的方法 1 保存断点 先用info b 查看一下目前设
  • C可变参数函数 实现

    C函数要在程序中用到以下这些宏 void va start va list arg ptr prev param type va arg va list arg ptr type void va end va list arg ptr va
  • 灰度发布系统的实现

    灰度发布 xff0c 已经不是一个很新的概念了 xff0e 一个产品 xff0c 如果需要快速迭代开发上线 xff0c 又要保证质量 xff0c 保证刚上线的系统 xff0c 一旦出现问题那么可以很快的控制影响面 xff0c 就需要设计一套
  • 软件汉化教程

    看到网上经常有人问汉化方面的东西 xff0c 我今天也来灌水一篇 xff0c 来个汉化扫盲教程 写的不好的地方欢迎大家指正 xff01 OK xff0c 现在我们进入正题 我这里所说的汉化 xff0c 是指汉化 Windows 下的 PE
  • Python操作mysql数据库(封装基本的增删改查)

    新学Python xff0c 在这里分享操作MySQL的全过程 1 安装MySQL python 1 2 3 win amd64 py2 7 exe xff0c 这是操作mysql数据库的python库 xff0c 有32位和64位之分 x
  • iOS内存管理

    1 内总管理原则 引用计数 IOS的对象都继承于NSObject 该对象有一个方法 retainCount xff0c 内存引用计数 引用计数在很多技术都用到 window下的COM组件 xff0c 多线程的信号量 xff0c 读写锁 xf
  • python 网络框架twisted基础学习及详细讲解

    twisted网络框架的三个基础模块 xff1a Protocol ProtocolFactory Transport 这三个模块是构成twisted服务器端与客户端程序的基本 Protocol xff1a Protocol对象实现协议内容
  • Python中struct.pack()和struct.unpack()用法详细说明

    python 中的struct主要是用来处理C结构数据的 xff0c 读入时先转换为Python的 字符串 类型 xff0c 然后再转换为Python的结构化类型 xff0c 比如元组 tuple 啥的 一般输入的渠道来源于文件或者网络的二
  • PWM脉宽调制 与PPM、SBUS、DSM2 协议 详细介绍

    原文地址 xff1a http www 5imx com portal php mod 61 view amp aid 61 1351 相信这个问题是每个模友在新入航模坑时都会遇到的问题 xff0c 也仍然在困扰着不少新手 这里简单对比解释
  • C/C++ 数学库文件 (math.h)

    转载 xff1a C C 43 43 数学库文件 math h C 标准库 lt math h gt C 标准库 lt math h gt 菜鸟教程 一 xff1a min xff0c max 函数使用 在math h 中没有这两个函数 c
  • extern “C"作用

    1 在cpp文件中调用c文件中实现的函数的时候 xff0c 需要用extern 34 C 34 声明该函数 xff0c 否则cpp会按名字改编后的 函数名去找该函数而找不到 这是作用 xff09 c文件中有一函数 xff1a void Tr
  • c语言char数组指针,C中char数组与char指针的区别是什么?

    冉冉说 C中char数组与char指针的区别是什么 xff1f C99 N 1256草稿字符串文字有两种不同的用法 xff1a 初始化char char c 61 34 abc 34 这是 更神奇的 xff0c 并在6 7 8 14 初始化
  • api身份验证_api上下文中的身份验证

    api身份验证 APIs are becoming a main interface for interacting with many things from enterprise services public services off
  • CORS手机测试软件,千寻cors账号的差分播发服务连接稳定性测试教程,测量员们赶紧进来看看哦...

    原标题 xff1a 千寻cors账号的差分播发服务连接稳定性测试教程 xff0c 测量员们赶紧进来看看哦 最近看到有很多人都在咨询千寻cors账号差分播放服务的相关问题 xff0c 那么今天cors账号网给大家收集整理了一个关于差分播发服务
  • linux 模拟socket请求,SOCKET模拟HTTP请求

    SOCKET模拟HTTP请求 HTTP请求头部样例 xff1a GET HTTP 1 1 Accept html text Host 220 181 6 175 80 Connection Close 这是一个请求百度页面的头部 属性和值的

随机推荐