无法从C ++代码访问C共享库方法

时间:2018-02-18 12:22:28

标签: android c++ c

我试图在我的C ++代码中包含一个C库。

C代码已编译到C库中。 C部分如下:

这是来自C组件的Android.mk文件:

LOCAL_PATH:= $(call my-dir)

    include $(CLEAR_VARS)
    LOCAL_SRC_FILES:= logger.c
    LOCAL_C_INCLUDES += $(LOCAL_PATH)
    LOCAL_CFLAGS += -Wall -Wno-unused-parameter -std=gnu99

    LOCAL_SHARED_LIBRARIES := libcutils libsysutils
    LOCAL_LDLIBS := -llog

    LOCAL_MODULE_OWNER := company_name
    LOCAL_PROPRIETARY_MODULE := true
    LOCAL_MODULE := liblogger
    LOCAL_MODULE_SUFFIX := .so
    LOCAL_MODULE_TAGS := optional

    include $(BUILD_SHARED_LIBRARY)

C层的头文件(c_logger.h)如下:

#if defined (__cplusplus)
extern "C" {
#endif // __cplusplus
int     logger_init ();
#if defined (__cplusplus)
}
#endif // __cplusplus

logger.c实现如下:

int combilog_init ()
{
    // logic
    return 0;
}

我的CPP代码,Android.mk,我已将此C库包含在" LOCAL_SHARED_LIBRARIES":

LOCAL_SHARED_LIBRARIES := liblogger

然后我在我的CPP代码中访问它:

int ret = init();

编译时,我发现以下错误:

In file included from xxxx/Logger.cpp:20:
XXXX/CPP_Logger.h:26:10: fatal error: 'c_logger.h' file not found

非常感谢任何帮助。

1 个答案:

答案 0 :(得分:0)

您仍需要包含匹配的.h,以便编译器识别您的init函数