我正在使用 C++ 开发一个简单的命令行工具。一半作为一个有趣的学习过程,一半分发给朋友/同事等。
我认为使其可分发的最简单方法就是将源代码与安装脚本一起打包——任何人都可以给我指一个好的教程吗?设置那个?
换句话说,脚本必须包含哪些内容才能编译程序、将文件放在合适的位置*并使其可以从命令行的任何目录执行?
-
- 例如,我知道编译后的二进制文件应该放在 /usr/local/bin/ 中,但是如果我正在写入和访问文本文件(例如),那么它应该放在哪里?存储设置/配置参数的文件怎么样?
我使用的是 mac osx,所以这将是一个起点,但到 windows、linux 等的可移植性会很棒。
I'm working on a simple command line tool in c++. Half as a fun learning-process thing, and half to distribute to friends/colleagues etc.
I assume the easiest way to make it distributable is just packaging the source code with an installation script---can anyone point me to a good tutorial for setting that up?
In other words, what must a script include to compile the program, put the files in good places*, and make it executable from any directory from the command line?
-
- E.g. I know the compiled binary should go in /usr/local/bin/ , but if I'm writing-to and accessing a text file (for instance), where should that go? What about a file that stores settings/configuration-parameters?
I'm on mac osx, so that would be the starting point, but portability to windows, linux, etc would be great.
发布评论
评论(2)
您可以使用CMake来制作跨平台构建系统,并且可以使用它的CPack (Wiki 此处)功能,以便生成纯二进制包。首先,您创建一个在每个平台上运行和安装的构建脚本(CMake 使该脚本变得像预期的那样简单)。然后,您运行 CPack 以生成仅包含二进制文件的包。
这里有一个很好的教程,涵盖了基本的 cmake 过程(包括安装命令) 。
CMake 通常被认为比 autoconf 更简单(并且具有更好的 Windows 支持),但每个都有自己的优点。
You can use CMake to make a cross platform build system, and you can use it's CPack (Wiki here) feature in order to generate binary only packages. First you create a build script that runs and installs on each platform (which CMake makes as easy as can be expected). You then run CPack to generate a package which just includes your binaries.
There is a good tutorial that covers the basic cmake process (including install commands) here.
CMake is generally considered simpler then autoconf (and has better windows support), but each has it's own strengths.
不要假设安装该程序的用户具有 root 访问权限。提示或提供命令行选项(例如 --install-prefix=/home/user/apps)来指定安装位置。
我讨厌在 /usr/local 中安装垃圾的程序。如果您这样做,最好将其包装在 .rpm 或 .deb 或任何平台包中,以便可以干净地卸载您的应用程序。
我建议查看 autoconf
Do not assume that the user installing the program has root access. Prompt, or provide a command-line option, like --install-prefix=/home/user/apps, to specify where to install.
I HATE programs that install shit in /usr/local. If you do that, you'd best wrap it up in an .rpm or .deb or whatever the platform package is so that your app can be cleanly uninstalled.
I would suggest checking out autoconf