问题描述
我已经使用vcpkg安装dlib。
我已经编写了一个使用dlib的C ++程序,我正尝试使用该程序中的cmake在Ubuntu 20.04上构建一个共享库。
我的CMakeLists.txt文件的dlib部分如下所示:
find_package(dlib required)
message(STATUS "Using dlib-${dlib_VERSION}")
当我创建库时,请确保引用dlib::dlib
:
add_library(dlib_jni SHARED src/dlib-jni.cpp)
set_target_properties(dlib_jni PROPERTIES POSITION_INDEPENDENT_CODE ON)
target_link_libraries(dlib_jni dlib::dlib ${DLIB_JNI_THIRDPARTY_LIBS} ${JAVA_JVM_LIBRARY})
我可以做得很好,而且我知道它找到了dlib,因为输出了版本消息:
-- Using dlib-19.21.0
这是我的cmake命令并输出:
$ cmake -DUSE_AVX_INSTRUCTIONS=ON -DCMAKE_TOOLCHAIN_FILE=/home/ubuntu/vcpkg/scripts/buildsystems/vcpkg.cmake ../
-- The C compiler identification is GNU 9.3.0
-- The CXX compiler identification is GNU 9.3.0
-- 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
-- Found OpenCV: /usr/local (found suitable version "3.4.0",minimum required is "3")
-- Looking for pthread.h
-- Looking for pthread.h - found
-- Performing Test CMAKE_HAVE_LIBC_PTHREAD
-- Performing Test CMAKE_HAVE_LIBC_PTHREAD - Failed
-- Looking for pthread_create in pthreads
-- Looking for pthread_create in pthreads - not found
-- Looking for pthread_create in pthread
-- Looking for pthread_create in pthread - found
-- Found Threads: TRUE
-- Using dlib-19.21.0
-- Looking for sgemm_
-- Looking for sgemm_ - not found
-- Looking for sgemm_
-- Looking for sgemm_ - found
-- Found BLAS: /home/ubuntu/vcpkg/installed/x64-linux/debug/lib/libopenblas.a;-lpthread
-- Using blas-
-- Found JNI: /usr/lib/jvm/java-8-openjdk-amd64/jre/lib/amd64/libjawt.so
-- JNI_INCLUDE_Dirs=/usr/lib/jvm/java-8-openjdk-amd64/include;/usr/lib/jvm/java-8-openjdk-amd64/include/linux;/usr/lib/jvm/java-8-openjdk-amd64/include
-- JAVA_INCLUDE_PATH =/usr/lib/jvm/java-8-openjdk-amd64/include
-- JNI_LIBRARIES=/usr/lib/jvm/java-8-openjdk-amd64/jre/lib/amd64/libjawt.so;/usr/lib/jvm/java-8-openjdk-amd64/jre/lib/amd64/server/libjvm.so
-- JAVA_JVM_LIBRARY=/usr/lib/jvm/java-8-openjdk-amd64/jre/lib/amd64/server/libjvm.so
-- Configuring done
-- Generating done
-- Build files have been written to: /home/ubuntu/dlib-jni/build
$ cmake --build . --config Release
Scanning dependencies of target dlib_jni
[ 50%] Building CXX object CMakeFiles/dlib_jni.dir/src/dlib-jni.cpp.o
[100%] Linking CXX shared library libdlib_jni.so
[100%] Built target dlib_jni
我尝试过make
和cmake --build . --config Release
来构建程序。在这两种情况下,当我尝试使用该库时,都会得到相同的结果:
/usr/local/lib/libdlib_jni.so: undefined symbol: USER_ERROR__inconsistent_build_configuration__see_dlib_faq_1_
我已阅读:http://dlib.net/faq.html#WhydoIgetUSERERRORinconsistentbuildconfigurationseedlibfaq1
代码中的注释为:
// ...if you are getting an error here then you are either not enabling DLIB_ASSERT consistently
// (e.g. by compiling part of your program in a debug mode and part in a release mode) or
// you have simply forgotten to compile dlib/all/source.cpp into your application.
根据http://devdoc.net/c/dlib-19.7/compile.html:
If you are using Visual Studio or CMake then ENABLE_ASSERTS will be automatically enabled for you when you compile in debug mode
但是据我所知,我还没有在调试模式下对其进行编译。那么,vcpkg是否这样做?
我不确定自己做错了什么,也不是一个出色的C ++程序员,我似乎无法解决这个问题。
在编译库时如何正确链接dlib使其真正起作用?
感谢您的帮助!
解决方法
暂无找到可以解决该程序问题的有效方法,小编努力寻找整理中!
如果你已经找到好的解决方法,欢迎将解决方案带上本链接一起发送给小编。
小编邮箱:dio#foxmail.com (将#修改为@)