C++ Qt:静态构建和外部 dylib
我在个人项目中使用 Qt 做了一些有趣的事情。我不是这方面的专家,所以如果这是一个愚蠢的问题(我猜不是我找不到任何有用的东西),请随意杀了我。
无论如何,我在 OSX 中,通常我使用带有以下命令的 shell 脚本针对 Qt 的静态版本编译最终版本:
cd "project folder...";
PATH=/Users/TCB13/(...)/qt-source/bin:$PATH; --> Path to my static QT.
export PATH;
qmake -config release;
make;
make clean;
到目前为止,如果我将编译的二进制文件移动到另一台没有安装 Qt 的计算机上,一切都正常! ;)
昨天,我开始使用一家公司提供的动态库,并将 dylib 包含在我的 .pro 文件中,如下所示:(我在项目文件夹中有一个 dylib 的副本)
#macx: LIBS += -L$$PWD/ -lwpsapi
#INCLUDEPATH += $$PWD/
#DEPENDPATH += $$PWD/
当我编译它时“静态”(使用上面的命令)并在我得到的另一台计算机上运行它:
dyld: Library not loaded: @executable_path/libwpsapi.dylib
Referenced from: /Users/TCB13/Desktop/dude111
Reason: image not found
Trace/BPT trap: 5
我注意到我编译的二进制文件的大小与包含或不包含 dylib 相同,因此,我用谷歌搜索了如何包含和外部库以及一些人都说我需要将“CONFIG += static”添加到我的 .pro 文件中。我这样做了,文件的大小增加了,但我仍然遇到同样的错误。
希望有人能帮助我。
I've been doing some funny stuff in personal projects with Qt. I'm not an expert in this so if it's a dumb question (guess not I couldn't find anything useful) feel free to kill me.
Anyway, I'm in OSX and usually I compile the final versions against a static version of Qt using a shell script with this commands:
cd "project folder...";
PATH=/Users/TCB13/(...)/qt-source/bin:$PATH; --> Path to my static QT.
export PATH;
qmake -config release;
make;
make clean;
So far if I move the compiled binary to another computer without Qt installed everything works just fine! ;)
Yesterday I start to play around with a dynamic library provided by a company and I've included the dylib in my .pro file like this: (I've a copy of the dylib in the project folder)
#macx: LIBS += -L$PWD/ -lwpsapi
#INCLUDEPATH += $PWD/
#DEPENDPATH += $PWD/
And when I compile it "statically" (using the commands above) and run it on the other computer I get:
dyld: Library not loaded: @executable_path/libwpsapi.dylib
Referenced from: /Users/TCB13/Desktop/dude111
Reason: image not found
Trace/BPT trap: 5
I noticed that the size of my compiled binary is the same with or without including the dylib so, I googled how to include and external lib and some people are saying that I need to add "CONFIG += static" to my .pro file. I did it and the size of the file increased but I still got the same error.
Hope someone can help me.
如果你对这篇内容有疑问,欢迎到本站社区发帖提问 参与讨论,获取更多帮助,或者扫码二维码加入 Web 技术交流群。
绑定邮箱获取回复消息
由于您还没有绑定你的真实邮箱,如果其他用户或者作者回复了您的评论,将不能在第一时间通知您!
发布评论
评论(1)
错误消息非常清楚,您需要将 libwpsapi.dylib 与您的应用程序一起分发。如果您想避免这种情况,请查阅此第三方库的文档以使其使用静态链接代码。请注意,您告诉链接器链接静态库这一事实并不意味着代码已被引用。我怀疑代码中有某种预处理器#define(或默认)来使用动态加载的库。
The error message is pretty clear, you need to distribute libwpsapi.dylib with your application. If you want to avoid that, consult the documentation of this third-party library to make it use the statically linked code. Note that the fact that you are telling the linker to link a static library, does not mean that the code is referenced. I suspect that there is some kind of preprocessor #define in the code (or defaulted) to use the dynamically loaded library.