c++ - C 和 C++ --- undefined reference

标签 c++ c undefined-symbol

我需要帮助!

我在下一个路径中实现了一个.cpp程序:home/virginia/android/vlc/src/input/virtual.cpp

    /*
    *  virtual.cpp
    */
    #include <stdlib.h>

    #include <jni.h>
    #include <math.h>

    #include <opencv2/core/core.hpp>
    #include <opencv2/imgproc/imgproc.hpp>
    #include <opencv2/imgproc/types_c.h>
    #include <opencv2/highgui/highgui_c.h>
    #include <opencv2/photo/photo.hpp>

    #include <android/log.h>

    extern "C" {
       #include "virtual.h"
    }
    #define  LOG_TAG    "VLC - Imagen 3D -  JNI"
    #define  LOGI(...)  __android_log_print(ANDROID_LOG_INFO,LOG_TAG,__VA_ARGS__)
    #define  LOGE(...)  __android_log_print(ANDROID_LOG_ERROR,LOG_TAG,__VA_ARGS__)

    using namespace cv;
    using namespace std;

    extern "C" int camino(void){... }

此程序调用 opencv 函数。

virtual.h ( home/virginia/android/vlc/src/input/virtual.h)

/*
* virtual.h
*/
    #ifndef __VIRTUAL_H
    #define __VIRTUAL_H

    int camino(void);

    #endif /*__VIRTUAL_H*/

但问题是我需要从 decoder.c 调用“camino”函数((home/virginia/android/vlc/src/input/decoder.c):

#include "virtual.h"

#ifdef HAVE_CONFIG_H
# include "config.h"
#endif
#include <assert.h>

...
static void DecoderPlayVideo( decoder_t *p_dec, picture_t *p_picture,
                              int *pi_played_sum, int *pi_lost_sum ){

...
            int res = camino();
            msg_Warn( p_dec, "Llamada a virtualJNI devuelve %d", &res );
            vout_PutPicture( p_vout, p_picture );
...
}
...

我遇到下一个错误:

/home/virginia/android-ndk-r8c/toolchains/arm-linux-androideabi-4.6/prebuilt/linux-x86/bin/../lib/gcc/arm-linux-androideabi/4.6/../../../../arm-linux-androideabi/bin/ld: ../vlc/android/src/.libs/libvlccore.a(decoder.o): in function DecoderDecodeVideo:../../src/input/decoder.c:1501: error: undefined reference to 'camino'
collect2: ld returned 1 exit status
make[1]: *** [obj/local/armeabi-v7a/libvlcjni.so] Error 1
make[1]: Leaving directory `/home/virginia/android/vlc-android'
make: *** [vlc-android/obj/local/armeabi-v7a/libvlcjni.so] Error 2

我做错了什么?非常感谢

最佳答案

关于 extern "C" 的东西,不建议这样做:

extern "C" {
   #include "virtual.h"
}

相反,你应该把它放在标题中:

/*
* virtual.h
*/
    #ifndef __VIRTUAL_H
    #define __VIRTUAL_H

    #ifdef __cplusplus
    extern "C" {
    #endif

    int camino();

    #ifdef __cplusplus
    }
    #endif

    #endif /*__VIRTUAL_H*/

您会在几乎所有旨在在 C 和 C++ 之间共享的 header 中看到这一点。

至于你真正的问题,你必须向我们展示实际的链接器命令,而不仅仅是错误,但它看起来像 virtual.o 没有被链接到你的程序中,并且可能没有在 build 中。

关于c++ - C 和 C++ --- undefined reference ,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/17998338/

相关文章:

c++ - 如何编译/构建/链接 - XLNT 库?

c - 倒序时最后一个词没有倒序

C++ undefined symbol 错误与 ForceFit

compiler-errors - D 和 SDL - 函数未定义

c++ - C++中没有参数和void参数有什么区别?

c++ - 二叉搜索树递归插入

C++如何调用子类函数

c - UNIX 和 Windows 上的非规范模式 getchar()

c - gcc C 编译器是用 C 本身编写的吗?

c++ - 目标文件中带有 "U" undefined symbol 类型的程序如何在没有任何链接器错误的情况下进行编译?