我可以检索使用Conan软件包管理器打包的库的源代码,以便能够在其中进行调试吗?

时间:2022-01-18 23:02:12

Typically Conan package contains only build artifacts like *.dll, *.lib, *.pdb, *.so, *.a, *.dylib files as well headers of given C or C++ library. However sometimes when you debugging your code consuming the library is very useful to be able to step into the library code to look what happens inside. For example to determine when having some problem whether this is because of incorrect use of the library or because of bug in it.

通常,Conan包只包含构建工件,如* .dll,* .lib,* .pdb,* .so,* .a,* .dylib文件以及给定C或C ++库的标头。但是,有时当您调试代码时,使用库对于能够进入库代码以查看内部发生的情况非常有用。例如,确定何时出现问题,这是因为库的使用不正确还是因为库中存在错误。

  1. Is it possible alongside package which you consume to retrieve the source code from which it is build to be able to debug in it?
  2. 是否可以与您使用的包一起检索构建它的源代码以便能够在其中进行调试?

  3. If this is not possible for arbitrary package whether it is possible to create such package by yourself?
  4. 如果这对于任意包装是不可能的,是否可以自己创建这样的包装?

1 个解决方案

#1


3  

There are two strategies that might work to debug dependencies:

有两种策略可用于调试依赖项:

  • Forcing it to build from sources, with the --build=PkgName argument. When you build from sources the package, depending on the build system, it is possible that the binary artifacts reference the temporary build folder where the package was built, and then be able to find them and use the to debug. This strategy can work for third party packages, even when they do not consider debug.
  • 使用--build = PkgName参数强制它从源构建。当您从源代码构建包时,根据构建系统,二进制工件可能会引用构建包的临时构建文件夹,然后能够找到它们并使用它来进行调试。即使不考虑调试,此策略也适用于第三方软件包。

  • If you are creating the packages yourself, and you want to be able to directly debug the binary artifact, without re-building it from source, then the correct way would be to package the sources too. If the debugger needs some help to locate those sources, then it should be used.
  • 如果您自己创建包,并且希望能够直接调试二进制工件,而无需从源代码重新构建它,那么正确的方法是打包源。如果调试器需要一些帮助来定位这些源,那么应该使用它。

With gdb you could do something like

使用gdb你可以做类似的事情

def build(self):
    cmake = CMake(self.settings)
    gcc_dbg_src = ""
    if self.settings.compiler == "gcc" and self.settings.build_type == "Debug":
        gcc_dbg_src =  ' -DCMAKE_CXX_FLAGS="-fdebug-prefix-map=%s/hello=src"' % os.getcwd()
    self.run('cmake hello %s %s' % (cmake.command_line, gcc_dbg_src))
    self.run("cmake --build . %s" % cmake.build_config)

def package(self):
    self.copy("*.h", dst="include", src="hello")
    if self.settings.build_type == "Debug":
        self.copy("*.cpp", dst="src", src="hello")
    self.copy("*.lib", dst="lib", keep_path=False)
    self.copy("*.a", dst="lib", keep_path=False)

To make sure that you compile with the right flags, and also that the source files are packaged too. Then, in the consumer side, you might want to imports the .cpp files, so the gdb debugger can find them besides the binary being debug, or play with your debugger path to add the package folder.

确保使用正确的标志进行编译,并确保源文件也已打包。然后,在消费者方面,您可能想要导入.cpp文件,因此除了正在调试的二进制文件之外,gdb调试器还可以找到它们,或者使用调试器路径来添加包文件夹。

In Windows, with Visual Studio, you probably want to package the .pdb files

在Windows中,使用Visual Studio,您可能希望打包.pdb文件

#1


3  

There are two strategies that might work to debug dependencies:

有两种策略可用于调试依赖项:

  • Forcing it to build from sources, with the --build=PkgName argument. When you build from sources the package, depending on the build system, it is possible that the binary artifacts reference the temporary build folder where the package was built, and then be able to find them and use the to debug. This strategy can work for third party packages, even when they do not consider debug.
  • 使用--build = PkgName参数强制它从源构建。当您从源代码构建包时,根据构建系统,二进制工件可能会引用构建包的临时构建文件夹,然后能够找到它们并使用它来进行调试。即使不考虑调试,此策略也适用于第三方软件包。

  • If you are creating the packages yourself, and you want to be able to directly debug the binary artifact, without re-building it from source, then the correct way would be to package the sources too. If the debugger needs some help to locate those sources, then it should be used.
  • 如果您自己创建包,并且希望能够直接调试二进制工件,而无需从源代码重新构建它,那么正确的方法是打包源。如果调试器需要一些帮助来定位这些源,那么应该使用它。

With gdb you could do something like

使用gdb你可以做类似的事情

def build(self):
    cmake = CMake(self.settings)
    gcc_dbg_src = ""
    if self.settings.compiler == "gcc" and self.settings.build_type == "Debug":
        gcc_dbg_src =  ' -DCMAKE_CXX_FLAGS="-fdebug-prefix-map=%s/hello=src"' % os.getcwd()
    self.run('cmake hello %s %s' % (cmake.command_line, gcc_dbg_src))
    self.run("cmake --build . %s" % cmake.build_config)

def package(self):
    self.copy("*.h", dst="include", src="hello")
    if self.settings.build_type == "Debug":
        self.copy("*.cpp", dst="src", src="hello")
    self.copy("*.lib", dst="lib", keep_path=False)
    self.copy("*.a", dst="lib", keep_path=False)

To make sure that you compile with the right flags, and also that the source files are packaged too. Then, in the consumer side, you might want to imports the .cpp files, so the gdb debugger can find them besides the binary being debug, or play with your debugger path to add the package folder.

确保使用正确的标志进行编译,并确保源文件也已打包。然后,在消费者方面,您可能想要导入.cpp文件,因此除了正在调试的二进制文件之外,gdb调试器还可以找到它们,或者使用调试器路径来添加包文件夹。

In Windows, with Visual Studio, you probably want to package the .pdb files

在Windows中,使用Visual Studio,您可能希望打包.pdb文件