Forums - snpe_sample application makefile to cmake

4 posts / 0 new
Last post
snpe_sample application makefile to cmake
22imonreal
Join Date: 10 Feb 21
Posts: 80
Posted: Thu, 2021-07-08 07:57

Hello,

What would the Makefile.x86_64-linux-clang Makefile look like when implemented in CMake as a CMakeLists.txt file?

For reference, this is the Makefile:


# Copyright (c) 2017-2020 Qualcomm Technologies, Inc.
# All Rights Reserved.
# Confidential and Proprietary - Qualcomm Technologies, Inc.

# Specify the compiler flags
#CXX ?= g++

CXXFLAGS += -std=c++11 -fPIC -march=x86-64


# Include paths
INCLUDES += -I $(SNPE_ROOT)/include/zdl

# Specify the paths to the libraries
LDFLAGS  += -L $(SNPE_ROOT)/lib/x86_64-linux-clang


# Specify the link libraries
LLIBS    += -lSNPE


# Specify the target
PROGRAM  := snpe-sample
SRC_DIR  := jni
OBJ_DIR  := obj/local/x86_64-linux-clang

# Specify the source list and the object directories.
# The source file is in the 'jni' directory to be compatible with the
# Android NDK structure.
# Get the list of source files including the directory
SRC      := $(wildcard $(SRC_DIR)/*.cpp)
# Generate the output names by substituting the object dir for the source dir
OBJS     := $(subst $(SRC_DIR),$(OBJ_DIR),$(subst .cpp,.o,$(SRC)))

default: all
all: $(OBJ_DIR)/$(PROGRAM)

$(OBJ_DIR)/%.o: $(SRC_DIR)/%.cpp $(OBJ_DIR)
    $(CXX) -c $(CXXFLAGS) $(INCLUDES) $< -o $@

$(OBJ_DIR)/$(PROGRAM): $(OBJS)
    $(CXX) $(LDFLAGS) $^ $(LLIBS) -o $@

clean:
    -rm -f $(OBJS) $(PROGRAM).o
    -rm -f $(PROGRAM)

$(OBJ_DIR):
    mkdir -p $(OBJ_DIR)

.PHONY: default clean

Thanks in advance.

  • Up0
  • Down0
kevin.dai
Join Date: 21 Oct 20
Posts: 137
Posted: Thu, 2021-07-08 11:30

This is cmake to generate Makefile? Have you genearted makefile correctly?

 

  • Up0
  • Down0
22imonreal
Join Date: 10 Feb 21
Posts: 80
Posted: Fri, 2021-07-09 01:06

Hello, the above is the Makefile provided in snpe-1.50.0.2622/examples/NativeCpp/SampleCode.

I want to compile the main.cpp and neccessary libraries in my own CMake project, so I wanted to translate the Makefile into a CMakeLists.txt usinf find_library(), target_link_libraries(), include_directories() and the sort, but I can't get it to build because I get undefined reference to:

/usr/bin/ld: CMakeFiles/osd_snpe_infer.dir/main.cpp.o: in function `infer()':
main.cpp:(.text+0x211): undefined reference to `zdl::DlSystem::RuntimeList::RuntimeList()'
/usr/bin/ld: main.cpp:(.text+0x232): undefined reference to `zdl::DlSystem::RuntimeList::~RuntimeList()'
/usr/bin/ld: main.cpp:(.text+0x299): undefined reference to `UdlExample::MyUDLFactory(void*, zdl::DlSystem::UDLContext const*)'
/usr/bin/ld: main.cpp:(.text+0x30b): undefined reference to `loadContainerFromFile(std::__cxx11::basic_string<char, std::char_traits<char>, std::allocator<char> >)'
/usr/bin/ld: main.cpp:(.text+0x38b): undefined reference to `zdl::DlSystem::RuntimeList::RuntimeList(zdl::DlSystem::RuntimeList const&)'
/usr/bin/ld: main.cpp:(.text+0x3c1): undefined reference to `setBuilderOptions(std::unique_ptr<zdl::DlContainer::IDlContainer, std::default_delete<zdl::DlContainer::IDlContainer> >&, zdl::DlSystem::Runtime_t, zdl::DlSystem::RuntimeList, zdl::DlSystem::UDLBundle, bool, zdl::DlSystem::PlatformConfig, bool)'
/usr/bin/ld: main.cpp:(.text+0x3fc): undefined reference to `zdl::DlSystem::RuntimeList::~RuntimeList()'
/usr/bin/ld: main.cpp:(.text+0x4c2): undefined reference to `zdl::SNPE::SNPE::getDiagLogInterface()'
/usr/bin/ld: main.cpp:(.text+0x5b7): undefined reference to `zdl::DlSystem::TensorShape::TensorShape()'
/usr/bin/ld: main.cpp:(.text+0x5db): undefined reference to `zdl::SNPE::SNPE::getInputDimensions() const'
/usr/bin/ld: main.cpp:(.text+0x5ff): undefined reference to `zdl::DlSystem::TensorShape::operator=(zdl::DlSystem::TensorShape const&)'
/usr/bin/ld: main.cpp:(.text+0x61d): undefined reference to `zdl::DlSystem::TensorShape::getDimensions() const'
/usr/bin/ld: main.cpp:(.text+0x6a4): undefined reference to `preprocessInput[abi:cxx11](char const*, unsigned long)'
/usr/bin/ld: main.cpp:(.text+0x6c0): undefined reference to `zdl::DlSystem::UserBufferMap::UserBufferMap()'
/usr/bin/ld: main.cpp:(.text+0x6cf): undefined reference to `zdl::DlSystem::UserBufferMap::UserBufferMap()'
/usr/bin/ld: main.cpp:(.text+0x745): undefined reference to `createOutputBufferMap(zdl::DlSystem::UserBufferMap&, std::unordered_map<std::__cxx11::basic_string<char, std::char_traits<char>, std::allocator<char> >, std::vector<unsigned char, std::allocator<unsigned char> >, std::hash<std::__cxx11::basic_string<char, std::char_traits<char>, std::allocator<char> > >, std::equal_to<std::__cxx11::basic_string<char, std::char_traits<char>, std::allocator<char> > >, std::allocator<std::pair<std::__cxx11::basic_string<char, std::char_traits<char>, std::allocator<char> > const, std::vector<unsigned char, std::allocator<unsigned char> > > > >&, std::vector<std::unique_ptr<zdl::DlSystem::IUserBuffer, std::default_delete<zdl::DlSystem::IUserBuffer> >, std::allocator<std::unique_ptr<zdl::DlSystem::IUserBuffer, std::default_delete<zdl::DlSystem::IUserBuffer> > > >&, std::unique_ptr<zdl::SNPE::SNPE, std::default_delete<zdl::SNPE::SNPE> >&, bool, int)'
/usr/bin/ld: main.cpp:(.text+0x787): undefined reference to `createInputBufferMap(zdl::DlSystem::UserBufferMap&, std::unordered_map<std::__cxx11::basic_string<char, std::char_traits<char>, std::allocator<char> >, std::vector<unsigned char, std::allocator<unsigned char> >, std::hash<std::__cxx11::basic_string<char, std::char_traits<char>, std::allocator<char> > >, std::equal_to<std::__cxx11::basic_string<char, std::char_traits<char>, std::allocator<char> > >, std::allocator<std::pair<std::__cxx11::basic_string<char, std::char_traits<char>, std::allocator<char> > const, std::vector<unsigned char, std::allocator<unsigned char> > > > >&, std::vector<std::unique_ptr<zdl::DlSystem::IUserBuffer, std::default_delete<zdl::DlSystem::IUserBuffer> >, std::allocator<std::unique_ptr<zdl::DlSystem::IUserBuffer, std::default_delete<zdl::DlSystem::IUserBuffer> > > >&, std::unique_ptr<zdl::SNPE::SNPE, std::default_delete<zdl::SNPE::SNPE> >&, bool, int)'
/usr/bin/ld: main.cpp:(.text+0x834): undefined reference to `zdl::SNPE::SNPE::execute(zdl::DlSystem::UserBufferMap const&, zdl::DlSystem::UserBufferMap const&)'
/usr/bin/ld: main.cpp:(.text+0x8cf): undefined reference to `createOutputBufferMap(zdl::DlSystem::UserBufferMap&, std::unordered_map<std::__cxx11::basic_string<char, std::char_traits<char>, std::allocator<char> >, std::vector<unsigned char, std::allocator<unsigned char> >, std::hash<std::__cxx11::basic_string<char, std::char_traits<char>, std::allocator<char> > >, std::equal_to<std::__cxx11::basic_string<char, std::char_traits<char>, std::allocator<char> > >, std::allocator<std::pair<std::__cxx11::basic_string<char, std::char_traits<char>, std::allocator<char> > const, std::vector<unsigned char, std::allocator<unsigned char> > > > >&, std::vector<std::unique_ptr<zdl::DlSystem::IUserBuffer, std::default_delete<zdl::DlSystem::IUserBuffer> >, std::allocator<std::unique_ptr<zdl::DlSystem::IUserBuffer, std::default_delete<zdl::DlSystem::IUserBuffer> > > >&, std::unique_ptr<zdl::SNPE::SNPE, std::default_delete<zdl::SNPE::SNPE> >&, bool, int)'
/usr/bin/ld: main.cpp:(.text+0x91e): undefined reference to `createInputBufferMap(zdl::DlSystem::UserBufferMap&, std::unordered_map<std::__cxx11::basic_string<char, std::char_traits<char>, std::allocator<char> >, std::vector<unsigned char, std::allocator<unsigned char> >, std::hash<std::__cxx11::basic_string<char, std::char_traits<char>, std::allocator<char> > >, std::equal_to<std::__cxx11::basic_string<char, std::char_traits<char>, std::allocator<char> > >, std::allocator<std::pair<std::__cxx11::basic_string<char, std::char_traits<char>, std::allocator<char> > const, std::vector<unsigned char, std::allocator<unsigned char> > > > >&, std::vector<std::unique_ptr<zdl::DlSystem::IUserBuffer, std::default_delete<zdl::DlSystem::IUserBuffer> >, std::allocator<std::unique_ptr<zdl::DlSystem::IUserBuffer, std::default_delete<zdl::DlSystem::IUserBuffer> > > >&, std::unique_ptr<zdl::SNPE::SNPE, std::default_delete<zdl::SNPE::SNPE> >&, bool, int)'
/usr/bin/ld: main.cpp:(.text+0x9cb): undefined reference to `zdl::SNPE::SNPE::execute(zdl::DlSystem::UserBufferMap const&, zdl::DlSystem::UserBufferMap const&)'
/usr/bin/ld: main.cpp:(.text+0xa5d): undefined reference to `zdl::DlSystem::UserBufferMap::~UserBufferMap()'
/usr/bin/ld: main.cpp:(.text+0xa6c): undefined reference to `zdl::DlSystem::UserBufferMap::~UserBufferMap()'
/usr/bin/ld: main.cpp:(.text+0xa8d): undefined reference to `zdl::DlSystem::TensorMap::TensorMap()'
/usr/bin/ld: main.cpp:(.text+0xb44): undefined reference to `loadInputTensor(std::unique_ptr<zdl::SNPE::SNPE, std::default_delete<zdl::SNPE::SNPE> >&, std::vector<std::__cxx11::basic_string<char, std::char_traits<char>, std::allocator<char> >, std::allocator<std::__cxx11::basic_string<char, std::char_traits<char>, std::allocator<char> > > >&)'
/usr/bin/ld: main.cpp:(.text+0xb7d): undefined reference to `zdl::SNPE::SNPE::execute(zdl::DlSystem::ITensor const*, zdl::DlSystem::TensorMap&)'
/usr/bin/ld: main.cpp:(.text+0xbe2): undefined reference to `zdl::DlSystem::TensorMap::~TensorMap()'
/usr/bin/ld: main.cpp:(.text+0xd02): undefined reference to `zdl::DlSystem::TensorShape::~TensorShape()'
/usr/bin/ld: main.cpp:(.text+0xeb2): undefined reference to `zdl::DlSystem::RuntimeList::~RuntimeList()'
/usr/bin/ld: main.cpp:(.text+0xf8c): undefined reference to `zdl::DlSystem::UserBufferMap::~UserBufferMap()'
/usr/bin/ld: main.cpp:(.text+0xfa4): undefined reference to `zdl::DlSystem::UserBufferMap::~UserBufferMap()'
/usr/bin/ld: main.cpp:(.text+0xfd4): undefined reference to `zdl::DlSystem::TensorMap::~TensorMap()'
/usr/bin/ld: main.cpp:(.text+0x1004): undefined reference to `zdl::DlSystem::TensorShape::~TensorShape()'
/usr/bin/ld: CMakeFiles/osd_snpe_infer.dir/main.cpp.o: in function `zdl::DlSystem::Optional<zdl::DlSystem::TensorShape>::~Optional()':
main.cpp:(.text._ZN3zdl8DlSystem8OptionalINS0_11TensorShapeEED2Ev[_ZN3zdl8DlSystem8OptionalINS0_11TensorShapeEED5Ev]+0x76): undefined reference to `zdl::DlSystem::TensorShape::~TensorShape()'
/usr/bin/ld: CMakeFiles/osd_snpe_infer.dir/main.cpp.o: in function `std::default_delete<zdl::SNPE::SNPE>::operator()(zdl::SNPE::SNPE*) const':
main.cpp:(.text._ZNKSt14default_deleteIN3zdl4SNPE4SNPEEEclEPS2_[_ZNKSt14default_deleteIN3zdl4SNPE4SNPEEEclEPS2_]+0x22): undefined reference to `zdl::SNPE::SNPE::~SNPE()'
collect2: error: ld returned 1 exit status
make[2]: *** [src/CMakeFiles/osd_snpe_infer.dir/build.make:152: src/osd_snpe_infer] Error 1
make[1]: *** [CMakeFiles/Makefile2:199: src/CMakeFiles/osd_snpe_infer.dir/all] Error 2
make: *** [Makefile:91: all] Error 2

How would a suitable CMakeLists.txt look like to include all necesary libraries into the project?

  • Up0
  • Down0
22imonreal
Join Date: 10 Feb 21
Posts: 80
Posted: Fri, 2021-07-09 02:14

Using:

find_library(LIBHTPPREPARE
    NAMES libHtpPrepare.so
    PATHS "/snpe-1.50.0.2622/lib/x86_64-linux-clang"
)

find_library(LIBOMP
    NAMES libomp.so
    PATHS "/snpe-1.50.0.2622/lib/x86_64-linux-clang"
)

find_library(LIBSNPE
    NAMES libSNPE.so
    PATHS "/snpe-1.50.0.2622/lib/x86_64-linux-clang"
)

target_link_libraries(osd_snpe_infer PRIVATE inferer cameraGrabber ${OpenCV_LIBS} ${LIBHTPPREPARE} ${LIBOMP} ${LIBSNPE})

I get the following:

Consolidate compiler generated dependencies of target cameraGrabber
[ 10%] Built target cameraGrabber
Consolidate compiler generated dependencies of target inferer
[ 21%] Built target inferer
Consolidate compiler generated dependencies of target snpe
[ 89%] Built target snpe
Consolidate compiler generated dependencies of target osd_snpe_infer
[ 94%] Linking CXX executable osd_snpe_infer
/usr/bin/ld: /home/inigo/dev/external/rb5/snpe-1.50.0.2622/lib/x86_64-linux-clang/libomp.so: .dynsym local symbol at index 76 (>= sh_info of 1)
/usr/bin/ld: CMakeFiles/osd_snpe_infer.dir/main.cpp.o: in function `infer()':
main.cpp:(.text+0x299): undefined reference to `UdlExample::MyUDLFactory(void*, zdl::DlSystem::UDLContext const*)'
/usr/bin/ld: main.cpp:(.text+0x30b): undefined reference to `loadContainerFromFile(std::__cxx11::basic_string<char, std::char_traits<char>, std::allocator<char> >)'
/usr/bin/ld: main.cpp:(.text+0x3c1): undefined reference to `setBuilderOptions(std::unique_ptr<zdl::DlContainer::IDlContainer, std::default_delete<zdl::DlContainer::IDlContainer> >&, zdl::DlSystem::Runtime_t, zdl::DlSystem::RuntimeList, zdl::DlSystem::UDLBundle, bool, zdl::DlSystem::PlatformConfig, bool)'
/usr/bin/ld: main.cpp:(.text+0x6a4): undefined reference to `preprocessInput[abi:cxx11](char const*, unsigned long)'
/usr/bin/ld: main.cpp:(.text+0x745): undefined reference to `createOutputBufferMap(zdl::DlSystem::UserBufferMap&, std::unordered_map<std::__cxx11::basic_string<char, std::char_traits<char>, std::allocator<char> >, std::vector<unsigned char, std::allocator<unsigned char> >, std::hash<std::__cxx11::basic_string<char, std::char_traits<char>, std::allocator<char> > >, std::equal_to<std::__cxx11::basic_string<char, std::char_traits<char>, std::allocator<char> > >, std::allocator<std::pair<std::__cxx11::basic_string<char, std::char_traits<char>, std::allocator<char> > const, std::vector<unsigned char, std::allocator<unsigned char> > > > >&, std::vector<std::unique_ptr<zdl::DlSystem::IUserBuffer, std::default_delete<zdl::DlSystem::IUserBuffer> >, std::allocator<std::unique_ptr<zdl::DlSystem::IUserBuffer, std::default_delete<zdl::DlSystem::IUserBuffer> > > >&, std::unique_ptr<zdl::SNPE::SNPE, std::default_delete<zdl::SNPE::SNPE> >&, bool, int)'
/usr/bin/ld: main.cpp:(.text+0x787): undefined reference to `createInputBufferMap(zdl::DlSystem::UserBufferMap&, std::unordered_map<std::__cxx11::basic_string<char, std::char_traits<char>, std::allocator<char> >, std::vector<unsigned char, std::allocator<unsigned char> >, std::hash<std::__cxx11::basic_string<char, std::char_traits<char>, std::allocator<char> > >, std::equal_to<std::__cxx11::basic_string<char, std::char_traits<char>, std::allocator<char> > >, std::allocator<std::pair<std::__cxx11::basic_string<char, std::char_traits<char>, std::allocator<char> > const, std::vector<unsigned char, std::allocator<unsigned char> > > > >&, std::vector<std::unique_ptr<zdl::DlSystem::IUserBuffer, std::default_delete<zdl::DlSystem::IUserBuffer> >, std::allocator<std::unique_ptr<zdl::DlSystem::IUserBuffer, std::default_delete<zdl::DlSystem::IUserBuffer> > > >&, std::unique_ptr<zdl::SNPE::SNPE, std::default_delete<zdl::SNPE::SNPE> >&, bool, int)'
/usr/bin/ld: main.cpp:(.text+0x8cf): undefined reference to `createOutputBufferMap(zdl::DlSystem::UserBufferMap&, std::unordered_map<std::__cxx11::basic_string<char, std::char_traits<char>, std::allocator<char> >, std::vector<unsigned char, std::allocator<unsigned char> >, std::hash<std::__cxx11::basic_string<char, std::char_traits<char>, std::allocator<char> > >, std::equal_to<std::__cxx11::basic_string<char, std::char_traits<char>, std::allocator<char> > >, std::allocator<std::pair<std::__cxx11::basic_string<char, std::char_traits<char>, std::allocator<char> > const, std::vector<unsigned char, std::allocator<unsigned char> > > > >&, std::vector<std::unique_ptr<zdl::DlSystem::IUserBuffer, std::default_delete<zdl::DlSystem::IUserBuffer> >, std::allocator<std::unique_ptr<zdl::DlSystem::IUserBuffer, std::default_delete<zdl::DlSystem::IUserBuffer> > > >&, std::unique_ptr<zdl::SNPE::SNPE, std::default_delete<zdl::SNPE::SNPE> >&, bool, int)'
/usr/bin/ld: main.cpp:(.text+0x91e): undefined reference to `createInputBufferMap(zdl::DlSystem::UserBufferMap&, std::unordered_map<std::__cxx11::basic_string<char, std::char_traits<char>, std::allocator<char> >, std::vector<unsigned char, std::allocator<unsigned char> >, std::hash<std::__cxx11::basic_string<char, std::char_traits<char>, std::allocator<char> > >, std::equal_to<std::__cxx11::basic_string<char, std::char_traits<char>, std::allocator<char> > >, std::allocator<std::pair<std::__cxx11::basic_string<char, std::char_traits<char>, std::allocator<char> > const, std::vector<unsigned char, std::allocator<unsigned char> > > > >&, std::vector<std::unique_ptr<zdl::DlSystem::IUserBuffer, std::default_delete<zdl::DlSystem::IUserBuffer> >, std::allocator<std::unique_ptr<zdl::DlSystem::IUserBuffer, std::default_delete<zdl::DlSystem::IUserBuffer> > > >&, std::unique_ptr<zdl::SNPE::SNPE, std::default_delete<zdl::SNPE::SNPE> >&, bool, int)'
/usr/bin/ld: main.cpp:(.text+0xb44): undefined reference to `loadInputTensor(std::unique_ptr<zdl::SNPE::SNPE, std::default_delete<zdl::SNPE::SNPE> >&, std::vector<std::__cxx11::basic_string<char, std::char_traits<char>, std::allocator<char> >, std::allocator<std::__cxx11::basic_string<char, std::char_traits<char>, std::allocator<char> > > >&)'
collect2: error: ld returned 1 exit status
make[2]: *** [src/CMakeFiles/osd_snpe_infer.dir/build.make:155: src/osd_snpe_infer] Error 1
make[1]: *** [CMakeFiles/Makefile2:199: src/CMakeFiles/osd_snpe_infer.dir/all] Error 2
make: *** [Makefile:91: all] Error 2

 

  • Up0
  • Down0
or Register

Opinions expressed in the content posted here are the personal opinions of the original authors, and do not necessarily reflect those of Qualcomm Incorporated or its subsidiaries (“Qualcomm”). The content is provided for informational purposes only and is not meant to be an endorsement or representation by Qualcomm or any other party. This site may also provide links or references to non-Qualcomm sites and resources. Qualcomm makes no representations, warranties, or other commitments whatsoever about any non-Qualcomm sites or third-party resources that may be referenced, accessible from, or linked to this site.