Android NDK与CMAKE构建链接:对C ++对象/方法的未定义引用

时间:2017-06-09 01:13:42

标签: android android-ndk cmake

我使用gradle中的ndk构建工具完美地构建了这个项目,但现在我正在尝试迁移到本机构建的CMAKE系统,并且对于我的生活,我无法弄清楚问题是什么。我对这个CMAKE系统非常陌生,所以我确定它对我的CMakeLists.txt文件来说是微不足道的,但我似乎无法找出为什么我一直收到此错误< / p>

Information:Gradle tasks [:app:assembleDebug]
C:\Users\usr\AndroidStudioPs\GLDemo\app\src\main\jni\glesNative\glesContextActivity.cpp
   Error:(13) undefined reference to `GLESNative::GLESNative()'
   Error:error: linker command failed with exit code 1 (use -v to see invocation)

C:\Users\usr\AndroidStudioPs\GLDemo\app\src\main\jni\glesNative\myGLRenderer.cpp
    Error:(14) undefined reference to `gGlesObject'
    Error:(17) undefined reference to `gGlesObject'
    Error:(17) undefined reference to `GLESNative::Render()'
    Error:(24) undefined reference to `gGlesObject'
    Error:(27) undefined reference to `gGlesObject'
    Error:(27) undefined reference to `GLESNative::PerformGLInits()'
    Error:(35) undefined reference to `gGlesObject'
    Error:(38) undefined reference to `gGlesObject'
    Error:(38) undefined reference to `GLESNative::SetViewport(int, int)'
    Error:error: linker command failed with exit code 1 (use -v to see invocation)

这是项目结构

enter image description here

这是我的CMakeLists.txt

cmake_minimum_required(VERSION 3.4.1)

#add header files path
include_directories(src/main/jni/glesNative/)

add_library( # Specifies the name of the library.
         GLESNative

         # Sets the library as a shared library.
         SHARED

         # Provides a relative path to your source file(s).
         src/main/jni/glesNative/glesNative.cpp)

add_library( # Specifies the name of the library.
         dateLib

         # Sets the library as a shared library.
         SHARED

         # Provides a relative path to your source file(s).
         src/main/jni/glesNative/dateLib.cpp)

add_library( # Specifies the name of the library.
         glesContextActivity

         # Sets the library as a shared library.
         SHARED

         # Provides a relative path to your source file(s).
         src/main/jni/glesNative/glesContextActivity.cpp)

add_library( # Specifies the name of the library.
         myGLRenderer

         # Sets the library as a shared library.
         SHARED

         # Provides a relative path to your source file(s).
         src/main/jni/glesNative/myGLRenderer.cpp)

find_library(log log)
find_library(android android)
find_library(EGL EGL)
find_library(GLESv2 GLESv2)
find_library(stdc++ stdc++)

# Links your native library against one or more other native libraries.
target_link_libraries( # Specifies the target library.
                   GLESNative

                   # Links the libraries to the target library.
                   ${log} ${android} ${EGL} ${GLESv2} ${stdc++} ${glesContextActivity} ${myGLRenderer})

我试图将glesNative.cpp和glesNative.h文件中的方法和对象链接到myGLRenderer.cpp和glesContextActivity.cpp。任何建议都非常感谢。

0 个答案:

没有答案