简体   繁体   English

在这种情况下如何调试动态库

[英]How debug dynamic library in such situation

Well, I am new to CMake. 好吧,我是CMake的新手。 I have the following file structure 我有以下文件结构

    haze_removal
    |---build
    |---bin
    |    |--Test
    |    |--CMakeLists.txt
    |---lib
    |    |--libtools.so
    |---include
    |    |--tools.hpp
    |---test
    |    |--main.cpp
    |    |--CMakeLists.txt
    |---src
    |    |--tools.cpp
    |    |--CMakeLists.txt
    |---CMakeLists.txt

The libtools.so is builded from ../src/tools.cpp . libtools.so是从../src/tools.cpp I build the whole project in ../build using the following cmake command: cmake -DCMAKE_BUILD_TYPE=Debug .. make The Test is build from ../test/main.cpp I build this project successfully. 我使用以下cmake命令在../build构建整个项目: cmake -DCMAKE_BUILD_TYPE=Debug .. make测试是从../test/main.cpp构建的,我已成功构建了此项目。 But when I debug Test using gdb ./Test , I can't skip in the function that from libtools.so. 但是,当我使用gdb ./Test调试Test时,无法跳过libtools.so中的功能。 These are my CMakeLists.txt from different directories. 这些是我来自不同目录的CMakeLists.txt

CMakeLists.txt under haze_removal/ haze_removal/下的CMakeLists.txt

    cmake_minimum_required(VERSION 2.8)
    project(haze_removal)

    # find needed package
    find_package(OpenCV REQUIRED)

    # library directory
    add_subdirectory(src)

    # test
    add_subdirectory(test)

CMakeLists.txt under ../src/ ../src/下的CMakeLists.txt

    # generate dynamic library
    # add source file, include directories
    aux_source_directory(. TOOLS_SRC)
    include_directories(${PROJECT_SOURCE_DIR}/include)

    # generate
    add_library(tools SHARED ${TOOLS_SRC})

    # set output directory and lib's name
    set(LIBRARY_OUTPUT_PATH ${PROJECT_SOURCE_DIR}/lib)
    set_target_properties(tools PROPERTIES OUTPUT_NAME "tools")

    # link library
    target_link_libraries(tools ${OpenCV_LIBS})

CMakeLists.txt under ../test/ ../test/下的CMakeLists.txt

    # add source file, include directories, link directories
    aux_source_directory(. EXE_SRC)
    include_directories(${PROJECT_SOURCE_DIR}/include)
    link_directories(${PROJECT_SOURCE_DIR}/lib)

    # generate
    add_executable(Test ${EXE_SRC})

    # set output directory
    set(EXECUTABLE_OUTPUT_PATH ${PROJECT_SOURCE_DIR}/bin)

    # link libraries
    target_link_libraries(Test ${OpenCV_LIBS} libtools.so)

My question is how I can debug the functions that from libtools. 我的问题是如何调试libtools中的功能。

Well, I find that why I can't step in the dynamic library even though I set CMAKE_BUILD_TYPE=Debug . 好吧,我发现即使设置了CMAKE_BUILD_TYPE=Debug也为什么不能进入动态库。 Because before I set the build model to Debug I used to set CMAKE_BUILD_TYPE=Release . 因为在将构建模型设置为Debug之前,我曾设置CMAKE_BUILD_TYPE=Release After I change the build model, I didn't delete the files in the build directory. 更改构建模型后,没有删除build目录中的文件。

I don't know whether the above explanation is right or not, but I do solve my problem. 我不知道上面的解释是否正确,但是我确实解决了我的问题。

Thx! 谢谢!

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM