Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Error linking during compilation with Advanced Sensing #851

Open
Caseiber opened this issue Dec 3, 2021 · 3 comments
Open

Error linking during compilation with Advanced Sensing #851

Caseiber opened this issue Dec 3, 2021 · 3 comments

Comments

@Caseiber
Copy link

Caseiber commented Dec 3, 2021

I am trying to compile a file that imports the OSDK and uses advanced sensing. Everything seems to build, but during linking I get an error. This is my CMake file.

cmake_minimum_required(VERSION 3.0)
project(camera_access)

# Set compiler flags + our source files
set(CMAKE_CXX_FLAGS "${CMAKE_CXX_FLAGS} -std=c++11 -pthread -g -O0")
set(THREADS_PREFER_PTHREAD_FLAG ON)
set(SRC_FILES ${SRC_FILES} camera_access.cpp)

# Enable advanced sensing
set(ADVANCED_SENSING 1)
if (ADVANCED_SENSING)
  add_definitions(-DADVANCED_SENSING)
endif()

# CPU-specific stuff
if(CMAKE_SYSTEM_PROCESSOR MATCHES "i386|i686|x86|AMD64|x86_64")
   set(ARCH x86)
   add_definitions(-DDJIOSDK_HARDWARE_TYPE=3)
elseif((CMAKE_SYSTEM_PROCESSOR MATCHES "^arm*") OR (CMAKE_SYSTEM_PROCESSOR MATCHES "^aarch"))
  if(CMAKE_SIZEOF_VOID_P EQUAL 4)
     set(ARCH armv7)
     add_definitions(-DDJIOSDK_HARDWARE_TYPE=1)
  elseif(CMAKE_SIZEOF_VOID_P EQUAL 8)
     set(ARCH armv8)
     add_definitions(-DDJIOSDK_HARDWARE_TYPE=2)
  endif()
elseif()
  add_definitions(-DDJIOSDK_HARDWARE_TYPE=0)
endif()

# Set the DJI sources
if (NOT ONBOARDSDK_SOURCE)
    set(ONBOARDSDK_SOURCE "~/Projects/Onboard-SDK/osdk-core")
endif()
set(ORI_OSDK_CORE_SRC "${ONBOARDSDK_SOURCE}/advanced-sensing/ori-osdk-core")

# Include DJI header directories
include_directories(${ONBOARDSDK_SOURCE}/api/inc)
include_directories(${ONBOARDSDK_SOURCE}/utility/inc)
include_directories(${ONBOARDSDK_SOURCE}/hal/inc)
include_directories(${ONBOARDSDK_SOURCE}/protocol/inc)
include_directories(${ONBOARDSDK_SOURCE}/platform/linux/inc)
include_directories(${ONBOARDSDK_SOURCE}/platform/${ARCH}/inc)
include_directories(${ONBOARDSDK_SOURCE}/../sample/platform/linux/hal)
include_directories(${ONBOARDSDK_SOURCE}/../sample/platform/linux/hal/hotplug)
include_directories(${ONBOARDSDK_SOURCE}/../sample/platform/linux/osal)
include_directories(${ONBOARDSDK_SOURCE}/../sample/sore/inc)
include_directories(${ONBOARDSDK_SOURCE}/..sample/platform/linux/hal)
include_directories(${ONBOARDSDK_SOURCE}/..sample/platform/linux/hal/hotplug)
include_directories(${ONBOARDSDK_SOURCE}/..sample/platform/linux/osal)
include_directories(${ONBOARDSDK_SOURCE}/..sample/sore/inc)
include_directories(include /usr/local/include)
include_directories(include /usr/local/lib)

# Find OpenCV
find_package(OpenCV)
if (OpenCV_FOUND)
  message("\n${PROJECT_NAME}...")
  message(STATUS "Found OpenCV installed in the system, will use it to display image in AdvancedSensing APIs")
  message(STATUS " - Includes: ${OpenCV_INCLUDE_DIRS}")
  message(STATUS " - Libraries: ${OpenCV_LIBRARIES}")
  add_definitions(-DOPEN_CV_INSTALLED)
else()
  message( STATUS "Did not find OpenCV in the system, image data is inside RecvContainer as raw data")
endif ()

# Find LibUSB
set(CMAKE_MODULE_PATH ${CMAKE_MODULE_PATH} "${ORI_OSDK_CORE_SRC}/cmake-modules/")
find_package(LibUSB REQUIRED)
include_directories(${LIBUSB_1_INCLUDE_DIRS})
find_package(FFMPEG REQUIRED)
include_directories(${ADVANCED_SENSING_HEADERS_DIR})
include_directories(${CLOSED_SRC_DIR})

