LINUX.ORG.RU

unresolved exteral symbol

 ,


0

1

Добрый вечер! не ругайте сильно, пришлось вот собирать под винду приложение. Создал модель проблемы:

Вот такой код и правила сборки.

#include <iostream>
#include <opencv2/opencv.hpp>
int main(){
    std::cout << "OpenCV Version: " << CV_VERSION << std::endl;
    return 0;
}

cmake_minimum_required(VERSION 3.17)
project(cvtest)
set (CMAKE_CXX_STANDARD 11)
file(GLOB SRCS main.cpp)
set (OpenCV_DIR C:\\Users\\user\\openccv3_build\\bbb)
find_package(OpenCV REQUIRED opencv_core)
message("OpenCV_INCLUDE_DIRS = " ${OpenCV_INCLUDE_DIRS}
        "OpenCV_LIBS = " ${OpenCV_LIBS})
include_directories(${OpenCV_INCLUDE_DIRS})
add_executable(${PROJECT_NAME} ${SRCS} )
target_link_libraries(${PROJECT_NAME} ${OpenCV_LIBS})
echo %PATH%
... C:\Users\user\openccv3_build\bbb\lib\Release; ...
cmake ..
CMake Error: The source directory "C:/Users/user" does not appear to contain CMakeLists.txt.
Specify --help for usage, or press the help button on the CMake GUI.
C:\Users\user\test>
C:\Users\user\test>
C:\Users\user\test>
C:\Users\user\test>
C:\Users\user\test>cmake .
-- Building for: Visual Studio 16 2019
-- Selecting Windows SDK version 10.0.18362.0 to target Windows 10.0.19041.
-- The C compiler identification is MSVC 19.27.29111.0
-- The CXX compiler identification is MSVC 19.27.29111.0
-- Detecting C compiler ABI info
-- Detecting C compiler ABI info - done
-- Check for working C compiler: C:/Program Files (x86)/Microsoft Visual Studio/2019/Community/VC/Tools/MSVC/14.27.29110/bin/Hostx64/x64/cl.exe - skipped
-- Detecting C compile features
-- Detecting C compile features - done
-- Detecting CXX compiler ABI info
-- Detecting CXX compiler ABI info - done
-- Check for working CXX compiler: C:/Program Files (x86)/Microsoft Visual Studio/2019/Community/VC/Tools/MSVC/14.27.29110/bin/Hostx64/x64/cl.exe - skipped
-- Detecting CXX compile features
-- Detecting CXX compile features - done
-- Found OpenCV: C:/Users/user/openccv3_build/bbb (found version "3.4.11") found components: opencv_core
OpenCV_INCLUDE_DIRS = C:/Users/user/openccv3_build/bbbC:/Users/user/openccv3_build/opencv-3.4.11/includeC:/Users/user/openccv3_build/opencv-3.4.11/include/opencvC:/Users/user/openccv3_build/opencv-3.4.11/modules/core/includeC:/Users/user/openccv3_build/opencv-3.4.11/modules/flann/includeC:/Users/user/openccv3_build/opencv-3.4.11/modules/imgproc/includeC:/Users/user/openccv3_build/opencv-3.4.11/modules/ml/includeC:/Users/user/openccv3_build/opencv-3.4.11/modules/photo/includeC:/Users/user/openccv3_build/opencv-3.4.11/modules/video/includeC:/Users/user/openccv3_build/opencv-3.4.11/modules/dnn/includeC:/Users/user/openccv3_build/opencv-3.4.11/modules/features2d/includeC:/Users/user/openccv3_build/opencv-3.4.11/modules/imgcodecs/includeC:/Users/user/openccv3_build/opencv-3.4.11/modules/shape/includeC:/Users/user/openccv3_build/opencv-3.4.11/modules/videoio/includeC:/Users/user/openccv3_build/opencv-3.4.11/modules/calib3d/includeC:/Users/user/openccv3_build/opencv-3.4.11/modules/highgui/includeC:/Users/user/openccv3_build/opencv-3.4.11/modules/objdetect/includeC:/Users/user/openccv3_build/opencv-3.4.11/modules/stitching/includeC:/Users/user/openccv3_build/opencv-3.4.11/modules/superres/includeC:/Users/user/openccv3_build/opencv-3.4.11/modules/ts/includeC:/Users/user/openccv3_build/opencv-3.4.11/modules/videostab/includeC:/Users/user/openccv3_build/opencv_contrib-3.4.11/modules/bioinspired/includeOpenCV_LIBS = opencv_core
-- Configuring done
-- Generating done
-- Build files have been written to: C:/Users/user/test

Ну и проблема

C:\Users\user\test>cmake --build .
Microsoft (R) Build Engine version 16.7.0+b89cb5fde for .NET Framework
Copyright (C) Microsoft Corporation. All rights reserved.
  Checking Build System
  Building Custom Rule C:/Users/user/test/CMakeLists.txt
  main.cpp
main.obj : error LNK2019: unresolved external symbol "private: void __cdecl cv::String::deallocate(void)" (?dealloc
ate@String@cv@@AEAAXXZ) referenced in function "public: __cdecl cv::String::~String(void)" (??1String@cv@@QEAA@XZ)
[C:\Users\user\test\cvtest.vcxproj]
C:\Users\user\test\Debug\cvtest.exe : fatal error LNK1120: 1 unresolved externals [C:\Users\user\test\cvtes
t.vcxproj]

Под Windows – за деньги помогу, пишите в контакты в профиле.

EXL ★★★★★ ()

Вариант решения, может кому пригодится. Собрать Visual Studio, для этого в настройках проекта

  1. VC++/Include Directories добавить путь к заголовочным файлам, для cv это каталог opencv/build/install/include.

  2. VC++/Library Directories добавить путь к *lib, это opencv/build/install/x64/cv16/lib

странно, но в линковщик ничего добавлять не пришлось

cvprog ()
Ответ на: комментарий от cvprog

В более сложной программе потребуется настраивать линковщик.

#include <iostream>
#include <opencv2/opencv.hpp>
int main()
{
    cv::Mat mat = cv::imread("test.png");
    cv::imshow("test", mat);
    cv::waitKey();
    return 0;
}

3. Linker/Input/Additional Dependencies/Edit просто указать имена библиотек

opencv_core440.lib
opencv_imgproc440.lib
opencv_imgcodecs440.lib
opencv_highgui440.lib

Чтобы приложение запустилось, нужны dll-ки. Их можно скопировать в каталог с exe-шником.

P.S. Ну вот, Линуксовый/ОпенСорсный код работает и в Винду.

cvprog ()
Для того чтобы оставить комментарий войдите или зарегистрируйтесь.