Date: Tue, 02 Mar 2004 19:19:10 -0500 From: Scott W <wegster@mindcore.net> To: Charles McManis <cmcmanis@mcmanis.com> Cc: freebsd-questions@freebsd.org Subject: Re: Can one compile khello.cc ? Message-ID: <4045247E.2050100@mindcore.net> In-Reply-To: <200403021119.06516.cmcmanis@mcmanis.com> References: <200403021119.06516.cmcmanis@mcmanis.com>
next in thread | previous in thread | raw e-mail | index | archive | help
Charles McManis wrote: >Ok, so this is now officially weird. I decided to try to compile khello.cc >from the KDE tutorial on my 4.8 system that has never had me attempt to >upgrade KDE on it. > >When I compile khello.cc, it compiles fine, when I link it I get this: >-----------------------------snip---------------------------------------------------------------- >ddp% make >g++ -o khello -R/usr/X11R6/lib -L/usr/local/lib/kde3/ -L/usr/local/lib >-L/usr/X11R6/lib -lqt-mt -pthread -lkdeui -lkdecore -lXft khello.o >/usr/local/gnu/lib/gcc-lib/i386-unknown-freebsd4.8/3.2.3/../../../../i386-unknown-freebsd4.8/bin/ld: >warning: libstdc++.so.3, needed by /usr/X11R6/lib/libqt-mt.so, may conflict >with libstdc++.so.5 >/usr/lib/libc.so.4: WARNING! setkey(3) not present in the system! >/usr/lib/libc.so.4: warning: this program uses gets(), which is unsafe. >/usr/lib/libc.so.4: warning: mktemp() possibly used unsafely; consider using >mkstemp() >/usr/lib/libc.so.4: WARNING! des_setkey(3) not present in the system! >/usr/lib/libc.so.4: WARNING! encrypt(3) not present in the system! >/usr/lib/libc.so.4: warning: tmpnam() possibly used unsafely; consider using >mkstemp() >/usr/lib/libc.so.4: warning: this program uses f_prealloc(), which is not >recommended. >/usr/lib/libc.so.4: WARNING! des_cipher(3) not present in the system! >/usr/lib/libc.so.4: warning: tempnam() possibly used unsafely; consider using >mkstemp() >khello.o(.text+0x2b): In function `main': >: undefined reference to `QCString::QCString[in-charge](char const*)' >khello.o(.text+0x48): In function `main': >: undefined reference to `KApplication::KApplication[in-charge](int&, char**, >QCString const&, bool, bool)' >khello.o(.text+0x68): In function `main': >: undefined reference to `QCString::~QCString [in-charge]()' >khello.o(.text+0x8e): In function `main': >: undefined reference to `QCString::~QCString [in-charge]()' >khello.o(.text+0xc2): In function `main': >: undefined reference to `KMainWindow::KMainWindow[in-charge](QWidget*, char >const*, unsigned)' >khello.o(.text+0x16e): In function `main': >: undefined reference to `QApplication::setMainWidget(QWidget*)' >khello.o(.text+0x19d): In function `main': >: undefined reference to `QApplication::exec()' >khello.o(.text+0x1b1): In function `main': >: undefined reference to `KApplication::~KApplication [in-charge]()' >khello.o(.text+0x1d7): In function `main': >: undefined reference to `KApplication::~KApplication [in-charge]()' >collect2: ld returned 1 exit status >make: *** [khello] Error 1 >ddp% >----------------------------------------------------------------------------------------- >So what am I missing? > >--Chuck >_______________________________________________ >freebsd-questions@freebsd.org mailing list >http://lists.freebsd.org/mailman/listinfo/freebsd-questions >To unsubscribe, send any mail to "freebsd-questions-unsubscribe@freebsd.org" > > > If you have a pointer to the KDE tutorial/code you're using, may be of more help, but here's a quick 'khello' program, step by step: [wegster@db KDETutorial]$ cat main.cc #include <qapplication.h> #include <qpushbutton.h> int main(int argc, char **argv) { QApplication app( argc, argv ); QPushButton *hello=new QPushButton( "Hello world!", 0 ); hello->resize(200, 30 ); QObject::connect(hello, SIGNAL(clicked()), &app, SLOT(quit()) ); app.setMainWidget(hello); hello->show(); return app.exec(); } wegster@db KDETutorial]$ g++ main.cc main.cc:1:26: qapplication.h: No such file or directory main.cc:2:25: qpushbutton.h: No such file or directory main.cc: In function `int main(int, char**)': main.cc:7: `QApplication' undeclared (first use this function) main.cc:7: (Each undeclared identifier is reported only once for each function it appears in.) main.cc:7: syntax error before `(' token main.cc:9: `QPushButton' undeclared (first use this function) main.cc:9: `hello' undeclared (first use this function) main.cc:9: syntax error before `(' token main.cc:12: `QObject' undeclared (first use this function) main.cc:12: syntax error before `::' token main.cc:17: `app' undeclared (first use this function) We're missing the header location in our include path (because we didn't specify one), so let's find it: [wegster@db KDETutorial]$ locate qapplication.h /usr/share/doc/qt-devel-3.1.2/html/qapplication.html /usr/lib/qt-3.1/include/qapplication.h The latter is the one we need, so feed the path as an include path to g++ via the -I switch: [wegster@db KDETutorial]$ g++ main.cc -I /usr/lib/qt-3.1/include /tmp/ccC2zAn3.o(.text+0x23): In function `main': : undefined reference to `QApplication::QApplication[in-charge](int&, char**)' /tmp/ccC2zAn3.o(.text+0x52): In function `main': : undefined reference to `QString::QString[in-charge](char const*)' /tmp/ccC2zAn3.o(.text+0x61): In function `main': : undefined reference to `QPushButton::QPushButton[in-charge](QString const&, QWidget*, char const*)' /tmp/ccC2zAn3.o(.text+0x12c): In function `main': : undefined reference to `QObject::connect(QObject const*, char const*, QObject const*, char const*)' /tmp/ccC2zAn3.o(.text+0x13e): In function `main': : undefined reference to `QApplication::setMainWidget(QWidget*)' /tmp/ccC2zAn3.o(.text+0x164): In function `main': : undefined reference to `QApplication::exec()' /tmp/ccC2zAn3.o(.text+0x175): In function `main': : undefined reference to `QApplication::~QApplication [in-charge]()' /tmp/ccC2zAn3.o(.text+0x195): In function `main': : undefined reference to `QApplication::~QApplication [in-charge]()' /tmp/ccC2zAn3.o(.gnu.linkonce.t._ZN7QStringD1Ev+0x21): In function `QString::~QString [in-charge]()': : undefined reference to `QString::shared_null' /tmp/ccC2zAn3.o(.gnu.linkonce.t._ZN7QStringD1Ev+0x30): In function `QString::~QString [in-charge]()': : undefined reference to `QStringData::deleteSelf()' collect2: ld returned 1 exit status Looks like what you've got, which isn't surprising- I'll bet we can compile to an object file only however, let's test using -c for 'compile but don't link' to g++: [wegster@db KDETutorial]$ g++ -c main.cc -I /usr/lib/qt-3.1/include [wegster@db KDETutorial]$ ls -l main.* -rw-rw-r-- 1 wegster wegster 380 Mar 2 19:05 main.cc -rw-rw-r-- 1 wegster wegster 2816 Mar 2 19:13 main.o Yep, that works. But to get a running executable, you need to resolve library dependencies, in this case likely the QT library...let's find it first: [wegster@db KDETutorial]$ locate libqt /usr/lib/qt-3.1/lib/libqt-mt.so.3.1.2 /usr/lib/qt-3.1/lib/libqt-mt.so.3 /usr/lib/qt-3.1/lib/libqt-mt.so.3.1 /usr/lib/qt-3.1/lib/libqt.so.3.1 /usr/lib/qt-3.1/lib/libqt.so.3 /usr/lib/qt-3.1/lib/libqt.so.3.1.2 /usr/lib/qt-3.1/lib/libqt-mt.so /usr/lib/qt-3.1/lib/libqt.so /usr/lib/libqthreads.so.12.3.0 /usr/lib/libqthreads.so.12 /usr/lib/libqtmcop.la /usr/lib/libqtmcop.so.1 /usr/lib/libqtmcop.so.1.0.0 /usr/lib/libqtmcop.so What we really want here is likely the libqt, so add the compile time library path via -L switches, and finally the short name (lib name - the 'lib' prefix and the versioning) of the library we want to link against: [wegster@db KDETutorial]$ g++ main.cc -I /usr/lib/qt-3.1/include -L/usr/lib/qt-3.1/lib/ -lqt [wegster@db KDETutorial]$ ./a.out Works ;-) NOTE: This was done on a RHES system, because I've got the KDE development headers and libs installed. For FreeBSD, you'll need the qt sources or a KDE development package, although I'm not entirely sure which offhand... HTH, Scott
Want to link to this message? Use this URL: <https://mail-archive.FreeBSD.org/cgi/mid.cgi?4045247E.2050100>