I downloaded CMake and OpenCV using homebrew, I am trying to run a simple openCV program that opens my camera and starts to stream a video. I can compile my program regularly using the command line with: clang++ -std=c++11 mvu_lib_cpp.cpp -o execute 'pkg-config --cflags --libs opencv4'
However when I try to build and compile my project using CMake I am running into trouble and errors.
Script:
#!/bin/bash
SDK=/Users/Iftach/Library/Android/sdk
CMAKE=$SDK/cmake/3.18.1/bin/cmake
NDK=$SDK/ndk/23.0.7272597
TOOLCHAIN_FILE=$NDK/build/cmake/android.toolchain.cmake
TOOLCHAIN_BINARIES=$NDK/toolchains/llvm/prebuilt/darwin-x86_64/bin
LD=$TOOLCHAIN_BINARIES/ld
ABI=arm64-v8a
MIN_SDK=16
STL=c++_shared
STD=-std=c++11 -o
CXX=$TOOLCHAIN_BINARIES/aarch64-linux-android30-clang++
CMAKE_ARGS=""
export CXX=$CXX
$CMAKE -DCMAKE_CXX_FLAGS=$STD -DCMAKE_TOOLCHAIN_FILE=$TOOLCHAIN_FILE -DANDROID_ABI=$ABI -DANDROID_NATIVE_API_LEVEL=$MIN_SDK -DANDROID_STL=$STL $CMAKE_ARGS
CMakeLists.txt:
cmake_minimum_required(VERSION 3.7 FATAL_ERROR)
project(mvu_shared_library_cpp VERSION 1.0.0 LANGUAGES CXX)
set(OpenCV_DIR "/usr/local/Cellar/opencv/4.5.2_1/lib/cmake/opencv4")
find_package(OpenCV REQUIRED)
include_directories(${OpenCV_INCLUDE_DIRS})
add_library(mvu_shared_library_cpp SHARED mvu_lib_cpp.cpp mvu_cpp.def)
add_executable(mvu_cpp_exec mvu_lib_cpp.cpp)
target_link_libraries( mvu_shared_library_cpp ${OpenCV_LIBS} )
set_target_properties(mvu_shared_library_cpp PROPERTIES
PUBLIC_HEADER mvu_lib_cpp.h
VERSION ${PROJECT_VERSION}
SOVERSION 1
OUTPUT_NAME "mvu_cpp"
XCODE_ATTRIBUTE_CODE_SIGN_IDENTITY "MacOS_ID"
)
For some reason I am getting a linkage problem, the script runs smoothly but when running make
I am getting an error in the middle of the build
script output:
./create_mvu_makefile.sh: line 12: -o: command not found
CMake Warning:
No source or binary directory provided. Both will be assumed to be the
same as the current working directory, but note that this warning will
become a fatal error in future CMake releases.
CMake Warning at /Users/Iftach/Library/Android/sdk/ndk/23.0.7272597/build/cmake/android-legacy.toolchain.cmake:416 (message):
An old version of CMake is being used that cannot automatically detect
compiler attributes. Compiler identification is being bypassed. Some
values may be wrong or missing. Update to CMake 3.19 or newer to use
CMake's built-in compiler identification.
Call Stack (most recent call first):
/Users/Iftach/Library/Android/sdk/ndk/23.0.7272597/build/cmake/android.toolchain.cmake:55 (include)
/Users/Iftach/Library/Android/sdk/cmake/3.18.1/share/cmake-3.18/Modules/CMakeDetermineSystem.cmake:93 (include)
CMakeLists.txt:3 (project)
-- Detecting CXX compiler ABI info
CMake Warning at /Users/Iftach/Library/Android/sdk/ndk/23.0.7272597/build/cmake/android-legacy.toolchain.cmake:416 (message):
An old version of CMake is being used that cannot automatically detect
compiler attributes. Compiler identification is being bypassed. Some
values may be wrong or missing. Update to CMake 3.19 or newer to use
CMake's built-in compiler identification.
Call Stack (most recent call first):
/Users/Iftach/Library/Android/sdk/ndk/23.0.7272597/build/cmake/android.toolchain.cmake:55 (include)
/Users/Iftach/Desktop/CPP/CMakeFiles/3.18.1-g262b901/CMakeSystem.cmake:6 (include)
/Users/Iftach/Desktop/CPP/CMakeFiles/CMakeTmp/CMakeLists.txt:2 (project)
-- Detecting CXX compiler ABI info - done
-- Check for working CXX compiler: /Users/Iftach/Library/Android/sdk/ndk/23.0.7272597/toolchains/llvm/prebuilt/darwin-x86_64/bin/clang++ - skipped
-- Detecting CXX compile features
-- Detecting CXX compile features - done
-- Found OpenCV: /usr/local/Cellar/opencv/4.5.2_1 (found version "4.5.2")
-- Configuring done
-- Generating done
-- Build files have been written to: /Users/Iftach/Desktop/CPP
error output:
Scanning dependencies of target mvu_cpp_exec
[ 25%] Building CXX object CMakeFiles/mvu_cpp_exec.dir/mvu_lib_cpp.cpp.o
[ 50%] Linking CXX executable mvu_cpp_exec
ld: error: undefined symbol: cv::VideoCapture::VideoCapture(int, int)
>>> referenced by mvu_lib_cpp.cpp:22
>>> CMakeFiles/mvu_cpp_exec.dir/mvu_lib_cpp.cpp.o:(startVideo)
ld: error: undefined symbol: cv::VideoCapture::isOpened() const
>>> referenced by mvu_lib_cpp.cpp:23
>>> CMakeFiles/mvu_cpp_exec.dir/mvu_lib_cpp.cpp.o:(startVideo)
ld: error: undefined symbol: cv::Mat::Mat()
>>> referenced by mvu_lib_cpp.cpp:27
>>> CMakeFiles/mvu_cpp_exec.dir/mvu_lib_cpp.cpp.o:(startVideo)
ld: error: undefined symbol: cv::VideoCapture::operator>>(cv::Mat&)
>>> referenced by mvu_lib_cpp.cpp:28
>>> CMakeFiles/mvu_cpp_exec.dir/mvu_lib_cpp.cpp.o:(startVideo)
ld: error: undefined symbol: cv::imshow(std::__ndk1::basic_string<char, std::__ndk1::char_traits<char>, std::__ndk1::allocator<char> > const&, cv::_InputArray const&)
>>> referenced by mvu_lib_cpp.cpp:29
>>> CMakeFiles/mvu_cpp_exec.dir/mvu_lib_cpp.cpp.o:(startVideo)
ld: error: undefined symbol: cv::waitKey(int)
>>> referenced by mvu_lib_cpp.cpp:31
>>> CMakeFiles/mvu_cpp_exec.dir/mvu_lib_cpp.cpp.o:(startVideo)
ld: error: undefined symbol: cv::Mat::~Mat()
>>> referenced by mvu_lib_cpp.cpp:33
>>> CMakeFiles/mvu_cpp_exec.dir/mvu_lib_cpp.cpp.o:(startVideo)
>>> referenced by mvu_lib_cpp.cpp:33
>>> CMakeFiles/mvu_cpp_exec.dir/mvu_lib_cpp.cpp.o:(startVideo)
ld: error: undefined symbol: cv::VideoCapture::~VideoCapture()
>>> referenced by mvu_lib_cpp.cpp:36
>>> CMakeFiles/mvu_cpp_exec.dir/mvu_lib_cpp.cpp.o:(startVideo)
>>> referenced by mvu_lib_cpp.cpp:36
>>> CMakeFiles/mvu_cpp_exec.dir/mvu_lib_cpp.cpp.o:(startVideo)
clang++: error: linker command failed with exit code 1 (use -v to see invocation)
make[2]: *** [mvu_cpp_exec] Error 1
make[1]: *** [CMakeFiles/mvu_cpp_exec.dir/all] Error 2
make: *** [all] Error 2
Aucun commentaire:
Enregistrer un commentaire