I would like to compile my own project. I have error with **make**
. cmake ..
works properly.
I tried to compile the example in /Onboard-SDK/sample/platform/telemetry. I did mkdir build and cd build in telemetry directory.
This is my CMakeList.txt
cmake_minimum_required(VERSION 2.8)
project(djiosdk-telemetry-sample)
# Compiler flags: link with pthread and enable C++11 support
set(CMAKE_CXX_FLAGS "${CMAKE_CXX_FLAGS} -std=c++11 -pthread -g -O0")
# Tell the project where osdk-core is located
if(NOT ONBOARDSDK_SOURCE)
set(ONBOARDSDK_SOURCE "/home/pi/Onboard-SDK/osdk-core")
#set(ONBOARDSDK_SOURCE "/usr/local/include")
endif()
# Specify locations for osdk-core headers
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(${CMAKE_CURRENT_SOURCE_DIR}/../hal)
include_directories(${CMAKE_CURRENT_SOURCE_DIR}/../osal)
include_directories(include /usr/local/include)
include_directories(${ONBOARDSDK_SOURCE}/../sample/core/inc)
# User-code related project files
include_directories(${CMAKE_CURRENT_SOURCE_DIR}/../common)
FILE(GLOB SOURCE_FILES *.hpp *.cpp
${CMAKE_CURRENT_SOURCE_DIR}/../common/dji_linux_environment.cpp
${CMAKE_CURRENT_SOURCE_DIR}/../common/dji_linux_helpers.cpp
main.cpp
telemetry_sample.cpp
)
if (OSDK_HOTPLUG)
FILE(GLOB SOURCE_FILES ${SOURCE_FILES} ${CMAKE_CURRENT_SOURCE_DIR}/../hal/hotplug/*.c)
endif ()
# Target and linking
add_executable(${PROJECT_NAME} ${SOURCE_FILES})
target_link_libraries(${PROJECT_NAME} djiosdk-core)
This is the result after make
[ 20%] Linking CXX executable djiosdk-telemetry-sample
/usr/bin/ld: //usr/local/lib/libdjiosdk-core.a(dji_legacy_linker.cpp.o): in function `DJI::OSDK::LegacyLinker::legacyX5SEnableTask(void*)':
/home/pi/Onboard-SDK/osdk-core/api/src/dji_legacy_linker.cpp:69: **undefined reference to `DJI::OSDK**::Linker::getLocalSenderId()'
/usr/bin/ld: /home/pi/Onboard-SDK/osdk-core/api/src/dji_legacy_linker.cpp:71: **undefined reference** to `OsdkOsal_TaskSleepMs'
/usr/bin/ld: /home/pi/Onboard-SDK/osdk-core/api/src/dji_legacy_linker.cpp:72: **undefined reference** to `**DJI::OSDK**::Linker::isUSBPlugged()'
collect2: error: ld returned 1 exit status
make[2]: *** [CMakeFiles/djiosdk-telemetry-sample.dir/build.make:129: djiosdk-telemetry-sample] Error 1
make[1]: *** [CMakeFiles/Makefile2:76: CMakeFiles/djiosdk-telemetry-sample.dir/all] Error 2
make: *** [Makefile:84: all] Error 2
I often have [100%] Linking CXX executable djiosdk-telemetry-sample
.
The main problem is with "undefined reference".
I create CMakeList.txt according to: https://developer.dji.com/onboard-sdk/documentation/development-workflow/integrate-sdk.html
What I should do?
The proper CMakeList.txt for creating your own project (example based on telemetry sample):
cmake_minimum_required(VERSION 2.8)
project(djiosdk-telemetry-sample)
set(ARCH armv7)
# Compiler flags: link with pthread and enable C++11 support
set(CMAKE_CXX_FLAGS "${CMAKE_CXX_FLAGS} -std=c++11 -pthread -g -O0")
# Tell the project where osdk-core is located
if(NOT ONBOARDSDK_SOURCE)
set(ONBOARDSDK_SOURCE "/home/pi/Onboard-SDK/osdk-core")
endif()
set(CURRENT_CMAKE_MODULE_PATH ${ONBOARDSDK_SOURCE}/cmake-modules)
# Specify locations for osdk-core headers
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}/linker/${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(include /usr/local/include)
include_directories(include /usr/local/lib)
include_directories(${ONBOARDSDK_SOURCE}/../sample/core/inc)
# User-code related project files
include_directories(${ONBOARDSDK_SOURCE}/../sample/platform/linux/common)
FILE(GLOB SOURCE_FILES *.hpp *.cpp
${ONBOARDSDK_SOURCE}/../sample/platform/linux/common/dji_linux_environment.cpp
${ONBOARDSDK_SOURCE}/../sample/platform/linux/common/dji_linux_helpers.cpp
${ONBOARDSDK_SOURCE}/../sample/platform/linux/hal/osdkhal_linux.c
${ONBOARDSDK_SOURCE}/../sample/platform/linux/osal/osdkosal_linux.c
)
if (OSDK_HOTPLUG)
FILE(GLOB SOURCE_FILES ${SOURCE_FILES} ${ONBOARDSDK_SOURCE}/../sample/platform/linux/hal/hotplug/*.c)
endif ()
link_libraries(dji-linker)
link_directories(/usr/local/include /usr/local/lib)
link_libraries(${ONBOARDSDK_SOURCE}/linker/${ARCH}/lib/libdji-linker.a)
set(CMAKE_MODULE_PATH ${CURRENT_CMAKE_MODULE_PATH})
find_package(LibUSB REQUIRED)
find_package(FFMPEG REQUIRED)
include_directories(${ADVANCED_SENSING_HEADERS_DIR})
# Target and linking
add_executable(${PROJECT_NAME} ${SOURCE_FILES})
target_link_libraries(${PROJECT_NAME} PUBLIC djiosdk-core)
target_link_libraries(${PROJECT_NAME} PUBLIC dji-linker)
target_link_libraries(${PROJECT_NAME} PUBLIC ${ONBOARDSDK_SOURCE}/linker/${ARCH}/lib/libdji-linker.a)
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})