【问题标题】:Getting error: undefined reference to function Android NDK出现错误:未定义对函数 Android NDK 的引用
【发布时间】:2017-11-19 11:44:55
【问题描述】:

我已经尝试解决这个问题两天多,但仍然没有运气。

我不知道哪里出了问题,我只需要设置一个简单的 NDK 项目,但它已经花费了大量时间。

问题是我得到了

error: undefined reference to 'firpm(unsigned int, std::vector<double, std::allocator<double> > const&, std::vector<double, std::allocator<double> > const&, std::vector<double, std::allocator<double> > const&, double, int)'

这是我的根 CMakeLists

# Cmake Minimum Version
cmake_minimum_required(VERSION 3.4.1)
project(EcgProcessing)
# Add nested cmake files
include(libs/CMakeLists.txt)

include_directories(${CMAKE_CURRENT_SOURCE_DIR})

# ECG Audio Processor library
add_library(ecg-signal-processor-demodulator SHARED
            demodulator.cpp)
add_library(ecg-signal-processor-qrsdetection SHARED
            qrsdetection.cpp)
# Link

target_link_libraries(
            firpm_d
            log
            android
            ecg-signal-processor-demodulator
            ecg-signal-processor-qrsdetection)

在libs目录下

# Cmake Minimum Version
cmake_minimum_required(VERSION 3.4.1)
set(LIBS_DIRECTORY ${CMAKE_CURRENT_LIST_DIR})
#include_directories(${CMAKE_CURRENT_SOURCE_DIR}/Eigen/)
MACRO(ADD_SUBLIB libname source_ext)
  #Compute required sources
  set(sublib_path "${LIBS_DIRECTORY}/${libname}")
  file(GLOB_RECURSE sublib_sources "${sublib_path}/src/*.${source_ext}")
  #Create library
  IF( sublib_sources )
    ADD_LIBRARY(${libname} SHARED ${sublib_sources})
  ENDIF()
  #add this library's header folder to the global include set
  INCLUDE_DIRECTORIES("${sublib_path}/include")
  INCLUDE_DIRECTORIES("${sublib_path}/")
  link_directories(${sublib_path})
ENDMACRO(ADD_SUBLIB)

ADD_SUBLIB(firpm_d "cpp")
ADD_SUBLIB(eigen "cpp")

它开始编译项目,但最终出现错误。

什么会导致这个错误,我不知道该怎么做。

这里是源代码,所以你可以看到它的结构。 https://github.com/DurianOdour/EcgProcessor

如果有任何帮助,我将不胜感激

【问题讨论】:

  • 您显然没有链接任何定义 firpm 符号的内容。 或者您以不正确的顺序链接事物,因此链接器在提供它的 objct 文件或库之前看不到该符号(是的,链接顺序很重要)。
  • @JesperJuhl,谢谢你的评论,我包括firpm头文件以及使用ADD_SUBLIB宏的源文件,这个函数位于pm.h文件中。
  • 标题在这里无关紧要。重要的是文件实现函数它出现在相对于使用它的文件的链接行上。 使用符号的文件必须(通常)在文件提供符号之前提及。
  • @JesperJuhl,我也添加了源文件file(GLOB_RECURSE sublib_sources "${sublib_path}/src/*.${source_ext}")

标签: android c++ cmake android-ndk ndk-build


【解决方案1】:

我找到了解决方案。这里是

Android ndk(cmake): 'undefined reference to `__android_log_write' when using log api in the second jni library

问题在于链接库的顺序不正确。

这段代码很好用

# Link
target_link_libraries(
            ecg-signal-processor
            log
            android
            firpm_d)

第一个参数应该是需要依赖项的库。

target_link_libraries(<target> [item1 [item2 [...]]]
                      [[debug|optimized|general] <item>] ...)

【讨论】:

    猜你喜欢
    • 1970-01-01
    • 1970-01-01
    • 2013-05-07
    • 1970-01-01
    • 1970-01-01
    • 1970-01-01
    • 2017-03-13
    • 1970-01-01
    • 1970-01-01
    相关资源
    最近更新 更多