在不同发行版之间有没有什么特性或变化会影响在一个发行版上使用GCC 4.7.x编译的C++二进制文件在另一个发行版上直接使用?我理解理想的情况是在第二个发行版上从源代码编译,但我真的不愿意担心在我的生产机器上编译新的GCC版本和程序源代码。我是一个相对缺乏经验的linux用户(因此才有这个问题!)相对于命令行编译,我仍然更喜欢IDE,ssh是我真正能用来访问生产机器的唯一工具。
代码本身并不有趣,但它确实利用了mill操作系统的一些功能,如阻塞、套接字等。
任何建议都将不胜感激!
发布于 2012-10-19 23:35:12
除非二进制文件构建在完全相同的操作系统(包括版本)的上,并且完全相同的硬件,否则没有保证。
在实践中:
- This is because most people don't turn on the hardware specific optimizations (but they can).
- Moving binaries across chip sets is highly unlikely to work
- Moving binaries from older to newer members of a hardware family is likely to work
- Moving binaries from newer to older members of a hardware family is less likely (but will depend on optimization and compiler settings (ir moving from 64 to 32 bit architecture is unlikely to work).
- The version of OS that a binary will work across will depend on the version of the compiler used to build it and the host OS.
- If the compiler has changes in the ABI it generates then all bets are off. But usually a change in the ABI generated by the compiler will be a major issue and thus only happen at major points in the OS road map (not at minor increments).
- Don't specifically go out and update the development environment (use the one that comes with distribution (if you do the default updates they will not break backwards compatibility)).
- Building is easy just read the `README` file. But usually it involves running two commands `./configure` and `make`. If you don't want anything special you usually do not need to do anything else.
发布于 2012-10-19 23:29:58
G++有一个稳定的ABI已经有很长一段时间了,所以这应该不会造成问题。可能导致问题的是使用动态链接库。运行该程序的系统将需要具有编译可执行文件所依据的任何共享库的兼容版本。如果只使用静态链接,应该不会有问题。您可以使用-static选项打开静态链接。
发布于 2012-10-19 23:31:48
使用静态链接时,必须满足两个条件:
1)目标系统和构建系统必须具有相同的体系结构(有例外:您可以在多个64位主机上运行32位二进制文件)
2)目标系统上的(g)libc包的版本不能比构建系统上的旧(您有时可以通过较小的版本差异逃脱惩罚)
随着动态链接的出现,它变得更加复杂。
https://stackoverflow.com/questions/12977381
复制相似问题