trying to play around with odas library, using following CMakeLists.txt file to crosscompile for Raspberry PI platform:
make_minimum_required(VERSION 3.10)
# Set some basic project attributes
project (Audio_Sweep_Cross_CMake_04
VERSION 0.1
DESCRIPTION "Audio Sweep Project")
# Referencing ODAS here
include (CMakeListsOdas.cmake)
#Add base directory for includes (global)
include_directories(include)
set (SRC src)
# This project will output an executable file
add_executable(${PROJECT_NAME} ${SRC}/main.cpp )
# Include the configuration header in the build
SET(GCC_COVERAGE_LINK_FLAGS "-lm -lpthread " )
set(ENV{PKG_CONFIG_PATH} "/sysroot/usr/lib/aarch64-linux-gnu/pkgconfig")
find_package(PkgConfig REQUIRED)
pkg_check_modules(PC_ALSA REQUIRED alsa)
pkg_check_modules(PC_FFTW3 REQUIRED fftw3f)
pkg_check_modules(PC_LIBCONFIG REQUIRED libconfig)
pkg_check_modules(PC_PULSEAUDIO REQUIRED libpulse-simple)
target_link_libraries(${PROJECT_NAME}
odas
${PC_FFTW3_LIBRARIES}
${PC_ALSA_LIBRARIES}
${PC_LIBCONFIG_LIBRARIES}
${PC_PULSEAUDIO_LIBRARIES}
# m
# pthread
)
SET(CMAKE_CXX_FLAGS "${CMAKE_CXX_FLAGS} ${GCC_COVERAGE_COMPILE_FLAGS}")
SET(CMAKE_EXE_LINKER_FLAGS "${CMAKE_EXE_LINKER_FLAGS} ${GCC_COVERAGE_LINK_FLAGS}")
This one compiles no problem.
However, if I comment out
# SET(GCC_COVERAGE_LINK_FLAGS "-lm -lpthread " )
and un-comment m and pthread in
target_link_libraries(${PROJECT_NAME}
odas
${PC_FFTW3_LIBRARIES}
${PC_ALSA_LIBRARIES}
${PC_LIBCONFIG_LIBRARIES}
${PC_PULSEAUDIO_LIBRARIES}
m
pthread
)
then, when i try to build the project, i am getting a bunch of errors:
**** Incremental Build of configuration Debug for project RPI_audio_sweep_04 ****
/usr/bin/ninja -j 8 all
[1/1] Linking CXX executable Audio_Sweep_Cross_CMake_04
FAILED: Audio_Sweep_Cross_CMake_04
: && /opt/x-tools/aarch64-rpi3-linux-gnu/bin/aarch64-rpi3-linux-gnu-g++ --sysroot=/sysroot -g --sysroot=/sysroot CMakeFiles/Audio_Sweep_Cross_CMake_04.dir/src/main.cpp.o -o Audio_Sweep_Cross_CMake_04 -Wl,-rpath,/RPI_audio_sweep_04/_build/Debug libodas.so -lfftw3f -lasound -lconfig -lpulse-simple -lpulse -lm -lpthread && :
/opt/x-tools/aarch64-rpi3-linux-gnu/bin/../lib/gcc/aarch64-rpi3-linux-gnu/12.2.0/../../../../aarch64-rpi3-linux-gnu/bin/ld.bfd: /sysroot/lib/aarch64-linux-gnu/libpthread.a(pthread_create.o): in function `allocate_stack':
./nptl/allocatestack.c:525: undefined reference to `_dl_stack_flags'
/opt/x-tools/aarch64-rpi3-linux-gnu/bin/../lib/gcc/aarch64-rpi3-linux-gnu/12.2.0/../../../../aarch64-rpi3-linux-gnu/bin/ld.bfd: ./nptl/allocatestack.c:647: undefined reference to `_dl_stack_flags'
/opt/x-tools/aarch64-rpi3-linux-gnu/bin/../lib/gcc/aarch64-rpi3-linux-gnu/12.2.0/../../../../aarch64-rpi3-linux-gnu/bin/ld.bfd: /sysroot/lib/aarch64-linux-gnu/libpthread.a(nptl-init.o): in function `__pthread_initialize_minimal_internal':
./nptl/nptl-init.c:335: undefined reference to `_dl_pagesize'
/opt/x-tools/aarch64-rpi3-linux-gnu/bin/../lib/gcc/aarch64-rpi3-linux-gnu/12.2.0/../../../../aarch64-rpi3-linux-gnu/bin/ld.bfd: ./nptl/nptl-init.c:344: undefined reference to `_dl_pagesize'
/opt/x-tools/aarch64-rpi3-linux-gnu/bin/../lib/gcc/aarch64-rpi3-linux-gnu/12.2.0/../../../../aarch64-rpi3-linux-gnu/bin/ld.bfd: ./nptl/nptl-init.c:360: undefined reference to `_dl_init_static_tls'
/opt/x-tools/aarch64-rpi3-linux-gnu/bin/../lib/gcc/aarch64-rpi3-linux-gnu/12.2.0/../../../../aarch64-rpi3-linux-gnu/bin/ld.bfd: ./nptl/nptl-init.c:362: undefined reference to `_dl_wait_lookup_done'
/opt/x-tools/aarch64-rpi3-linux-gnu/bin/../lib/gcc/aarch64-rpi3-linux-gnu/12.2.0/../../../../aarch64-rpi3-linux-gnu/bin/ld.bfd: /sysroot/lib/aarch64-linux-gnu/libpthread.a(nptl-init.o): in function `__pthread_get_minstack':
./nptl/nptl-init.c:393: undefined reference to `_dl_pagesize'
/opt/x-tools/aarch64-rpi3-linux-gnu/bin/../lib/gcc/aarch64-rpi3-linux-gnu/12.2.0/../../../../aarch64-rpi3-linux-gnu/bin/ld.bfd: /sysroot/lib/aarch64-linux-gnu/libpthread.a(unwind.o): in function `_jmpbuf_sp':
./nptl/../sysdeps/aarch64/jmpbuf-offsets.h:52: undefined reference to `__pointer_chk_guard_local'
collect2: error: ld returned 1 exit status
ninja: build stopped: subcommand failed.
"/usr/bin/ninja -j 8 all" terminated with exit code 1. Build might be incomplete.
Not sure what is going on here.
Related
I'm trying to include TensorFlow lite libraries in CMakeLists.txt of C++ project. I followed the instructure in https://www.tensorflow.org/lite/guide/build_cmake
git clone https://github.com/tensorflow/tensorflow.git tensorflow_src
mkdir tflite_build && cd tflite_build
cmake ../tensorflow_src/tensorflow/lite -DTFLITE_ENABLE_XNNPACK=OFF
-DTFLITE_ENABLE_EXTERNAL_DELEGATE=OFF TFLITE_ENABLE_RUY=ON/OFF (tried both option)
cmake --build . --config release -j24
and added all the libs to the CmakeLists.txt file as follow
cmake_minimum_required(VERSION 3.0.0)
project(main)
set(TENSORFLOW_SRC_DIR "test_cpp/tensorflow_src")
set(TFLITE_DIR "test_cpp/tflite_build")
find_package(OpenCV 4 REQUIRED)
file(GLOB SOURCE_FILES src/*.cpp src/*.h )
message(${SOURCE_FILES})
add_executable(${CMAKE_PROJECT_NAME} ${SOURCE_FILES})
include_directories(
${TENSORFLOW_SRC_DIR}
${TFLITE_DIR}/eigen
${TFLITE_DIR}/neon2sse
${TFLITE_DIR}/abseil-cpp
${TFLITE_DIR}/farmhash/src
${TFLITE_DIR}/flatbuffers/include
${TFLITE_DIR}/gemmlowp/public
${TFLITE_DIR}/gemmlowp
${TFLITE_DIR}/ruy
${TFLITE_DIR}/cpuinfo/include
)
target_link_libraries(
${CMAKE_PROJECT_NAME} PUBLIC
${OpenCV_LIBS}
${TFLITE_DIR}/_deps/farmhash-build/libfarmhash.a
${TFLITE_DIR}/_deps/abseil-cpp-build/absl/flags/libabsl_flags_marshalling.a
${TFLITE_DIR}/_deps/abseil-cpp-build/absl/flags/libabsl_flags_program_name.a
${TFLITE_DIR}/_deps/abseil-cpp-build/absl/flags/libabsl_flags_reflection.a
${TFLITE_DIR}/_deps/abseil-cpp-build/absl/flags/libabsl_flags_private_handle_accessor.a
${TFLITE_DIR}/_deps/abseil-cpp-build/absl/flags/libabsl_flags_config.a
${TFLITE_DIR}/_deps/abseil-cpp-build/absl/flags/libabsl_flags_internal.a
${TFLITE_DIR}/_deps/abseil-cpp-build/absl/flags/libabsl_flags_commandlineflag_internal.a
${TFLITE_DIR}/_deps/abseil-cpp-build/absl/flags/libabsl_flags_commandlineflag.a
${TFLITE_DIR}/_deps/abseil-cpp-build/absl/flags/libabsl_flags.a
${TFLITE_DIR}/_deps/abseil-cpp-build/absl/strings/libabsl_cordz_functions.a
${TFLITE_DIR}/_deps/abseil-cpp-build/absl/strings/libabsl_strings_internal.a
${TFLITE_DIR}/_deps/abseil-cpp-build/absl/strings/libabsl_cordz_handle.a
${TFLITE_DIR}/_deps/abseil-cpp-build/absl/strings/libabsl_str_format_internal.a
${TFLITE_DIR}/_deps/abseil-cpp-build/absl/strings/libabsl_cordz_info.a
${TFLITE_DIR}/_deps/abseil-cpp-build/absl/strings/libabsl_cord.a
${TFLITE_DIR}/_deps/abseil-cpp-build/absl/strings/libabsl_cord_internal.a
${TFLITE_DIR}/_deps/abseil-cpp-build/absl/strings/libabsl_strings.a
${TFLITE_DIR}/_deps/abseil-cpp-build/absl/container/libabsl_raw_hash_set.a
${TFLITE_DIR}/_deps/abseil-cpp-build/absl/container/libabsl_hashtablez_sampler.a
${TFLITE_DIR}/_deps/abseil-cpp-build/absl/synchronization/libabsl_synchronization.a
${TFLITE_DIR}/_deps/abseil-cpp-build/absl/synchronization/libabsl_graphcycles_internal.a
${TFLITE_DIR}/_deps/abseil-cpp-build/absl/hash/libabsl_city.a
${TFLITE_DIR}/_deps/abseil-cpp-build/absl/hash/libabsl_hash.a
${TFLITE_DIR}/_deps/abseil-cpp-build/absl/hash/libabsl_low_level_hash.a
${TFLITE_DIR}/_deps/abseil-cpp-build/absl/time/libabsl_civil_time.a
${TFLITE_DIR}/_deps/abseil-cpp-build/absl/time/libabsl_time_zone.a
${TFLITE_DIR}/_deps/abseil-cpp-build/absl/time/libabsl_time.a
${TFLITE_DIR}/_deps/abseil-cpp-build/absl/profiling/libabsl_exponential_biased.a
${TFLITE_DIR}/_deps/abseil-cpp-build/absl/types/libabsl_bad_optional_access.a
${TFLITE_DIR}/_deps/abseil-cpp-build/absl/types/libabsl_bad_variant_access.a
${TFLITE_DIR}/_deps/abseil-cpp-build/absl/numeric/libabsl_int128.a
${TFLITE_DIR}/_deps/abseil-cpp-build/absl/base/libabsl_raw_logging_internal.a
${TFLITE_DIR}/_deps/abseil-cpp-build/absl/base/libabsl_throw_delegate.a
${TFLITE_DIR}/_deps/abseil-cpp-build/absl/base/libabsl_base.a
${TFLITE_DIR}/_deps/abseil-cpp-build/absl/base/libabsl_log_severity.a
${TFLITE_DIR}/_deps/abseil-cpp-build/absl/base/libabsl_spinlock_wait.a
${TFLITE_DIR}/_deps/abseil-cpp-build/absl/base/libabsl_malloc_internal.a
${TFLITE_DIR}/_deps/abseil-cpp-build/absl/status/libabsl_status.a
${TFLITE_DIR}/_deps/abseil-cpp-build/absl/debugging/libabsl_stacktrace.a
${TFLITE_DIR}/_deps/abseil-cpp-build/absl/debugging/libabsl_demangle_internal.a
${TFLITE_DIR}/_deps/abseil-cpp-build/absl/debugging/libabsl_symbolize.a
${TFLITE_DIR}/_deps/abseil-cpp-build/absl/debugging/libabsl_debugging_internal.a
${TFLITE_DIR}/_deps/flatbuffers-build/libflatbuffers.a
${TFLITE_DIR}/_deps/ruy-build/ruy/libruy_ctx.a
${TFLITE_DIR}/_deps/ruy-build/ruy/libruy_kernel_avx.a
${TFLITE_DIR}/_deps/ruy-build/ruy/libruy_have_built_path_for_avx512.a
${TFLITE_DIR}/_deps/ruy-build/ruy/libruy_cpuinfo.a
${TFLITE_DIR}/_deps/ruy-build/ruy/libruy_frontend.a
${TFLITE_DIR}/_deps/ruy-build/ruy/libruy_blocking_counter.a
${TFLITE_DIR}/_deps/ruy-build/ruy/libruy_kernel_avx512.a
${TFLITE_DIR}/_deps/ruy-build/ruy/libruy_apply_multiplier.a
${TFLITE_DIR}/_deps/ruy-build/ruy/libruy_block_map.a
${TFLITE_DIR}/_deps/ruy-build/ruy/libruy_trmul.a
${TFLITE_DIR}/_deps/ruy-build/ruy/libruy_kernel_avx2_fma.a
${TFLITE_DIR}/_deps/ruy-build/ruy/profiler/libruy_profiler_instrumentation.a
${TFLITE_DIR}/_deps/ruy-build/ruy/libruy_denormal.a
${TFLITE_DIR}/_deps/ruy-build/ruy/libruy_prepacked_cache.a
${TFLITE_DIR}/_deps/ruy-build/ruy/libruy_system_aligned_alloc.a
${TFLITE_DIR}/_deps/ruy-build/ruy/libruy_context_get_ctx.a
${TFLITE_DIR}/_deps/ruy-build/ruy/libruy_allocator.a
${TFLITE_DIR}/_deps/ruy-build/ruy/libruy_have_built_path_for_avx2_fma.a
${TFLITE_DIR}/_deps/ruy-build/ruy/libruy_pack_avx.a
${TFLITE_DIR}/_deps/ruy-build/ruy/libruy_wait.a
${TFLITE_DIR}/_deps/ruy-build/ruy/libruy_context.a
${TFLITE_DIR}/_deps/ruy-build/ruy/libruy_pack_avx2_fma.a
${TFLITE_DIR}/_deps/ruy-build/ruy/libruy_thread_pool.a
${TFLITE_DIR}/_deps/ruy-build/ruy/libruy_pack_arm.a
${TFLITE_DIR}/_deps/ruy-build/ruy/libruy_tune.a
${TFLITE_DIR}/_deps/ruy-build/ruy/libruy_kernel_arm.a
${TFLITE_DIR}/_deps/ruy-build/ruy/libruy_have_built_path_for_avx.a
${TFLITE_DIR}/_deps/ruy-build/ruy/libruy_prepare_packed_matrices.a
${TFLITE_DIR}/_deps/ruy-build/ruy/libruy_pack_avx512.a
${TFLITE_DIR}/_deps/fft2d-build/libfft2d_fftsg.a
${TFLITE_DIR}/_deps/fft2d-build/libfft2d_fftsg2d.a
${TFLITE_DIR}/_deps/clog-build/libclog.a
${TFLITE_DIR}/_deps/cpuinfo-build/libcpuinfo.a
${TFLITE_DIR}/libtensorflow-lite.a
dl
)
It worked on a windows machine but on Linux I'm getting error about
undefined reference to `ruy::ScopedSuppressDenormals::ScopedSuppressDenormals()'
[ 33%] Building CXX object CMakeFiles/main.dir/src/main.cpp.o
[ 66%] Building CXX object CMakeFiles/main.dir/src/ssd_mobilenet_tflite.cpp.o
[100%] Linking CXX executable main
/usr/bin/ld: ../tflite_build/libtensorflow-lite.a(interpreter.cc.o): in function `tflite::Interpreter::Invoke()':
interpreter.cc:(.text+0x3ff): undefined reference to `ruy::ScopedSuppressDenormals::ScopedSuppressDenormals()'
/usr/bin/ld: interpreter.cc:(.text+0x523): undefined reference to `ruy::ScopedSuppressDenormals::~ScopedSuppressDenormals()'
/usr/bin/ld: ../tflite_build/libtensorflow-lite.a(interpreter.cc.o): in function `tflite::Interpreter::Invoke() [clone .cold]':
interpreter.cc:(.text.unlikely+0x5c): undefined reference to `ruy::ScopedSuppressDenormals::~ScopedSuppressDenormals()'
/usr/bin/ld: CMakeFiles/main.dir/src/ssd_mobilenet_tflite.cpp.o: in function `SSD_MOBILENET::loadModel(std::__cxx11::basic_string<char, std::char_traits<char>, std::allocator<char> >)':
ssd_mobilenet_tflite.cpp:(.text+0x2b2): undefined reference to `tflite::ops::builtin::BuiltinOpResolver::BuiltinOpResolver()'
collect2: error: ld returned 1 exit status
make[2]: *** [CMakeFiles/main.dir/build.make:231: main] Error 1
make[1]: *** [CMakeFiles/Makefile2:76: CMakeFiles/main.dir/all] Error 2
make: *** [Makefile:84: all] Error 2
I don't want to add the libs as "add_subdirectory" as it was given in the guide because it will compile every time I create a new project
So how can I solve the undefined reference to `ruy::ScopedSuppressDenormals::ScopedSuppressDenormals()'
UPDATE:
if I change the CMakeLists.txt to :
cmake_minimum_required(VERSION 3.0.0)
project(main)
set(TENSORFLOW_SRC_DIR "test_cpp/tensorflow_src")
set(TFLITE_DIR "test_cpp/tflite_build")
find_package(OpenCV 4 REQUIRED)
find_package(TFLITE)
file(GLOB SOURCE_FILES src/*.cpp src/*.h )
message(${SOURCE_FILES})
add_executable(${CMAKE_PROJECT_NAME} ${SOURCE_FILES})
include_directories(
${TENSORFLOW_SRC_DIR}
)
target_link_libraries(
${CMAKE_PROJECT_NAME} PUBLIC
${OpenCV_LIBS}
${TFLITE_LIBS}
)
I take this error
from test_cpp/src/main.cpp:1:
test_cpp/tensorflow_src/tensorflow/lite/interpreter_builder.h:26:10: fatal error: flatbuffers/flatbuffers.h: No such file or directory
26 | #include "flatbuffers/flatbuffers.h" // from #flatbuffers
| ^~~~~~~~~~~~~~~~~~~~~~~~~~~
compilation terminated.
make[2]: *** [CMakeFiles/main.dir/build.make:63: CMakeFiles/main.dir/src/main.cpp.o] Error 1
make[1]: *** [CMakeFiles/Makefile2:76: CMakeFiles/main.dir/all] Error 2
make: *** [Makefile:84: all] Error 2
I found this repo that contains all needed libs for the project https://github.com/muhammedakyuzlu/tflite-cpp-package
I believe that the problem you have is the ordering of the libs.
Try putting the libtensorflow-lite.a before the ruy-*.a in your setup.
There is another trick that could help you getting started.
Just add this to your CMake File:
include(FetchContent)
FetchContent_Declare(
tensorflow
GIT_REPOSITORY https://github.com/tensorflow/tensorflow.git
GIT_PROGRESS TRUE
GIT_SHALLOW TRUE
GIT_TAG v2.10.0
SOURCE_SUBDIR tensorflow/lite
)
FetchContent_MakeAvailable(tensorflow)
and link to the library:
target_link_libraries(${PROJECT_NAME} PRIVATE
tensorflow-lite
)
This is downloading all dependencies automatically and should make you ready to go.
Let me first start with my CMakeLists.txt source:
cmake_minimum_required(VERSION 2.8.7)
project(audiowaveform)
#set(CMAKE_EXE_LINKER_FLAGS "-static-libgcc -static-libstdc++ -static")
if(NOT CMAKE_BUILD_TYPE)
set(CMAKE_BUILD_TYPE "Release")
message(STATUS "Build type not specified: default is Release")
endif()
set(CMAKE_FIND_LIBRARY_SUFFIXES ".a")
message(STATUS "CMAKE_VERSION=${CMAKE_VERSION}")
message(STATUS "Build type: ${CMAKE_BUILD_TYPE}")
set(CMAKE_MODULE_PATH "${audiowaveform_SOURCE_DIR}/cmake/modules")
message(STATUS "CMAKE_MODULE_PATH='${CMAKE_MODULE_PATH}'")
include(SystemInfo)
#-------------------------------------------------------------------------------
#
# Version number
#
#-------------------------------------------------------------------------------
# Read version number from VERSION file and split into its component parts.
file(STRINGS "VERSION" VERSION)
string(REGEX MATCH "^([0-9]+)\\.([0-9]+)\\.([0-9]+)$" VERSION_PARTS ${VERSION})
set(VERSION_MAJOR ${CMAKE_MATCH_1})
set(VERSION_MINOR ${CMAKE_MATCH_2})
set(VERSION_PATCH ${CMAKE_MATCH_3})
message(STATUS "Building version ${VERSION_MAJOR}.${VERSION_MINOR}.${VERSION_PATCH}")
#-------------------------------------------------------------------------------
#
# Dependencies
#
#-------------------------------------------------------------------------------
find_package(LibGD REQUIRED)
if(LIBGD_FOUND)
message(STATUS "LIBGD_INCLUDE_DIR='${LIBGD_INCLUDE_DIR}'")
message(STATUS "LIBGD_LIBRARY=${LIBGD_LIBRARY}")
include_directories(${LIBGD_INCLUDE_DIR})
endif(LIBGD_FOUND)
find_package(LibSndFile REQUIRED)
if(LIBSNDFILE_FOUND)
message(STATUS "LIBSNDFILE_INCLUDE_DIR='${LIBSNDFILE_INCLUDE_DIR}'")
message(STATUS "LIBSNDFILE_LIBRARY=${LIBSNDFILE_LIBRARY}")
include_directories(${LIBSNDFILE_INCLUDE_DIR})
endif(LIBSNDFILE_FOUND)
find_package(LibMad REQUIRED)
if(LIBMAD_FOUND)
message(STATUS "LIBMAD_INCLUDE_DIR='${LIBMAD_INCLUDE_DIR}'")
message(STATUS "LIBMAD_LIBRARY=${LIBMAD_LIBRARY}")
include_directories(${LIBMAD_INCLUDE_DIR})
endif(LIBMAD_FOUND)
find_package(LibId3Tag REQUIRED)
if(LIBID3TAG_FOUND)
message(STATUS "LIBID3TAG_INCLUDE_DIR='${LIBID3TAG_INCLUDE_DIR}'")
message(STATUS "LIBID3TAG_LIBRARY=${LIBID3TAG_LIBRARY}")
include_directories(${LIBID3TAG_INCLUDE_DIR})
endif(LIBID3TAG_FOUND)
add_definitions( -DBOOST_ALL_NO_LIB )
set(Boost_USE_STATIC_LIBS ON)
unset(Boost_INCLUDE_DIR CACHE)
unset(Boost_LIBRARY_DIRS CACHE)
find_package(Boost 1.46.0 COMPONENTS program_options filesystem regex system REQUIRED)
if(Boost_FOUND)
message(STATUS "Boost_INCLUDE_DIRS='${Boost_INCLUDE_DIRS}'")
message(STATUS "Boost_LIBRARIES='${Boost_LIBRARIES}'")
include_directories(${Boost_INCLUDE_DIRS})
endif(Boost_FOUND)
#-------------------------------------------------------------------------------
#
# Packaging
#
#-------------------------------------------------------------------------------
set(CPACK_PACKAGE_NAME "audiowaveform")
set(CPACK_PACKAGE_VENDOR "Chris Needham")
set(CPACK_PACKAGE_VERSION_MAJOR ${VERSION_MAJOR})
set(CPACK_PACKAGE_VERSION_MINOR ${VERSION_MINOR})
set(CPACK_PACKAGE_VERSION_PATCH ${VERSION_PATCH})
SET(CPACK_PACKAGE_VERSION "${CPACK_PACKAGE_VERSION_MAJOR}.${CPACK_PACKAGE_VERSION_MINOR}.${CPACK_PACKAGE_VERSION_PATCH}")
set(CPACK_PACKAGE_CONTACT "Chris Needham <chris#chrisneedham.com>")
set(CPACK_PACKAGE_DESCRIPTION_SUMMARY "Audio waveform data and image generator")
set(CPACK_PACKAGE_DESCRIPTION "Generates audio waveform data that can be used to render waveform images, similar to Audacity")
set(CPACK_RESOURCE_FILE_LICENSE "${audiowaveform_SOURCE_DIR}/COPYING")
set(CPACK_RESOURCE_FILE_README "${audiowaveform_SOURCE_DIR}/README.md")
set(PACKAGE_RELEASE_NUMBER 1)
if(UNIX AND NOT APPLE AND NOT CYGWIN)
if(OF_DISTRO_IS_UBUNTU)
set(CPACK_GENERATOR "DEB")
set(CPACK_DEBIAN_PACKAGE_SECTION "sound")
set(CPACK_DEBIAN_PACKAGE_PRIORITY "optional")
set(CPACK_DEBIAN_PACKAGE_ARCHITECTURE "${OF_SYSTEM_ARCH}")
set(PACKAGE_BOOST_VERSION "${Boost_MAJOR_VERSION}.${Boost_MINOR_VERSION}.${Boost_SUBMINOR_VERSION}")
set(CPACK_DEBIAN_PACKAGE_DEPENDS "libmad0 (>=0.15.1), libsndfile1 (>= 1.0.25), libgd2-xpm (>= 2.0.35), libboost-program-options${PACKAGE_BOOST_VERSION}, libboost-filesystem${PACKAGE_BOOST_VERSION}, libboost-regex${PACKAGE_BOOST_VERSION}")
# http://www.debian.org/doc/manuals/debian-faq/ch-pkg_basics.en.html#s-pkgname
# The Debian binary package file names conform to the following convention:
# <foo>_<VersionNumber>-<DebianRevisionNumber>_<DebianArchitecture>.deb
set(CPACK_PACKAGE_FILE_NAME "${CPACK_PACKAGE_NAME}_${CPACK_PACKAGE_VERSION}-${PACKAGE_RELEASE_NUMBER}_${CPACK_DEBIAN_PACKAGE_ARCHITECTURE}")
endif()
if(OF_DISTRO_IS_CENTOS OR OF_DISTRO_IS_FEDORA)
set(CPACK_GENERATOR "RPM")
set(CPACK_RPM_PACKAGE_GROUP "Applications/Multimedia")
set(CPACK_RPM_PACKAGE_ARCHITECTURE "${OF_SYSTEM_ARCH}")
set(CPACK_RPM_PACKAGE_REQUIRES "libmad >= 0.15.1, libsndfile >= 1.0.25, gd >= 2.0.35, boost >= ${Boost_MAJOR_VERSION}.${Boost_MINOR_VERSION}")
set(CPACK_PACKAGE_FILE_NAME "${CPACK_PACKAGE_NAME}-${CPACK_PACKAGE_VERSION}-${PACKAGE_RELEASE_NUMBER}.${OF_SYSTEM_ARCH}")
endif()
endif()
include(CPack)
#-------------------------------------------------------------------------------
#
# Compiler flags
#
#-------------------------------------------------------------------------------
if(CMAKE_VERSION VERSION_LESS "2.8.10")
exec_program(
${CMAKE_CXX_COMPILER}
ARGS --version
OUTPUT_VARIABLE COMPILER_VERSION_STRING
)
string(REGEX REPLACE ".*([0-9]\\.[0-9]\\.[0-9]).*" "\\1" CMAKE_CXX_COMPILER_VERSION ${COMPILER_VERSION_STRING})
endif()
if(CMAKE_COMPILER_IS_GNUCXX AND CMAKE_CXX_COMPILER_VERSION VERSION_LESS "4.6.3")
message(FATAL_ERROR "g++ 4.6.3 or later required")
endif()
if(CMAKE_COMPILER_IS_GNUCXX AND CMAKE_CXX_COMPILER_VERSION VERSION_GREATER "4.7")
set(CMAKE_CXX_FLAGS "-std=c++11")
else()
# Set GTEST_LANG_CXX11=0 to disable C++11 features when compiling googlemock.
# Without this compilation fails with g++ 4.6.3 on gmock-matchers.h.
set(CMAKE_CXX_FLAGS "-std=c++0x -DGTEST_LANG_CXX11=0")
endif()
set(COMMON_FLAGS "-Wall -Wextra -Wconversion -pedantic")
set(CMAKE_CXX_FLAGS "${CMAKE_CXX_FLAGS} ${COMMON_FLAGS} -DBOOST_FILESYSTEM_NO_DEPRECATED")
set(CMAKE_C_FLAGS ${COMMON_FLAGS})
if(APPLE)
set(CMAKE_CXX_FLAGS "-stdlib=libc++ ${CMAKE_CXX_FLAGS}")
endif()
message(STATUS "CMAKE_CXX_COMPILER_VERSION='${CMAKE_CXX_COMPILER_VERSION}'")
message(STATUS "CMAKE_CXX_FLAGS='${CMAKE_CXX_FLAGS}'")
message(STATUS "CMAKE_CXX_FLAGS_DEBUG='${CMAKE_CXX_FLAGS_DEBUG}'")
message(STATUS "CMAKE_CXX_FLAGS_RELEASE='${CMAKE_CXX_FLAGS_RELEASE}'")
message(STATUS "CMAKE_CXX_COMPILE_OBJECT='${CMAKE_CXX_COMPILE_OBJECT}'")
#-------------------------------------------------------------------------------
#
# Source files
#
#-------------------------------------------------------------------------------
include_directories(src)
# Configure a header file to pass some of the CMake settings to the source code.
configure_file(
"${PROJECT_SOURCE_DIR}/src/Config.h.in"
"${PROJECT_BINARY_DIR}/Config.h"
)
# Add the binary directory to the search path for include files so that we find
# Config.h.
include_directories("${PROJECT_BINARY_DIR}")
set(MODULES
src/AudioFileReader.cpp
src/AudioProcessor.cpp
src/BStdFile.cpp
src/Error.cpp
src/GdImageRenderer.cpp
src/MathUtil.cpp
src/Mp3AudioFileReader.cpp
src/Options.cpp
src/OptionHandler.cpp
src/Rgba.cpp
src/SndFileAudioFileReader.cpp
src/TimeUtil.cpp
src/WaveformBuffer.cpp
src/WaveformColors.cpp
src/WaveformGenerator.cpp
src/WaveformRescaler.cpp
src/WavFileWriter.cpp
src/madlld-1.1p1/bstdfile.c
)
set(SRCS
src/Main.cpp
${MODULES}
)
add_executable(audiowaveform ${SRCS})
#-------------------------------------------------------------------------------
#
# Linker
#
#-------------------------------------------------------------------------------
# Specify libraries to link against.
set(LIBS ${LIBSNDFILE_LIBRARY} ${LIBMAD_LIBRARY} ${LIBID3TAG_LIBRARY} ${Boost_LIBRARIES} ) #${ZLIB_LIBRARIES}
target_link_libraries(audiowaveform ${LIBS} )
target_link_libraries(audiowaveform ${LIBGD_LIBRARY} )
#-------------------------------------------------------------------------------
#
# Tests
#
#-------------------------------------------------------------------------------
if (NOT DEFINED ENABLE_TESTS)
set(ENABLE_TESTS 0)
endif()
if(ENABLE_TESTS)
enable_testing()
# Use EXCLUDE_FROM_ALL to prevent installing googletest headers as part of
# 'make install'.
add_subdirectory(googlemock EXCLUDE_FROM_ALL)
set(TESTS
test/AudioFileReaderTest.cpp
test/GdImageRendererTest.cpp
test/MathUtilTest.cpp
test/Mp3AudioFileReaderTest.cpp
test/OptionsTest.cpp
test/OptionHandlerTest.cpp
test/RgbaTest.cpp
test/SndFileAudioFileReaderTest.cpp
test/TimeUtilTest.cpp
test/WavFileWriterTest.cpp
test/WaveformBufferTest.cpp
test/WaveformGeneratorTest.cpp
test/WaveformRescalerTest.cpp
test/util/FileDeleter.cpp
test/util/FileUtil.cpp
test/util/Streams.cpp
)
include_directories(${gtest_SOURCE_DIR}/include ${gmock_SOURCE_DIR}/include)
set(TEST_LIBS gmock_main)
add_executable(audiowaveform_tests ${MODULES} ${TESTS})
target_link_libraries(audiowaveform_tests ${LIBS} ${TEST_LIBS})
add_test(audiowaveform_tests audiowaveform_tests)
else()
message(STATUS "Unit tests disabled")
endif()
#-------------------------------------------------------------------------------
#
# Documentation
#
#-------------------------------------------------------------------------------
file(MAKE_DIRECTORY ${PROJECT_BINARY_DIR}/doc)
add_custom_command(
OUTPUT ${PROJECT_BINARY_DIR}/doc/audiowaveform.1.gz
COMMAND gzip -c -9 ${PROJECT_SOURCE_DIR}/doc/audiowaveform.1 > ${PROJECT_BINARY_DIR}/doc/audiowaveform.1.gz
DEPENDS ${PROJECT_SOURCE_DIR}/doc/audiowaveform.1
)
add_custom_command(
OUTPUT ${PROJECT_BINARY_DIR}/doc/audiowaveform.5.gz
COMMAND gzip -c -9 ${PROJECT_SOURCE_DIR}/doc/audiowaveform.5 > ${PROJECT_BINARY_DIR}/doc/audiowaveform.5.gz
DEPENDS ${PROJECT_SOURCE_DIR}/doc/audiowaveform.5
)
add_custom_target(doc
DEPENDS ${PROJECT_BINARY_DIR}/doc/audiowaveform.1.gz
${PROJECT_BINARY_DIR}/doc/audiowaveform.5.gz
)
add_dependencies(audiowaveform doc)
#-------------------------------------------------------------------------------
#
# Installation
#
#-------------------------------------------------------------------------------
message(STATUS "CMAKE_INSTALL_PREFIX='${CMAKE_INSTALL_PREFIX}'")
# Install executable
install(TARGETS audiowaveform DESTINATION bin)
# Install man pages
install(
FILES ${PROJECT_BINARY_DIR}/doc/audiowaveform.1.gz
DESTINATION share/man/man1
)
install(
FILES ${PROJECT_BINARY_DIR}/doc/audiowaveform.5.gz
DESTINATION share/man/man5
)
#-------------------------------------------------------------------------------
Now here is the message when I run cmake:
The C compiler identification is GNU 5.4.1
The CXX compiler identification is GNU 5.4.1
Check for working C compiler: /usr/bin/cc
Check for working C compiler: /usr/bin/cc -- works
Detecting C compiler ABI info
Detecting C compiler ABI info - done
Detecting C compile features
Detecting C compile features - done
Check for working CXX compiler: /usr/bin/c++
Check for working CXX compiler: /usr/bin/c++ -- works
Detecting CXX compiler ABI info
Detecting CXX compiler ABI info - done
Detecting CXX compile features
Detecting CXX compile features - done
Build type not specified: default is Release
CMAKE_VERSION=3.5.2
Build type: Release
CMAKE_MODULE_PATH='/home/medo/build2/audiowaveform-master/cmake/modules'
Building version 1.1.0
Found LibGD: /usr/local/lib/libgd.a
LIBGD_INCLUDE_DIR='/usr/local/include'
LIBGD_LIBRARY=/usr/local/lib/libgd.a
Found LibSndFile: /usr/local/lib/libsndfile.a
LIBSNDFILE_INCLUDE_DIR='/usr/local/include'
LIBSNDFILE_LIBRARY=/usr/local/lib/libsndfile.a
Found LibMad: /usr/local/lib/libmad.a
LIBMAD_INCLUDE_DIR='/usr/local/include'
LIBMAD_LIBRARY=/usr/local/lib/libmad.a
Found LibId3Tag: /usr/local/lib/libid3tag.a
LIBID3TAG_INCLUDE_DIR='/usr/local/include'
LIBID3TAG_LIBRARY=/usr/local/lib/libid3tag.a
Boost version: 1.58.0
Found the following Boost libraries:
program_options
filesystem
regex
system
Boost_INCLUDE_DIRS='/usr/include'
Boost_LIBRARIES='/usr/lib/x86_64-linux-gnu/libboost_program_options.a;/usr/lib/x86_64-linux-gnu/libboost_filesystem.a;/usr/lib/x86_64-linux-gnu/libboost_regex.a;/usr/lib/x86_64-linux-gnu/libboost_system.a'
CMAKE_CXX_COMPILER_VERSION='5.4.1'
CMAKE_CXX_FLAGS='-std=c++11 -Wall -Wextra -Wconversion -pedantic -DBOOST_FILESYSTEM_NO_DEPRECATED'
CMAKE_CXX_FLAGS_DEBUG='-g'
CMAKE_CXX_FLAGS_RELEASE='-O3 -DNDEBUG'
CMAKE_CXX_COMPILE_OBJECT='<CMAKE_CXX_COMPILER> <DEFINES> <INCLUDES> <FLAGS> -o <OBJECT> -c <SOURCE>'
Unit tests disabled
CMAKE_INSTALL_PREFIX='/usr/local'
Configuring done
Generating done
now i enter to build folder and ran make command
and when the progress 100% its give me an error
[100%] Linking CXX executable audiowaveform
/usr/local/lib/libsndfile.a(libsndfile_la-flac.o): In function `sf_flac_error_callback':
/home/medo/build2/lib/libsndfile-1.0.28/src/flac.c:520: undefined reference to `FLAC__StreamDecoderErrorStatusString'
/usr/local/lib/libsndfile.a(libsndfile_la-flac.o): In function `flac_seek':
/home/medo/build2/lib/libsndfile-1.0.28/src/flac.c:1391: undefined reference to `FLAC__stream_decoder_seek_absolute'
/usr/local/lib/libsndfile.a(libsndfile_la-flac.o): In function `flac_close':
/home/medo/build2/lib/libsndfile-1.0.28/src/flac.c:736: undefined reference to `FLAC__metadata_object_delete'
/home/medo/build2/lib/libsndfile-1.0.28/src/flac.c:739: undefined reference to `FLAC__stream_encoder_finish'
/home/medo/build2/lib/libsndfile-1.0.28/src/flac.c:740: undefined reference to `FLAC__stream_encoder_delete'
/home/medo/build2/lib/libsndfile-1.0.28/src/flac.c:745: undefined reference to `FLAC__stream_decoder_finish'
/home/medo/build2/lib/libsndfile-1.0.28/src/flac.c:746: undefined reference to `FLAC__stream_decoder_delete'
/usr/local/lib/libsndfile.a(libsndfile_la-flac.o): In function `flac_write_strings':
/home/medo/build2/lib/libsndfile-1.0.28/src/flac.c:627: undefined reference to `FLAC__metadata_object_vorbiscomment_entry_from_name_value_pair'
/home/medo/build2/lib/libsndfile-1.0.28/src/flac.c:628: undefined reference to `FLAC__metadata_object_vorbiscomment_append_comment'
/home/medo/build2/lib/libsndfile-1.0.28/src/flac.c:631: undefined reference to `FLAC__stream_encoder_set_metadata'
/usr/local/lib/libsndfile.a(libsndfile_la-flac.o): In function `flac_write_header':
/home/medo/build2/lib/libsndfile-1.0.28/src/flac.c:646: undefined reference to `FLAC__stream_encoder_init_stream'
/home/medo/build2/lib/libsndfile-1.0.28/src/flac.c:647: undefined reference to `FLAC__StreamEncoderInitStatusString'
/usr/local/lib/libsndfile.a(libsndfile_la-flac.o): In function `flac_write_strings':
/home/medo/build2/lib/libsndfile-1.0.28/src/flac.c:582: undefined reference to `FLAC__metadata_object_new'
/usr/local/lib/libsndfile.a(libsndfile_la-flac.o): In function `sf_flac_meta_get_vorbiscomments':
/home/medo/build2/lib/libsndfile-1.0.28/src/flac.c:414: undefined reference to `FLAC__metadata_object_vorbiscomment_find_entry_from'
/usr/local/lib/libsndfile.a(libsndfile_la-flac.o): In function `flac_enc_init':
/home/medo/build2/lib/libsndfile-1.0.28/src/flac.c:792: undefined reference to `FLAC__stream_encoder_delete'
/home/medo/build2/lib/libsndfile-1.0.28/src/flac.c:793: undefined reference to `FLAC__stream_encoder_new'
/home/medo/build2/lib/libsndfile-1.0.28/src/flac.c:796: undefined reference to `FLAC__stream_encoder_set_channels'
/home/medo/build2/lib/libsndfile-1.0.28/src/flac.c:801: undefined reference to `FLAC__stream_encoder_set_sample_rate'
/home/medo/build2/lib/libsndfile-1.0.28/src/flac.c:806: undefined reference to `FLAC__stream_encoder_set_bits_per_sample'
/home/medo/build2/lib/libsndfile-1.0.28/src/flac.c:811: undefined reference to `FLAC__stream_encoder_set_compression_level'
/usr/local/lib/libsndfile.a(libsndfile_la-flac.o): In function `flac_write_d2flac':
/home/medo/build2/lib/libsndfile-1.0.28/src/flac.c:1272: undefined reference to `FLAC__stream_encoder_process_interleaved'
/usr/local/lib/libsndfile.a(libsndfile_la-flac.o): In function `flac_write_f2flac':
/home/medo/build2/lib/libsndfile-1.0.28/src/flac.c:1141: undefined reference to `FLAC__stream_encoder_process_interleaved'
/usr/local/lib/libsndfile.a(libsndfile_la-flac.o): In function `flac_write_i2flac':
/home/medo/build2/lib/libsndfile-1.0.28/src/flac.c:1099: undefined reference to `FLAC__stream_encoder_process_interleaved'
/usr/local/lib/libsndfile.a(libsndfile_la-flac.o): In function `flac_write_s2flac':
/home/medo/build2/lib/libsndfile-1.0.28/src/flac.c:1057: undefined reference to `FLAC__stream_encoder_process_interleaved'
/usr/local/lib/libsndfile.a(libsndfile_la-flac.o): In function `flac_read_loop':
/home/medo/build2/lib/libsndfile-1.0.28/src/flac.c:919: undefined reference to `FLAC__stream_decoder_get_state'
/home/medo/build2/lib/libsndfile-1.0.28/src/flac.c:932: undefined reference to `FLAC__stream_decoder_process_single'
/home/medo/build2/lib/libsndfile-1.0.28/src/flac.c:934: undefined reference to `FLAC__stream_decoder_get_state'
/home/medo/build2/lib/libsndfile-1.0.28/src/flac.c:936: undefined reference to `FLAC__StreamDecoderStateString'
/home/medo/build2/lib/libsndfile-1.0.28/src/flac.c:921: undefined reference to `FLAC__StreamDecoderStateString'
/usr/local/lib/libsndfile.a(libsndfile_la-flac.o): In function `flac_read_header':
/home/medo/build2/lib/libsndfile-1.0.28/src/flac.c:825: undefined reference to `FLAC__stream_decoder_delete'
/home/medo/build2/lib/libsndfile-1.0.28/src/flac.c:826: undefined reference to `FLAC__stream_decoder_new'
/home/medo/build2/lib/libsndfile-1.0.28/src/flac.c:829: undefined reference to `FLAC__stream_decoder_set_metadata_respond_all'
/home/medo/build2/lib/libsndfile-1.0.28/src/flac.c:831: undefined reference to `FLAC__stream_decoder_init_stream'
/home/medo/build2/lib/libsndfile-1.0.28/src/flac.c:834: undefined reference to `FLAC__stream_decoder_process_until_end_of_metadata'
/home/medo/build2/lib/libsndfile-1.0.28/src/flac.c:841: undefined reference to `FLAC__stream_decoder_get_decode_position'
/usr/local/lib/libsndfile.a(ogg.o): In function `ogg_close':
/home/medo/build2/lib/libsndfile-1.0.28/src/ogg.c:103: undefined reference to `ogg_sync_clear'
/home/medo/build2/lib/libgd-2.2.5/src/gd_png.c:328: undefined reference to `png_get_valid'
/home/medo/build2/lib/libgd-2.2.5/src/gd_png.c:336: undefined reference to `png_get_tRNS'
/home/medo/build2/lib/libgd-2.2.5/src/gd_png.c:311: undefined reference to `png_get_pHYs'
/home/medo/build2/lib/libgd-2.2.5/src/gd_png.c:292: undefined reference to `png_set_strip_16'
/home/medo/build2/lib/libgd-2.2.5/src/gd_png.c:396: undefined reference to `png_get_tRNS'
/usr/local/lib/libgd.a(gd_png.o): In function `gdPngReadData':
/home/medo/build2/lib/libgd-2.2.5/src/gd_png.c:89: undefined reference to `png_error'
collect2: error: ld returned 1 exit status
CMakeFiles/audiowaveform.dir/build.make:570: recipe for target 'audiowaveform' failed
make[2]: *** [audiowaveform] Error 1
CMakeFiles/Makefile2:99: recipe for target 'CMakeFiles/audiowaveform.dir/all' failed
make[1]: *** [CMakeFiles/audiowaveform.dir/all] Error 2
Makefile:149: recipe for target 'all' failed
make: *** [all] Error 2
I don't know what happened. All the libraries were linked and at the end it gave me this error. Does anyone have any ideas?
The following CMakeList produces errors which have been listed below:
cmake_minimum_required(VERSION 2.8.12)
set(CMAKE_CXX_FLAGS "${CMAKE_CXX_FLAGS} -std=c++11")
set(CMAKE_INCLUDE_CURRENT_DIR ON)
set(CMAKE_AUTOMOC ON)
set(CMAKE_AUTORCC ON)
project(draw_on_images)
find_package(catkin REQUIRED COMPONENTS
roscpp
rospy
std_msgs
)
find_package(OpenCV 2.4.8 REQUIRED)
find_package(Qt5 COMPONENTS Core Qml Quick REQUIRED)
qt5_add_resources(RESOURCES qml.qrc)
catkin_package(
CATKIN_DEPENDS roscpp rospy std_msgs
)
include_directories(
${catkin_INCLUDE_DIRS}
)
add_executable(${PROJECT_NAME} ${RESOURCES} src/main.cpp src/draw_on_qimage.cpp src/provide_qpixmap_to_qml.cpp )
qt5_use_modules(${PROJECT_NAME} Core Qml Quick)
target_link_libraries(${PROJECT_NAME} Qt5::Core Qt5::Qml Qt5::Quick ${OpenCV_LIBS})
The way I run it:
catkin_make -DCMAKE_PREFIX_PATH="/opt/Qt5.9.1/5.9.1/gcc_64/lib/" -DWITH_QT:BOOL=ON
Yes I have sourced it.
Errors:
Base path: /home/.../ros_workspace_test
Source space: /home/.../ros_workspace_test/src
Build space: /home/.../ros_workspace_test/build
Devel space: /home/.../ros_workspace_test/devel
Install space: /home/.../ros_workspace_test/install
####
#### Running command: "cmake /home/.../ros_workspace_test/src -DCMAKE_PREFIX_PATH=/opt/Qt5.9.1/5.9.1/gcc_64/lib/ -DWITH_QT:BOOL=ON -DCATKIN_DEVEL_PREFIX=/home/.../ros_workspace_test/devel -DCMAKE_INSTALL_PREFIX=/home/.../ros_workspace_test/install -G Unix Makefiles" in "/home/.../ros_workspace_test/build"
####
-- Using CATKIN_DEVEL_PREFIX: /home/.../ros_workspace_test/devel
-- Using CMAKE_PREFIX_PATH: /opt/Qt5.9.1/5.9.1/gcc_64/lib/
-- Using PYTHON_EXECUTABLE: /usr/bin/python
-- Using Debian Python package layout
-- Using empy: /usr/bin/empy
-- Using CATKIN_ENABLE_TESTING: ON
-- Call enable_testing()
-- Using CATKIN_TEST_RESULTS_DIR: /home/.../ros_workspace_test/build/test_results
-- Found gtest sources under '/usr/src/gtest': gtests will be built
-- Using Python nosetests: /usr/bin/nosetests-2.7
-- catkin 0.6.19
-- BUILD_SHARED_LIBS is on
-- ~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~
-- ~~ traversing 1 packages in topological order:
-- ~~ - draw_on_images
-- ~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~
-- +++ processing catkin package: 'draw_on_images'
-- ==> add_subdirectory(draw_on_images)
-- Configuring done
-- Generating done
CMake Warning:
Manually-specified variables were not used by the project:
WITH_QT
-- Build files have been written to: /home/.../ros_workspace_test/build
####
#### Running command: "make -j4 -l4" in "/home/.../ros_workspace_test/build"
####
[ 14%] Automoc for target draw_on_images
[ 14%] Built target draw_on_images_automoc
Linking CXX executable /home/.../ros_workspace_test/devel/lib/draw_on_images/draw_on_images
CMakeFiles/draw_on_images.dir/src/main.cpp.o: In function `int qmlRegisterType<Draw_on_qimage>(char const*, int, int, char const*)':
main.cpp:(.text._Z15qmlRegisterTypeI14Draw_on_qimageEiPKciiS2_[_Z15qmlRegisterTypeI14Draw_on_qimageEiPKciiS2_]+0x38): undefined reference to `Draw_on_qimage::staticMetaObject'
main.cpp:(.text._Z15qmlRegisterTypeI14Draw_on_qimageEiPKciiS2_[_Z15qmlRegisterTypeI14Draw_on_qimageEiPKciiS2_]+0x1b6): undefined reference to `Draw_on_qimage::staticMetaObject'
CMakeFiles/draw_on_images.dir/src/main.cpp.o: In function `Draw_on_qimage::~Draw_on_qimage()':
main.cpp:(.text._ZN14Draw_on_qimageD2Ev[_ZN14Draw_on_qimageD5Ev]+0x13): undefined reference to `vtable for Draw_on_qimage'
main.cpp:(.text._ZN14Draw_on_qimageD2Ev[_ZN14Draw_on_qimageD5Ev]+0x25): undefined reference to `vtable for Draw_on_qimage'
CMakeFiles/draw_on_images.dir/src/main.cpp.o: In function `QMetaTypeIdQObject<Draw_on_qimage*, true>::qt_metatype_id()':
main.cpp:(.text._ZN18QMetaTypeIdQObjectIP14Draw_on_qimageLb1EE14qt_metatype_idEv[_ZN18QMetaTypeIdQObjectIP14Draw_on_qimageLb1EE14qt_metatype_idEv]+0x2c): undefined reference to `Draw_on_qimage::staticMetaObject'
CMakeFiles/draw_on_images.dir/src/main.cpp.o: In function `QtPrivate::MetaObjectForType<Draw_on_qimage*, true>::value()':
main.cpp:(.text._ZN9QtPrivate17MetaObjectForTypeIP14Draw_on_qimageLb1EE5valueEv[_ZN9QtPrivate17MetaObjectForTypeIP14Draw_on_qimageLb1EE5valueEv]+0x7): undefined reference to `Draw_on_qimage::staticMetaObject'
CMakeFiles/draw_on_images.dir/src/main.cpp.o:(.data.rel.ro._ZTVN11QQmlPrivate11QQmlElementI14Draw_on_qimageEE[_ZTVN11QQmlPrivate11QQmlElementI14Draw_on_qimageEE]+0x10): undefined reference to `Draw_on_qimage::metaObject() const'
CMakeFiles/draw_on_images.dir/src/main.cpp.o:(.data.rel.ro._ZTVN11QQmlPrivate11QQmlElementI14Draw_on_qimageEE[_ZTVN11QQmlPrivate11QQmlElementI14Draw_on_qimageEE]+0x18): undefined reference to `Draw_on_qimage::qt_metacast(char const*)'
CMakeFiles/draw_on_images.dir/src/main.cpp.o:(.data.rel.ro._ZTVN11QQmlPrivate11QQmlElementI14Draw_on_qimageEE[_ZTVN11QQmlPrivate11QQmlElementI14Draw_on_qimageEE]+0x20): undefined reference to `Draw_on_qimage::qt_metacall(QMetaObject::Call, int, void**)'
CMakeFiles/draw_on_images.dir/src/main.cpp.o:(.data.rel.ro._ZTIN11QQmlPrivate11QQmlElementI14Draw_on_qimageEE[_ZTIN11QQmlPrivate11QQmlElementI14Draw_on_qimageEE]+0x10): undefined reference to `typeinfo for Draw_on_qimage'
CMakeFiles/draw_on_images.dir/src/main.cpp.o: In function `Provide_QPixmap_to_QML::~Provide_QPixmap_to_QML()':
main.cpp:(.text._ZN22Provide_QPixmap_to_QMLD2Ev[_ZN22Provide_QPixmap_to_QMLD5Ev]+0x13): undefined reference to `vtable for Provide_QPixmap_to_QML'
main.cpp:(.text._ZN22Provide_QPixmap_to_QMLD2Ev[_ZN22Provide_QPixmap_to_QMLD5Ev]+0x25): undefined reference to `vtable for Provide_QPixmap_to_QML'
CMakeFiles/draw_on_images.dir/src/draw_on_qimage.cpp.o: In function `Draw_on_qimage::Draw_on_qimage(QQuickPaintedItem*)':
draw_on_qimage.cpp:(.text+0x4b): undefined reference to `vtable for Draw_on_qimage'
draw_on_qimage.cpp:(.text+0x5d): undefined reference to `vtable for Draw_on_qimage'
CMakeFiles/draw_on_images.dir/src/provide_qpixmap_to_qml.cpp.o: In function `Provide_QPixmap_to_QML::Provide_QPixmap_to_QML()':
provide_qpixmap_to_qml.cpp:(.text+0x52): undefined reference to `vtable for Provide_QPixmap_to_QML'
provide_qpixmap_to_qml.cpp:(.text+0x64): undefined reference to `vtable for Provide_QPixmap_to_QML'
collect2: error: ld returned 1 exit status
make[2]: *** [/home/.../ros_workspace_test/devel/lib/draw_on_images/draw_on_images] Error 1
make[1]: *** [draw_on_images/CMakeFiles/draw_on_images.dir/all] Error 2
make: *** [all] Error 2
Invoking "make -j4 -l4" failed
How to link Qt 5.9 in ROS?
I am using Ubuntu 14.
Solution was to add the header files to add_executable in CMakelists.txt:
add_executable(${PROJECT_NAME} ${RESOURCES}
src/main.cpp
include/draw_on_images/draw_on_qimage.h src/draw_on_qimage.cpp
include/draw_on_images/provide_qpixmap_to_qml.h src/provide_qpixmap_to_qml.cpp)
My guess is that CMake's AUTOMOC fails in this case. See the documentation here https://cmake.org/cmake/help/v3.0/prop_tgt/AUTOMOC.html
It asserts, that the header file of your class Draw_on_qimage is similarly named as the source file and is locatable by CMake.
You can avoid AUTOMOC by manually running moc on your header for your QObject-derived class like this
QT5_WRAP_CPP(MOC_SOURCES <path of header file of your class Draw_on_qimage>)
add_executable(${PROJECT_NAME} ${RESOURCES} src/main.cpp src/draw_on_qimage.cpp ${MOC_SOURCES} src/provide_qpixmap_to_qml.cpp
Disclaimer: I'm new to cmake so i have no idea what I'm doing.
All guides and tutorials i find seem to think I'm running a 20 man team that needs to work together.
All I'm trying to do is put all my libraries in an include folder and lib folder.
In visual studio and code::blocks i just set up the linker in the IDE, but cmake is a little hard for me to wrap my head around.
I've set include and link directories with
include_directories(${PROJECT_SOURCE_DIR}/include)
link_directories(${PROJECT_SOURCE_DIR}/lib)
Then i try to
target_link_libraries(${PROJECT_NAME} jsoncpp)
This however produces undefined references. Is there a simple way to add and link libraries without me having to google and add a cmake module for each one?
Edit:
attempts:
target_link_libraries(${PROJECT_NAME} libjsoncpp.a)
error: undefined reference
target_link_libraries(${PROJECT_NAME} libjsoncpp)
error: cannot find -llibjsoncpp
target_link_libraries(${PROJECT_NAME} jsoncpp)
error: undefined reference
target_link_libraries(${PROJECT_NAME} C:/Repos/prosjekt-bad-racoon/lib/libjsoncpp.a)
error: undefined reference
target_link_libraries(${PROJECT_NAME} ${PROJECT_SOURCE_DIR}/lib/libjsoncpp.a)
error: undefined reference
Edit:
Full cmake file
cmake_minimum_required(VERSION 3.8)
project(prosjekt_bad_racoon)
set(CMAKE_CXX_STANDARD 11)
include_directories(${PROJECT_SOURCE_DIR}/include)
link_directories(${PROJECT_SOURCE_DIR}/lib)
set(SOURCE_FILES main.cpp Core.cpp Core.h Collider.cpp Collider.h Player.cpp Player.h Texture.cpp Texture.h AudioController.cpp AudioController.h)
add_executable(prosjekt_bad_racoon ${SOURCE_FILES})
set(EXECUTABLE_NAME ${PROJECT_NAME})
set(CMAKE_MODULE_PATH "${CMAKE_SOURCE_DIR}/cmake_modules" ${CMAKE_MODULE_PATH})
target_link_libraries(${PROJECT_NAME} libjsoncpp.a)
find_package(SFML 2 REQUIRED system window graphics network audio)
if(SFML_FOUND)
include_directories(${SFML_INCLUDE_DIR})
target_link_libraries(${EXECUTABLE_NAME} ${SFML_LIBRARIES})
link_directories("${PROJECT_SOURCE_DIR}")
endif()
"C:\Program Files\JetBrains\CLion 2017.2.2\bin\cmake\bin\cmake.exe" --build C:\Repos\prosjekt-bad-racoon\cmake-build-debug --target prosjekt_bad_racoon -- -j 2
[ 14%] Linking CXX executable prosjekt_bad_racoon.exe
CMakeFiles\prosjekt_bad_racoon.dir/objects.a(Core.cpp.obj): In function `ZN4CoreC2Ev':
C:/Repos/prosjekt-bad-racoon/Core.cpp:3: undefined reference to `Json::Value::Value(char const*)'
CMakeFiles\prosjekt_bad_racoon.dir/objects.a(Core.cpp.obj): In function `ZN4CoreD2Ev':
C:/Repos/prosjekt-bad-racoon/Core.cpp:8: undefined reference to `Json::Value::~Value()'
collect2.exe: error: ld returned 1 exit status
CMakeFiles\prosjekt_bad_racoon.dir\build.make:236: recipe for target 'prosjekt_bad_racoon.exe' failed
mingw32-make.exe[3]: *** [prosjekt_bad_racoon.exe] Error 1
CMakeFiles\Makefile2:66: recipe for target 'CMakeFiles/prosjekt_bad_racoon.dir/all' failed
mingw32-make.exe[2]: *** [CMakeFiles/prosjekt_bad_racoon.dir/all] Error 2
CMakeFiles\Makefile2:78: recipe for target 'CMakeFiles/prosjekt_bad_racoon.dir/rule' failed
mingw32-make.exe[1]: *** [CMakeFiles/prosjekt_bad_racoon.dir/rule] Error 2
Makefile:117: recipe for target 'prosjekt_bad_racoon' failed
mingw32-make.exe: *** [prosjekt_bad_racoon] Error 2
I'm just starting to learn how to work with zeromq libraries and using them in different C++ projects.
The sample code that I wrote (actually copied from there tutorials)is this:
// file: main.cpp
// Hello World client in C++
// Connects REQ socket to tcp://localhost:5555
// Sends "Hello" to server, expects "World" back
//
#include <zmq.hpp>
#include <string>
#include <iostream>
int main ()
{
// Prepare our context and socket
zmq::context_t context (1);
zmq::socket_t socket (context, ZMQ_REQ);
std::cout << "Connecting to hello world server…" << std::endl;
socket.connect ("tcp://localhost:5555");
// Do 10 requests, waiting each time for a response
for (int request_nbr = 0; request_nbr != 10; request_nbr++) {
zmq::message_t request (5);
memcpy (request.data (), "Hello", 5);
std::cout << "Sending Hello " << request_nbr << "…" << std::endl;
socket.send (request);
// Get the reply.
zmq::message_t reply;
socket.recv (&reply);
std::cout << "Received World " << request_nbr << std::endl;
}
return 0;
}
and by building the output of this file with the command below:
g++ main.cpp -o test -lzmq
the file will be generated with no problem.
The problem that I have is that I want to build the file using CMake.Thus, I've written a CMakeLists.txt file as below:
cmake_minimum_required(VERSION 3.6)
project(test2)
set(CMAKE_CXX_FLAGS "${CMAKE_CXX_FLAGS} -std=c++11 -lzmq")
set(SOURCE_FILES main.cpp)
add_executable(test2 ${SOURCE_FILES})
The part that I thought will be enough to build the program is -lzmq but even with that piece included, I get the following error messages:
CMakeFiles/test2.dir/main.cpp.o: In function `zmq::error_t::error_t()':
/usr/include/zmq.hpp:62: undefined reference to `zmq_errno'
CMakeFiles/test2.dir/main.cpp.o: In function `zmq::error_t::what() const':
/usr/include/zmq.hpp:66: undefined reference to `zmq_strerror'
CMakeFiles/test2.dir/main.cpp.o: In function `zmq::message_t::message_t()':
/usr/include/zmq.hpp:107: undefined reference to `zmq_msg_init'
CMakeFiles/test2.dir/main.cpp.o: In function `zmq::message_t::message_t(unsigned long)':
/usr/include/zmq.hpp:114: undefined reference to `zmq_msg_init_size'
CMakeFiles/test2.dir/main.cpp.o: In function `zmq::message_t::~message_t()':
/usr/include/zmq.hpp:129: undefined reference to `zmq_msg_close'
CMakeFiles/test2.dir/main.cpp.o: In function `zmq::message_t::data()':
/usr/include/zmq.hpp:180: undefined reference to `zmq_msg_data'
CMakeFiles/test2.dir/main.cpp.o: In function `zmq::context_t::context_t(int)':
/usr/include/zmq.hpp:204: undefined reference to `zmq_init'
CMakeFiles/test2.dir/main.cpp.o: In function `zmq::context_t::~context_t()':
/usr/include/zmq.hpp:225: undefined reference to `zmq_term'
CMakeFiles/test2.dir/main.cpp.o: In function `zmq::socket_t::socket_t(zmq::context_t&, int)':
/usr/include/zmq.hpp:251: undefined reference to `zmq_socket'
CMakeFiles/test2.dir/main.cpp.o: In function `zmq::socket_t::close()':
/usr/include/zmq.hpp:283: undefined reference to `zmq_close'
CMakeFiles/test2.dir/main.cpp.o: In function `zmq::socket_t::connect(char const*)':
/usr/include/zmq.hpp:314: undefined reference to `zmq_connect'
CMakeFiles/test2.dir/main.cpp.o: In function `zmq::socket_t::send(zmq::message_t&, int)':
/usr/include/zmq.hpp:321: undefined reference to `zmq_send'
/usr/include/zmq.hpp:324: undefined reference to `zmq_errno'
CMakeFiles/test2.dir/main.cpp.o: In function `zmq::socket_t::recv(zmq::message_t*, int)':
/usr/include/zmq.hpp:331: undefined reference to `zmq_recv'
/usr/include/zmq.hpp:334: undefined reference to `zmq_errno'
Should I set another kind of variable in the CMake file or have I installed the library in a wrong directory? or is there anything else that I should have mentioned?
and The system witch I'm working on is Ubuntu 14.04
CMake doesn't include direct support for 0mq and 0mq doesn't include direct support for CMake. But, 0mq does support pkg-config and we can use this to help us. Since you mentioned that you're on Ubuntu 14.04, make sure you've done sudo apt-get install libzmq3-dev to install the 0mq libraries, headers, and the pkg-config .pc file.
Then use the following CMakeLists.txt which I've modified from your version above. (I've commented all my changes inline.)
## i have cmake 3.5
cmake_minimum_required(VERSION 3.5)
project(test2)
## use this to globally use C++11 with in our project
set(CMAKE_CXX_STANDARD 11)
## load in pkg-config support
find_package(PkgConfig)
## use pkg-config to get hints for 0mq locations
pkg_check_modules(PC_ZeroMQ QUIET zmq)
## use the hint from above to find where 'zmq.hpp' is located
find_path(ZeroMQ_INCLUDE_DIR
NAMES zmq.hpp
PATHS ${PC_ZeroMQ_INCLUDE_DIRS}
)
## use the hint from above to find the location of libzmq
find_library(ZeroMQ_LIBRARY
NAMES zmq
PATHS ${PC_ZeroMQ_LIBRARY_DIRS}
)
set(SOURCE_FILES main.cpp)
add_executable(test2 ${SOURCE_FILES})
## add the include directory to our compile directives
target_include_directories(test2 PUBLIC ${ZeroMQ_INCLUDE_DIR})
## at the 0mq library to our link directive
target_link_libraries(test2 PUBLIC ${ZeroMQ_LIBRARY})
Now you can make your project.
❯ make
[ 50%] Building CXX object CMakeFiles/test2.dir/main.cpp.o
[100%] Linking CXX executable test2
[100%] Built target test2
If you want to see what's happening under the hood, do a verbose make.
❯ make VERBOSE=1
/usr/bin/cmake -H/home/nega/foo -B/home/nega/foo/build --check-build-system CMakeFiles/Makefile.cmake 0
/usr/bin/cmake -E cmake_progress_start /home/nega/foo/build/CMakeFiles /home/nega/foo/build/CMakeFiles/progress.marks
make -f CMakeFiles/Makefile2 all
make[1]: Entering directory '/home/nega/foo/build'
make -f CMakeFiles/test2.dir/build.make CMakeFiles/test2.dir/depend
make[2]: Entering directory '/home/nega/foo/build'
cd /home/nega/foo/build && /usr/bin/cmake -E cmake_depends "Unix Makefiles" /home/nega/foo /home/nega/foo /home/nega/foo/build /home/nega/foo/build /home/nega/foo/build/CMakeFiles/test2.dir/DependInfo.cmake --color=
make[2]: Leaving directory '/home/nega/foo/build'
make -f CMakeFiles/test2.dir/build.make CMakeFiles/test2.dir/build
make[2]: Entering directory '/home/nega/foo/build'
[ 50%] Building CXX object CMakeFiles/test2.dir/main.cpp.o
/usr/bin/c++ -std=gnu++11 -o CMakeFiles/test2.dir/main.cpp.o -c /home/nega/foo/main.cpp
[100%] Linking CXX executable test2
/usr/bin/cmake -E cmake_link_script CMakeFiles/test2.dir/link.txt --verbose=1
/usr/bin/c++ CMakeFiles/test2.dir/main.cpp.o -o test2 /usr/lib/x86_64-linux-gnu/libzmq.so
make[2]: Leaving directory '/home/nega/foo/build'
[100%] Built target test2
make[1]: Leaving directory '/home/nega/foo/build'
/usr/bin/cmake -E cmake_progress_start /home/nega/foo/build/CMakeFiles 0
If you look at the compile line, you'll notice that
C++11 support was added (with the -std=gnu++11 flag)
There's no -I/path/to/zmq flag. That's because Ubuntu dumps zmq.hpp in to /usr/include and CMake is smart enough to know that is a default path, so it does nothing
If you look at the link line, you'll notice that libzmq.so has been included via it's full path. Some people don't like that (myself included) and prefer -L/lib/dir -lmylib instead. Using the full path is "the CMake way", and you'll actually come to appreciate it as you grow with CMake and use it for larger and more complicated projects (you still might not like it though.)
Also note, that since you're on Ubuntu we could have cheated and used dpkg -L libzmq3-dev to find the locations of the files we're interested in then added them to your original CMAKE_CXX_FLAGS line, but that's cheating and more importantly, not portable.
A cmake config file has been added to libzmq github repository Jan 7, 2017 here.
This is not included in the latest release (4.2.1) yet, but I belive it should be in the next release.
I have installed the head version using cmake and then installed cppzmq, which uses find_package(ZeroMQ REQUIRED) to locate libzmq. All worked like a charm.
EDIT: The cmake config file is included in release 4.2.2 here. Then it was moved to directory builds/cmake at release 4.2.4. I didn't test it again but find_package(ZeroMQ REQUIRED) should just work since ibzmq 4.2.2.
This works as well
cmake_minimum_required(VERSION 3.6)
project(test)
add_executable(c main.cpp)
target_link_libraries(c zmq)