我试图在Capstone上的C++项目中使用Ubuntu反汇编框架。 I ran the following command to install the development package

sudo apt-get install libcapstone-dev


这在/usr/include/capstone中安装了include,但是当我尝试使用#include <capstone/capstone.h> include编译我的应用程序时,出现链接器错误:

undefined reference to `cs_open'
undefined reference to `cs_disasm'
undefined reference to `cs_free'
undefined reference to `cs_close'


这些都是应该在libcapstone.so中实现的功能。

实际上,libcapstone.so文件夹中没有/usr/lib

ubuntu@DESKTOP:/usr/lib$ ls
accountsservice    emacsen-common         libguestlib.so.0      networkd-dispatcher   software-properties
apt                environment.d          libguestlib.so.0.0.0  open-vm-tools         ssl
bfd-plugins        file                   libhgfs.so.0          openssh               sudo
binfmt-support     gcc                    libhgfs.so.0.0.0      os-release            sysctl.d
binfmt.d           git-core               libpsm1               pkg-config.multiarch  systemd
byobu              gnupg                  libvgauth.so.0        pkgconfig             sysusers.d
clang              gnupg2                 libvgauth.so.0.0.0    pm-utils              tar
cloud-init         gold-ld                libvmtools.so.0       policykit-1           tc
cnf-update-db      groff                  libvmtools.so.0.0.0   python2.7             tmpfiles.d
command-not-found  initcpio               llvm-6.0              python3               ubuntu-release-upgrader
compat-ld          initramfs-tools        locale                python3.6             update-notifier
dbus-1.0           kernel                 lxcfs                 python3.7             valgrind
debug              klibc                  lxd                   rsyslog               x86_64-linux-gnu
dpkg               language-selector      man-db                sasl2
dracut             libDeployPkg.so.0      mime                  sftp-server
eject              libDeployPkg.so.0.0.0  modules-load.d        snapd


sudo apt-get install libcapstone2不起作用,因为找不到该包。

是否需要安装其他软件包,或者CMake是否有一些简单的find_package() Capstone?我发现的资源似乎不足以使Capstone设置链接到它/将其包含在项目中。

编辑:
libcapstone-dev软件包安装的文件是:

$ dpkg-query -L libcapstone-dev
/.
/usr
/usr/include
/usr/include/capstone
/usr/include/capstone/arm.h
/usr/include/capstone/arm64.h
/usr/include/capstone/capstone.h
/usr/include/capstone/mips.h
/usr/include/capstone/platform.h
/usr/include/capstone/ppc.h
/usr/include/capstone/sparc.h
/usr/include/capstone/systemz.h
/usr/include/capstone/x86.h
/usr/include/capstone/xcore.h
/usr/lib
/usr/lib/x86_64-linux-gnu
/usr/lib/x86_64-linux-gnu/libcapstone.a
/usr/lib/x86_64-linux-gnu/pkgconfig
/usr/lib/x86_64-linux-gnu/pkgconfig/capstone.pc
/usr/share
/usr/share/doc
/usr/share/doc/libcapstone-dev
/usr/share/doc/libcapstone-dev/CREDITS.TXT
/usr/share/doc/libcapstone-dev/HACK.TXT
/usr/share/doc/libcapstone-dev/README
/usr/share/doc/libcapstone-dev/TODO
/usr/share/doc/libcapstone-dev/copyright
/usr/lib/x86_64-linux-gnu/libcapstone.so
/usr/share/doc/libcapstone-dev/changelog.Debian.gz

最佳答案

Capstone似乎提供了pkg-config .pc文件。因此,以下应工作:

include(FindPkgConfig)

pkg_check_modules (CAPSTONE REQUIRED capstone)

# Use CAPSTONE_FOUND, CAPSTONE_LIBRARIES, CAPSTONE_INCLUDE_DIRS vars
target_link_libraries(${PROJECT_NAME} ${CAPSTONE_LIBRARIES})

关于c++ - 如何使用CMake与Capstone链接?,我们在Stack Overflow上找到一个类似的问题:https://stackoverflow.com/questions/58495333/

10-09 19:32