简体   繁体   English

在Qt 4.5.1中使用g ++的链接器错误

[英]Linker Error using g++ with Qt 4.5.1

I'm trying to test out a new dev environment and I am having some problems referencing some of the required Qt libraries. 我正在尝试测试新的开发环境,但在引用某些必需的Qt库时遇到了一些问题。

First I ran this: 首先我运行这个:

$ g++ HelloWorld.C -o HelloWorld -I /usr/local/Trolltech/Qt-4.5.1/include/QtCore/ -I /usr/local/Trolltech/Qt-4.5.1/include/

and got this error: 并得到此错误:

    /tmp/ccmsm4kZ.o: In function `QString::QString(char const*)':
HelloWorld.C:(.text._ZN7QStringC2EPKc[_ZN7QStringC5EPKc]+0x1d): undefined reference to `QString::fromAscii_helper(char const*, int)'
/tmp/ccmsm4kZ.o: In function `QString::~QString()':
HelloWorld.C:(.text._ZN7QStringD2Ev[_ZN7QStringD5Ev]+0x2d): undefined reference to `QString::free(QString::Data*)'
collect2: ld returned 1 exit status

So then I added reference to the QtCore library via: 因此,我通过以下方式添加了对QtCore库的引用:

$ g++ HelloWorld.C -o HelloWorld -I /usr/local/Trolltech/Qt-4.5.1/include/QtCore/ -I /usr/local/Trolltech/Qt-4.5.1/include/ -L /usr/local/Trolltech/Qt-4.5.1/lib -lQtCore

which removed the compile errors, however when I try to run the program I get this error: 删除了编译错误,但是当我尝试运行程序时,出现此错误:

./HelloWorld: error while loading shared libraries: libQtCore.so.4: cannot open shared object file: No such file or directory

I wasn't able to find a solution for this problem via google. 我无法通过Google找到针对此问题的解决方案。 Anyone have advice? 有人有建议吗?

That error indicates that while the linker can find the library at compilation, it can't find it during runtime. 该错误表明,尽管链接器可以在编译时找到该库,但在运行时找不到该库。

You should update your LD_LIBRARY_PATH to include that location like this: 您应该更新您的LD_LIBRARY_PATH以包括该位置,如下所示:

In ~.bashrc probably somewhere near the bottom: ~.bashrc可能在底部附近:

export LD_LIBRARY_PATH=$LD_LIBRARY_PATH:/usr/local/Trolltech/Qt-4.5.1/lib

Alternatively, if you want to make this persistent throughout your system (and have root access), you can make an entry in /etc/ld.so.conf.d (on RedHat, I'm not sure about the other distributions) 另外,如果您想使它在整个系统中持久存在(并具有root访问权限),则可以在/etc/ld.so.conf.d创建一个条目(在RedHat上,我不确定其他发行版)

touch /etc/ld.so.conf.d/qt.conf

Add the path to this file, and then update your runtime via /sbin/ldconfig 将路径添加到此文件,然后通过/sbin/ldconfig更新运行时

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM