DEV Community

HarmonyOS
HarmonyOS

Posted on

How solve 'undefined symbol error has occurred' error

Read the original article:How solve 'undefined symbol error has occurred' error

Question

How to fix undefined error while writing native c (NDK) application ?

22.png

Short Answer

The "undefined symbol" error typically indicates that the linker cannot find the definition of a specific symbol. This issue often occurs when source files are not compiled or linked correctly, or when the necessary library files are missing. To locate and rectify this issue, perform the following steps:

Check your CMakeLists.txt file to ensure that all relevant source files are included in the project.

Step 1 ->

23.jpg

Step 2->

24.jpg

Step 3-> Add library in CmakeLists.txt in target_link_libraries

# the minimum version of CMake.
cmake_minimum_required(VERSION 3.5.0)
project(NativeDrawing)

set(NATIVERENDER_ROOT_PATH ${CMAKE_CURRENT_SOURCE_DIR})

if(DEFINED PACKAGE_FIND_FILE)
    include(${PACKAGE_FIND_FILE})
endif()

include_directories(${NATIVERENDER_ROOT_PATH}
                    ${NATIVERENDER_ROOT_PATH}/include)

add_library(entry SHARED napi_init.cpp)
target_link_libraries(entry PUBLIC libace_napi.z.so libnative_drawing.so libace_ndk.z.so)
Enter fullscreen mode Exit fullscreen mode

Applicable Scenarios

HarmonyOS 2.0 and above.

Written by Ataberk Celiktas

Top comments (0)