我已经为 linux 启动了一个 C++ SFML 项目。我想知道.so应该去哪里。他们是否应该进入项目文件夹,以便用户在获得程序后可以简单地运行程序?或者用户在运行我的程序之前是否应该在 linux 机器上安装 SFML 库?
3 回答
Even if you did include the .so
files, you have no guarantee that the user will be able to run it (different architecture, libraries linked against different libc, ...). Either link statically, or better yet, just let them provide the supporting libraries themselves.
@Joel J. Adamson's answer to use autoconf
is a good idea. SFML doesn't come with a pkg-config
file, so you will check for SFML as follows:
dnl Checking for a C++ compiler
AC_PROG_CXX
dnl Checking C++ features. This tells configure to use the C++ compiler for checks.
AC_LANG_PUSH([C++])
dnl Check for a SFML header.
AC_CHECK_HEADER([SFML/Config.hpp], [], [AC_MSG_ERROR([SFML headers not found.])])
AC_LANG_POP([C++])
Checking for the libraries is a bit more difficult because of name mangling and so on. Tyler McHenry wrote a good article on this part, if you want to be thorough.
在分发级别,SFML 将是一个依赖项,即用户必须在编译程序之前安装它(或者他们的包管理器必须安装它)。如果用户想要编译它,他们还需要头文件(通常有一个单独的“开发”包要安装)。您不必分发.so
文件,如果您不这样做,(对每个人来说)可能会更好。
您将需要检查用户是否拥有它,例如使用autoconf您需要检查configure.ac
应用程序项目中的相关标题。例如,要检查数学库,因为我正在使用该exp()
函数,所以我将使用
AC_CHECK_LIB([m], [exp])
configure
在该步骤中创建检查。幸运的是autoscan
,可以为您检查并创建一个configure.ac
名为configure.scan
. 另请参阅Cmake。
HTH。
您应该使您的程序依赖于它需要的特定库(和版本)。如果您打算将其打包到 rpm/deb 文件中,您也应该在其中添加依赖项,以便包管理器可以检查和应用它(例如,apt 可以安装给定包的所有依赖包)