编译 c++ 应用程序,以便它们也可以在其他计算机上工作
因此,我有一个非常简单的 SDL 应用程序,我希望能够将其传递给我的朋友,而无需让他下载一大堆 SDL 软件包。
我该怎么办? 我被告知使用这一行来编译: (请注意,我使用 ubuntu linux,我的朋友也是如此,并且该应用程序在没有“-Wl,-Bstatic”选项的情况下编译和运行就很好。)
g++ test-sdl.cpp -o test-sdl -Wl,-Bstatic -lSDL_image -lSDL
但是然后我收到此错误:
/usr/bin/ld: cannot find -lgcc_s collect2: ld returned 1 exit status
为什么我收到此错误? 我如何解决它? 我什至必须以这种方式这样做吗? 有不同/更简单/替代的方法吗?
我是否要求如此之多,想让我的朋友免去下载他可能永远不会使用的软件包的麻烦?
谢谢。
So I have this very simply SDL application I want to be able to pass to my friend without having him download a whole bunch of SDL packages.
how can I go about this? I was told to use this line to compile:
(note that I use ubuntu linux and so does my friend, and that this application compiles and runs without the "-Wl,-Bstatic" options just fine.)
g++ test-sdl.cpp -o test-sdl -Wl,-Bstatic -lSDL_image -lSDL
But then I get this error:
/usr/bin/ld: cannot find -lgcc_s collect2: ld returned 1 exit status
why am I getting this error? how do I fix it? do I even have to do this in this way? Is there a different/easier/alternative way?
Am I asking for so much by wanting to save my friend the hassle of downloading packages he will probably never use anyway?
Thanks.
如果你对这篇内容有疑问,欢迎到本站社区发帖提问 参与讨论,获取更多帮助,或者扫码二维码加入 Web 技术交流群。
绑定邮箱获取回复消息
由于您还没有绑定你的真实邮箱,如果其他用户或者作者回复了您的评论,将不能在第一时间通知您!
发布评论
评论(2)
从长远来看,您最好的选择是弄清楚如何构建 .debs,然后您朋友的系统的包管理可以负责安装所需的所有依赖项。 如果您想更广泛地分发软件包,按预期使用平台的本机打包系统将为您和您的用户省去很多麻烦。
查看 Ubuntu 的打包和pbuilder。
就我个人而言,我从 Martin Krafft Debian 书籍 中学习了如何为我自己的项目(在 Debian 上)执行此操作,并找到使用 yada 大大简化了流程。
In the long run your best bet would be to figure out how to build .debs and then your friend's system's package management can take care of installing all the dependencies needed. If you want to distribute the packages more widely, using the platform's native packaging system as intended will save you and your users a lot of headaches.
Take a look at Ubuntu's guide to packaging and pbuilder.
Personally, I learned how to do this for my own projects (on Debian) from the Martin Krafft Debian book, and find using yada streamlines the process considerably.
我认为你应该摆脱 -B (这会改变搜索路径,请参阅 man g++,因此你再也找不到你的库了)。
您所说的开关是 -static,没有 B。
编辑回应评论:抱歉,那是不完整的。 相反,将所有“-Wl,-Bstatic”替换为“-static”。
正如 codelogic 所写, -static 不是链接器的选项( -Wl 暗示)。
You should get rid of the -B, I think (this changes the search path, see man g++, and thus you can't find your libraries anymore).
The switch you meant is -static, without the B.
Edit in response to comments: sorry, that was incomplete. Instead, replace all of "-Wl,-Bstatic" with just "-static".
As codelogic wrote, -static is not an option to the linker (which -Wl implies).