English 中文(简体)
如何在CPP档案中从C.C.F.中称职,而在NNDK公司中则称职?
原标题:How to call a function in CPP file from C File and vice versa in ANDROID NDK?

我无法从案卷中抽取一个功能,也无法在案卷中从提克本身的一个卷宗中找到一个功能。

我还使用“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$

请允许我知道,是否有任何人知道如何从《印度民主与民主共和国法典》的法典中划出一条法典。

Regards,
SSuman185

最佳回答

The extern "C" should be in the Header file included by the C sources, not in the C++ source file. C++来源档案中包含的Cheler档案也是如此。

问题回答

如果你从文件上界定的电压档案中传出功能,你只能使用。

extern "C" void c_func(); // definition

// from a cpp file
c_func();

你们可以采取其他方式,把一功能用在一卷档案中。

// implemnatation in cpp file
extern "C" void cpp_func()
{
    // c++ code allowed here
}

// declaration in .h file
#ifdef _CPLUSPLUS
extern "C" void cpp_func();
#else
extern void cpp_func();
#endif

// from the c file
....
cpp_func();
.....




相关问题
Undefined reference

I m getting this linker error. I know a way around it, but it s bugging me because another part of the project s linking fine and it s designed almost identically. First, I have namespace LCD. Then I ...

C++ Equivalent of Tidy

Is there an equivalent to tidy for HTML code for C++? I have searched on the internet, but I find nothing but C++ wrappers for tidy, etc... I think the keyword tidy is what has me hung up. I am ...

Template Classes in C++ ... a required skill set?

I m new to C++ and am wondering how much time I should invest in learning how to implement template classes. Are they widely used in industry, or is this something I should move through quickly?

Print possible strings created from a Number

Given a 10 digit Telephone Number, we have to print all possible strings created from that. The mapping of the numbers is the one as exactly on a phone s keypad. i.e. for 1,0-> No Letter for 2->...

typedef ing STL wstring

Why is it when i do the following i get errors when relating to with wchar_t? namespace Foo { typedef std::wstring String; } Now i declare all my strings as Foo::String through out the program, ...

C# Marshal / Pinvoke CBitmap?

I cannot figure out how to marshal a C++ CBitmap to a C# Bitmap or Image class. My import looks like this: [DllImport(@"test.dll", CharSet = CharSet.Unicode)] public static extern IntPtr ...

Window iconification status via Xlib

Is it possible to check with the means of pure X11/Xlib only whether the given window is iconified/minimized, and, if it is, how?

热门标签