set(HELPER_FUNCTIONS_DIR "~/Projects/Onboard-SDK/sample/platform/linux")
include_directories(${HELPER_FUNCTIONS_DIR}/common)
FILE(GLOB SRC_FILES *.hpp *.cpp
  ${HELPER_FUNCTIONS_DIR}/common/dji_linux_environment.cpp
  ${HELPER_FUNCTIONS_DIR}/common/dji_linux_helpers.cpp
  ${HELPER_FUNCTIONS_DIR}/hal/osdkhal_linux.c
  ${HELPER_FUNCTIONS_DIR}/osal/osdkosal_linux.c
)

if (OSDK_HOTPLUG)
    FILE(GLOB SRC_FILES ${SRC_FILES} ${ONBOARDSDK_SOURCE}/../sample/platform/linux/hal/hotplug/*.c)
endif ()

# Finish up
add_executable(${PROJECT_NAME}
  ${SRC_FILES}
  ${HELPER_FUNCTIONS_DIR}/common/dji_linux_environment.cpp
  ${HELPER_FUNCTIONS_DIR}/common/dji_linux_helpers.cpp
  ~/Projects/drone_research_root/flight_algorithm/camera_access/camera_access.cpp
)

target_link_libraries(${PROJECT_NAME} PUBLIC ${FFMPEG_LIBRARIES} pthread)

FILE(GLOB ADVANCED_SENSING_HEADERS
    ${CMAKE_CURRENT_SOURCE_DIR}/api/inc/dji_advanced_sensing.hpp
    ${CMAKE_CURRENT_SOURCE_DIR}/api/inc/dji_liveview.hpp
    ${CMAKE_CURRENT_SOURCE_DIR}/api/inc/dji_perception.hpp
    ${CMAKE_CURRENT_SOURCE_DIR}/platform/inc/*.h*
    ${CMAKE_CURRENT_SOURCE_DIR}/protocol/inc/*.h*
    ${CMAKE_CURRENT_SOURCE_DIR}/camera_stream/src/dji_camera_image.hpp
    ${CMAKE_CURRENT_SOURCE_DIR}/camera_stream/src/dji_camera_stream.hpp
    ${ORI_OSDK_CORE_SRC}/protocol/inc/dji_aes.hpp
    ${ORI_OSDK_CORE_SRC}/protocol/inc/dji_protocol_base.hpp
    ${ORI_OSDK_CORE_SRC}/hal/inc/dji_hard_driver.hpp
    ${ORI_OSDK_CORE_SRC}/hal/inc/dji_memory.hpp
    ${ORI_OSDK_CORE_SRC}/hal/inc/dji_thread_manager.hpp
    ${ORI_OSDK_CORE_SRC}/platform/linux/inc/posix_thread_manager.hpp
)

FILE(GLOB CLOSED_SRC
        api/src/*.cpp
        protocol/src/*.cpp
        platform/src/*.cpp
        camera_stream/src/*.cpp
        camera_stream/udt/src/*.cpp
        ${CMAKE_CURRENT_SOURCE_DIR}/../v1/protocol/src/*.cpp
        ${CMAKE_CURRENT_SOURCE_DIR}/../v1/api/src/*.cpp
        ${ORI_OSDK_CORE_SRC}/protocol/src/*.cpp
        ${ORI_OSDK_CORE_SRC}/hal/src/*.cpp
        ${ORI_OSDK_CORE_SRC}/platform/linux/src/linux_serial_device.cpp
        ${ORI_OSDK_CORE_SRC}/platform/linux/src/posix_thread_manager.cpp
        ${ORI_OSDK_CORE_SRC}/platform/default/src/*.cpp
        ${ORI_OSDK_CORE_SRC}/utility/src/*.cpp
)

if (NOT TARGET camera_access)
  add_library(${PROJECT_NAME} STATIC ${CLOSED_SRC})
endif()

link_libraries(dji-linker)
link_directories(/usr/local/include /usr/local/lib)
link_libraries(${ONBOARDSDK_SOURCE}/linker/${ARCH}/lib/libdji-linker.a)

target_include_directories(${PROJECT_NAME} PRIVATE ${OpenCV_INCLUDE_DIRS})
target_include_directories(${PROJECT_NAME} PRIVATE ${CLOSED_SRC})

# Link libraries
if (OpenCV_FOUND)
  target_link_libraries(${PROJECT_NAME} PUBLIC
    ${OpenCV_LIBS}
    )
endif ()

target_link_libraries(${PROJECT_NAME} PUBLIC djiosdk-core)
target_link_libraries(${PROJECT_NAME} PUBLIC  dji-linker)
target_include_directories(${PROJECT_NAME} PUBLIC ${LIBUSB_1_INCLUDE_DIRS})
target_link_libraries(${PROJECT_NAME} PUBLIC ${LIBUSB_1_LIBRARIES})
target_link_libraries(${PROJECT_NAME} PUBLIC ${FFMPEG_LIBRARIES})
target_include_directories(${PROJECT_NAME} PUBLIC $<BUILD_INTERFACE:${ADVANCED_SENSING_HEADERS_DIR}>)
target_link_libraries(${PROJECT_NAME} PRIVATE advanced-sensing)
target_include_directories(${PROJECT_NAME} PUBLIC ${FFMPEG_INCLUDE_DIR})
target_link_libraries(${PROJECT_NAME} PUBLIC ${FFMPEG_LIBRARIES})
target_link_libraries(${PROJECT_NAME} PUBLIC ${ONBOARDSDK_SOURCE}/linker/${ARCH}/lib/libdji-linker.a)

This is the error I get after the cmake --build call

[ 25%] Linking CXX executable camera_access
CMakeFiles/camera_access.dir/home/caroline/Projects/Onboard-SDK/sample/platform/linux/common/dji_linux_helpers.cpp.o:(.data.rel+0x0): undefined reference to `OsdkLinux_UartInit'
CMakeFiles/camera_access.dir/home/caroline/Projects/Onboard-SDK/sample/platform/linux/common/dji_linux_helpers.cpp.o:(.data.rel+0x8): undefined reference to `OsdkLinux_UartSendData'
CMakeFiles/camera_access.dir/home/caroline/Projects/Onboard-SDK/sample/platform/linux/common/dji_linux_helpers.cpp.o:(.data.rel+0x10): undefined reference to `OsdkLinux_UartReadData'
CMakeFiles/camera_access.dir/home/caroline/Projects/Onboard-SDK/sample/platform/linux/common/dji_linux_helpers.cpp.o:(.data.rel+0x18): undefined reference to `OsdkLinux_UartClose'
CMakeFiles/camera_access.dir/home/caroline/Projects/Onboard-SDK/sample/platform/linux/common/dji_linux_helpers.cpp.o:(.data.rel+0x20): undefined reference to `OsdkLinux_USBBulkInit'
CMakeFiles/camera_access.dir/home/caroline/Projects/Onboard-SDK/sample/platform/linux/common/dji_linux_helpers.cpp.o:(.data.rel+0x28): undefined reference to `OsdkLinux_USBBulkSendData'
CMakeFiles/camera_access.dir/home/caroline/Projects/Onboard-SDK/sample/platform/linux/common/dji_linux_helpers.cpp.o:(.data.rel+0x30): undefined reference to `OsdkLinux_USBBulkReadData'
CMakeFiles/camera_access.dir/home/caroline/Projects/Onboard-SDK/sample/platform/linux/common/dji_linux_helpers.cpp.o:(.data.rel+0x38): undefined reference to `OsdkLinux_USBBulkClose'
CMakeFiles/camera_access.dir/home/caroline/Projects/Onboard-SDK/sample/platform/linux/common/dji_linux_helpers.cpp.o:(.data.rel+0x40): undefined reference to `OsdkLinux_TaskCreate'
CMakeFiles/camera_access.dir/home/caroline/Projects/Onboard-SDK/sample/platform/linux/common/dji_linux_helpers.cpp.o:(.data.rel+0x48): undefined reference to `OsdkLinux_TaskDestroy'
CMakeFiles/camera_access.dir/home/caroline/Projects/Onboard-SDK/sample/platform/linux/common/dji_linux_helpers.cpp.o:(.data.rel+0x50): undefined reference to `OsdkLinux_TaskSleepMs'
CMakeFiles/camera_access.dir/home/caroline/Projects/Onboard-SDK/sample/platform/linux/common/dji_linux_helpers.cpp.o:(.data.rel+0x58): undefined reference to `OsdkLinux_MutexCreate'
CMakeFiles/camera_access.dir/home/caroline/Projects/Onboard-SDK/sample/platform/linux/common/dji_linux_helpers.cpp.o:(.data.rel+0x60): undefined reference to `OsdkLinux_MutexDestroy'
CMakeFiles/camera_access.dir/home/caroline/Projects/Onboard-SDK/sample/platform/linux/common/dji_linux_helpers.cpp.o:(.data.rel+0x68): undefined reference to `OsdkLinux_MutexLock'
CMakeFiles/camera_access.dir/home/caroline/Projects/Onboard-SDK/sample/platform/linux/common/dji_linux_helpers.cpp.o:(.data.rel+0x70): undefined reference to `OsdkLinux_MutexUnlock'
CMakeFiles/camera_access.dir/home/caroline/Projects/Onboard-SDK/sample/platform/linux/common/dji_linux_helpers.cpp.o:(.data.rel+0x78): undefined reference to `OsdkLinux_SemaphoreCreate'
CMakeFiles/camera_access.dir/home/caroline/Projects/Onboard-SDK/sample/platform/linux/common/dji_linux_helpers.cpp.o:(.data.rel+0x80): undefined reference to `OsdkLinux_SemaphoreDestroy'
CMakeFiles/camera_access.dir/home/caroline/Projects/Onboard-SDK/sample/platform/linux/common/dji_linux_helpers.cpp.o:(.data.rel+0x88): undefined reference to `OsdkLinux_SemaphoreWait'
CMakeFiles/camera_access.dir/home/caroline/Projects/Onboard-SDK/sample/platform/linux/common/dji_linux_helpers.cpp.o:(.data.rel+0x90): undefined reference to `OsdkLinux_SemaphoreTimedWait'
CMakeFiles/camera_access.dir/home/caroline/Projects/Onboard-SDK/sample/platform/linux/common/dji_linux_helpers.cpp.o:(.data.rel+0x98): undefined reference to `OsdkLinux_SemaphorePost'
CMakeFiles/camera_access.dir/home/caroline/Projects/Onboard-SDK/sample/platform/linux/common/dji_linux_helpers.cpp.o:(.data.rel+0xa0): undefined reference to `OsdkLinux_GetTimeMs'
CMakeFiles/camera_access.dir/home/caroline/Projects/Onboard-SDK/sample/platform/linux/common/dji_linux_helpers.cpp.o:(.data.rel+0xa8): undefined reference to `OsdkLinux_Malloc'
CMakeFiles/camera_access.dir/home/caroline/Projects/Onboard-SDK/sample/platform/linux/common/dji_linux_helpers.cpp.o:(.data.rel+0xb0): undefined reference to `OsdkLinux_Free'
collect2: error: ld returned 1 exit status
CMakeFiles/camera_access.dir/build.make:189: recipe for target 'camera_access' failed
make[2]: *** [camera_access] Error 1
CMakeFiles/Makefile2:67: recipe for target 'CMakeFiles/camera_access.dir/all' failed
make[1]: *** [CMakeFiles/camera_access.dir/all] Error 2
Makefile:83: recipe for target 'all' failed
make: *** [all] Error 2

As you can see in my CMake file, I am already importing both hal/osdkhal_linux.c and osal/osdkosal_linux.c. I would also love to remove anything unnecessary from the rather large CMake file.

Thank you.

@dji-dev
Copy link
Contributor

dji-dev commented Dec 3, 2021

Agent comment from DJI SDK in Zendesk ticket #57351:

尊敬的开发者,感谢您联系DJI 大疆创新
由于github不是我们主要的咨询渠道,您的问题可能跟进不及时。我们建议您通过填写表单( https://djisdksupport.zendesk.com/hc/zh-cn/requests/new )向我们反馈问题。或者您也可以在论坛发帖,与其它开发者交流。论坛链接:https://djisdksupport.zendesk.com/hc/zh-cn/community/topics

Dear developer, thank you for contacting DJI.
Since github is not our main consultation channel, your questions may not be followed up in time. We recommend that you fill in the form (https://djisdksupport.zendesk.com/hc/en-us/requests/new) to report problems to us. Or you can post in the forum to communicate with other developers. Forum link: https://djisdksupport.zendesk.com/hc/zh-cn/community/topics

°°°

@dji-dev
Copy link
Contributor

dji-dev commented Dec 6, 2021

Agent comment from kyle.cai in Zendesk ticket #57351:

This issue seems same as the github issue, which maybe give you some referrcence.
#770

°°°

@Caseiber
Copy link
Author

Caseiber commented Dec 6, 2021

Thank you for your reply. I am aware of that post and had gone through it to try and solve my issue. However, that person’s problem was resolved by importing these files, specifically the last two:

FILE(GLOB SOURCE_FILES *.hpp *.cpp
         ${CMAKE_CURRENT_SOURCE_DIR}/../common/dji_linux_environment.cpp
         ${CMAKE_CURRENT_SOURCE_DIR}/../common/dji_linux_helpers.cpp
         ${CMAKE_CURRENT_SOURCE_DIR}/../hal/osdkhal_linux.c
         ${CMAKE_CURRENT_SOURCE_DIR}/../osal/osdkosal_linux.c

         )

I am already importing these files and still having the same issue.

Thank you

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

No branches or pull requests

2 participants