Closed HeloWong closed 2 months ago
Here is my CMakeLists.txt and Test Code comparison with OpenCV Framework And OpenCV works fine.
cmake_minimum_required(VERSION 3.10)
project(hello_cv LANGUAGES CXX)
set(OpenCV_DIR "3rd_party")
find_library(
opencv
NAMES opencv2
PATHS ${OpenCV_DIR}/
)
if (${opencv} MATCHES opencv-NOTFOUND)
message(STATUS " Can't find opencv in ${OpenCV_DIR}")
else()
message(STATUS " found ${opencv}")
endif()
set(MNN_DIR "./3rd_party/MNN-2.9.0/Static")
find_library(
mnn
NAMES MNN
PATHS ${MNN_DIR}/
)
if (${mnn} MATCHES mnn-NOTFOUND)
message(STATUS " Can't find mnn in ${MNN_DIR}")
else()
message(STATUS " found ${mnn}")
endif()
add_executable(${PROJECT_NAME} main.cc)
set_target_properties(${PROJECT_NAME} PROPERTIES
CXX_STANDARD 14)
target_link_libraries(${PROJECT_NAME}
${opencv}
${mnn}
)
target_include_directories(${PROJECT_NAME}
PUBLIC ${OpenCV_DIR}/opencv2.framework/Headers
PUBLIC ${MNN_DIR}/MNN.framework/Headers
)
#include <iostream>
#include "opencv2/opencv.hpp"
#include "MNN/Interpreter.hpp"
int main()
{
std::cout << cv::getVersionString() << std::endl;
std::cout << MNN::getVersion() << std::endl;
return 0;
}
Add this in Your CMakeLists.txt: find_library(FOUNDATION Foundation) target_link_libraries(${You_lib} PUBLIC ${FOUNDATION})
See MNN's CMakeLists.txt 735-741 line:
find_library(FOUNDATION Foundation REQUIRED)
target_link_libraries(MNN PUBLIC ${FOUNDATION})
find_library(METAL Metal REQUIRED)
target_link_libraries(MNN PUBLIC ${METAL})
find_library(GRAPHIC CoreGraphics)
target_link_libraries(MNN PUBLIC ${GRAPHIC})
Thank you, it works
...
find_library(FOUNDATION Foundation)
find_library(METAL Metal REQUIRED)
find_library(GRAPHIC CoreGraphics)
target_link_libraries(${You_lib}
PUBLIC ${FOUNDATION}
PUBLIC ${METAL}
PUBLIC ${GRAPHIC}
)
Platform(Include target platform as well if cross-compiling): MacOS with M2
Github Version: 2.9.0
it happened when use
release/mnn_2.9.0_macos_x64_arm82_cpu_opencl_metal.zip
and link it with-framework MNN
Undefined symbols for architecture arm64: [build] "_CFRelease", referenced from: [build] MNN::MetalRuntime::create(MNN::Backend::Info const&, id) in MNN[arm64]355
[build] MNN::MetalRuntime::~MetalRuntime() in MNN[arm64]355
[build] "_MTLCreateSystemDefaultDevice", referenced from:
...
MNN::Pipeline::_pushTuningTask(std::1::vector<MNN::Schedule::OpCacheInfo, std::1::allocator>&&) in MNN[arm64]12
[build] MNN::ThreadPool::ThreadPool(int) in MNN[arm64]222
[build] "std::1::ctype::id", referenced from:
[build] std:: 1::basic_ostream<char, std::1::char_traits>& std::1::put_character_sequence[abi:un170006]<char, std::__1::char_traits>(std:: 1::basic_ostream<char, std::__1::char_traits>&, char const, unsigned long) in MNN[arm64]352
[build] "std::__1::mutex::lock()", referenced from:
[build] MNN::Interpreter::updateCacheFile(MNN::Session, int) in MNN[arm64]9
Has anyone encountered a similar situation? Could you give me some help?