在QT官网下的qtsdk.bin
然后安装后使用,无法编译。就连它自带的示例也是同样的错误提示
这是个在QtCreator下的提示:
:-1: error: collect2: ld returned 1 exit status
好心给帮看看,谢谢了
解决办法:
不使用QtCreator生成应用程序,
在终端方方式下,转到工作目录下
1 qmake -project
2 qmake
此时生成一个Makefile,修改这个文件,将“LIBS =”行中“-pthread“后至末尾删除
3 make
好了,成功。
不知道有没有办法,让qmake不生成含那些字串的Makeifle.
还有什么疑问
应该不是qmake的错误,大概是楼主本人的系统原有的一些lib与要编译安装的有冲突。
可能是pro文件出错了,我也经常遇到这种错误,如果是QT-=gui/ core就改成QT +=gui/core或者直接把这行去掉,可能吧,反正是该pro文件的问题
#include <QApplication> #include <QPushButton> int main(int argc, char *argv[]) { QApplication app(argc, argv); QPushButton hello("Hello world!"); hello.resize(100, 30); hello.show(); return app.exec(); } |
保存成main.cpp
2、打开cmd,进入main.cpp的目录,执行以下命令
qmake -project // 为了生成project文件
qmake //生成Makefile文件
make //生成可执行文件
出问题了,
make -f Makefile.Debug make[1]: Entering directory `C:/Qt/mypro' g++ -c -g -g -frtti -fexceptions -Wall -DUNICODE -DQT_LARGEFILE_SUPPORT -DQT_DLL -DQT_GUI_LIB -DQT_CORE_LIB -DQT_THREAD_SUPPORT -DQT_NEEDS_QMAIN -I"C:/Qt/4.1.2/ include/QtCore" -I"C:/Qt/4.1.2/include/QtGui" -I"C:/Qt/4.1.2/include" -I"." -I"C :/Qt/4.1.2/include/ActiveQt" -I"debug" -I"." -I"C:/Qt/4.1.2/mkspecs/win32-g++" - o debug/main.o main.cpp main.cpp:10:4: warning: no newline at end of file g++ -mthreads -Wl,-enable-stdcall-fixup -Wl,-enable-auto-import -Wl,-enable-runt ime-pseudo-reloc -Wl,-subsystem,windows -o "debug/mypro.exe" debug/main.o -L"C: /Qt/4.1.2/lib" -lmingw32 -lqtmaind -lQtGuid4 -lQtCored4 c:/Dev-Cpp/bin/../lib/gcc/mingw32/3.4.2/../../../../mingw32/bin/ld.exe: cannot f ind -lQtGuid4 collect2: ld returned 1 exit status make[1]: *** [debug/mypro.exe] Error 1 make[1]: Leaving directory `C:/Qt/mypro' make: *** [debug] Error 2 |
提示mingw的ld.exe找不到QTGuid4库文件,我到QT安
装目录的lib里查看了一下,确实没有此库,只有libQTGui4.a这
个库文件,这个。。。。当机立断,把libQTGui4.a复制了一个,
更改名字为libQTGuid4.a,在进行make ,不错,那个错误提示没有
了,但是有提示找不到QTCored4库文件,
make -f Makefile.Debug make[1]: Entering directory `C:/Qt/mypro' g++ -c -g -g -frtti -fexceptions -Wall -DUNICODE -DQT_LARGEFILE_SUPPORT -DQT_DLL -DQT_GUI_LIB -DQT_CORE_LIB -DQT_THREAD_SUPPORT -DQT_NEEDS_QMAIN -I"C:/Qt/4.1.2/ include/QtCore" -I"C:/Qt/4.1.2/include/QtGui" -I"C:/Qt/4.1.2/include" -I"." -I"C :/Qt/4.1.2/include/ActiveQt" -I"debug" -I"." -I"C:/Qt/4.1.2/mkspecs/win32-g++" - o debug/main.o main.cpp main.cpp:10:4: warning: no newline at end of file g++ -mthreads -Wl,-enable-stdcall-fixup -Wl,-enable-auto-import -Wl,-enable-runt ime-pseudo-reloc -Wl,-subsystem,windows -o "debug/mypro.exe" debug/main.o -L"C: /Qt/4.1.2/lib" -lmingw32 -lqtmaind -lQtGuid4 -lQtCored4 c:/Dev-Cpp/bin/../lib/gcc/mingw32/3.4.2/../../../../mingw32/bin/ld.exe: cannot f ind -lQtGuid4 collect2: ld returned 1 exit status make[1]: *** [debug/mypro.exe] Error 1 make[1]: Leaving directory `C:/Qt/mypro' make: *** [debug] Error 2 |
照葫芦画瓢,再复制一份
libQTCored4.a,在运行make ,顺利通过。
虽然错误解决了,但是不知道是为什么,按说应该在安装QT时产生
那两个库文件的,可是。。。。反正是奇怪,继续寻找答案
PS:注意这个警告
main.cpp:10:4: warning: no newline at end of file
错误原由: Each instance of a backslash character (/) immediately followed by a
new-line character is deleted, splicing physical source lines to form logical
source lines. Only the last backslash on any physical source line shall be
eligible for being part of such a splice. A source file that is not empty
shall end in a new-line character, which shall not be immediately preceded
by a backslash character before any such splicing takes place.
改正方法:在main函数结束后打个回车符号
chmod u+x qt-sdk-linux-x86-opensource-2009.02.bin
./qt-sdk-linux-x86-opensource-2009.02.bin
接着出现安装,,,,,
安装结束,,,,,
运行如下代码时
#include <QApplication>
#include <QLabel>
int main(int argc, char *argv[])
{
QApplication app(argc, argv);
QLabel *label = new QLabel("Hello Qt!");
label->show();
return app.exec();
}
Qt Creator 编译运行,,,
Starting: /usr/bin/make -w
make: Entering directory `/home/sun/Desktop/Myprojects/hello'
g++ -c -pipe -O2 -Wall -W -D_REENTRANT -DQT_NO_DEBUG -DQT_GUI_LIB -DQT_CORE_LIB -DQT_SHARED -I../../../qt/qt/mkspecs/linux-g++ -I. -I../../../qt/qt/include/QtCore -I../../../qt/qt/include/QtGui -I../../../qt/qt/include -I. -I. -I. -o hello.o hello.cpp
g++ -Wl,-O1 -Wl,-rpath,/home/sun/qt/qt/lib -o hello hello.o -L/home/sun/qt/qt/lib -lQtGui -L/home/sun/qt/qt/lib -L/usr/X11R6/lib -pthread -lfreetype -lgobject-2.0 -lSM -lICE -pthread -pthread -lXrender -lfontconfig -lXext -lX11 -lQtCore -lm -pthread -lgthread-2.0 -lrt -lglib-2.0 -ldl -lpthread
/usr/bin/ld: cannot find -lfreetype
collect2: ld returned 1 exit status
make: *** [hello] Error 1
make: Leaving directory `/home/sun/Desktop/Myprojects/hello'
Exited with code 2.
Error while building project hello
When executing build step 'Make'
解决 /usr/bin/ld: cannot find -lfreetype
安装 libfreetype-dev
(用synaptic Package Manager 选 libfreetype6 和libfreetype6-dev )
编译时出现:
/usr/bin/ld: cannot find -lgobject-2.0
collect2: ld returned 1 exit status
make: *** [hello] Error 1
make: Leaving directory `/home/sun/Desktop/pro/hello'
Exited with code 2.
Error while building project hello
When executing build step 'Make'
安装:
gob2 2.0.15-1
libsm6
libsm-dev
libxrender-dev
fontconfig-dev
libxetx-dev
此时即可解决,,,,,,
编译、运行正常,,,