LinuxQuestions.org
Help answer threads with 0 replies.
Go Back   LinuxQuestions.org > Forums > Non-*NIX Forums > Programming
User Name
Password
Programming This forum is for all programming questions.
The question does not have to be directly related to Linux and any language is fair game.

Notices



Reply
 
Search this Thread
Old 03-17-2006, 11:38 AM   #1
richikiki
Member
 
Registered: Mar 2005
Location: Montréal, Québec, Canada
Distribution: Slackware 12.1 x32, 13.1 x64
Posts: 90

Rep: Reputation: 15
Angry KDE g++ program doesn't run test.cpp


Hi guys,

I'm starting with KDE but I don't know why is not running my application.
I would apreciate any help:


Code:
-----------test2.cpp--------------------------------
#include <qstring.h>

#include <kapp.h>
#include <klineedit.h>

int main (int argc, char *argv[])
{
   KApplication khello (argc, argv, "khello");
   KLineEdit *helloeditor = new KLineEdit (0);
   QString hellostring ("Hello!");

	helloeditor->setText (hellostring);
	helloeditor->show();

	khello.setMainWidget (helloeditor);
	return khello.exec();
}
----------------------------------------------------
ricardo@phoenix:$ g++ -c -I/usr/lib/qt/include -I/opt/kde/include -o test2.o test2.cpp
test2.cpp: In function `int main(int, char**)':
test2.cpp:10: warning: `__comp_ctor' is deprecated (declared at
/opt/kde/include/kapplication.h:196)
dir:~/programming/test
ricardo@phoenix:$ dir
total 44
drwxr-xr-x 2 ricardo users 4096 Mar 17 15:41 ./
drwxr-xr-x 8 ricardo users 4096 Mar 15 16:20 ../
-rw-r--r-- 1 ricardo users 361 Mar 17 14:51 Makefile
-rw-r--r-- 1 ricardo users 367 Mar 17 14:43 Makefile~
-rw-r--r-- 1 ricardo users 151 Mar 17 14:15 ricky.txt
-rw-r--r-- 1 ricardo users 693 Mar 17 15:01 test.cpp
-rw-r--r-- 1 ricardo users 692 Mar 17 14:51 test.cpp~
-rw-r--r-- 1 ricardo users 367 Mar 17 15:39 test2.cpp
-rw-r--r-- 1 ricardo users 369 Mar 17 15:38 test2.cpp~
-rw-r--r-- 1 ricardo users 4512 Mar 17 15:41 test2.o
dir:~/programming/test
ricardo@phoenix:$ chmod +x test2.o
dir:~/programming/test
ricardo@phoenix:$ dir
total 44
drwxr-xr-x 2 ricardo users 4096 Mar 17 15:41 ./
drwxr-xr-x 8 ricardo users 4096 Mar 15 16:20 ../
-rw-r--r-- 1 ricardo users 361 Mar 17 14:51 Makefile
-rw-r--r-- 1 ricardo users 367 Mar 17 14:43 Makefile~
-rw-r--r-- 1 ricardo users 151 Mar 17 14:15 ricky.txt
-rw-r--r-- 1 ricardo users 693 Mar 17 15:01 test.cpp
-rw-r--r-- 1 ricardo users 692 Mar 17 14:51 test.cpp~
-rw-r--r-- 1 ricardo users 367 Mar 17 15:39 test2.cpp
-rw-r--r-- 1 ricardo users 369 Mar 17 15:38 test2.cpp~
-rwxr-xr-x 1 ricardo users 4512 Mar 17 15:41 test2.o*
dir:~/programming/test
ricardo@phoenix:$ ./test2.o
-bash: ./test2.o: cannot execute binary file
dir:~/programming/test
ricardo@phoenix:$ sh test.o


I'm quite lost. I guess linking and other things are missing but I'm not sure you know I'm noob
 
Old 03-17-2006, 12:30 PM   #2
zackarya
Member
 
Registered: Jul 2003
Distribution: OpenSuse 10, Debian
Posts: 152

Rep: Reputation: 30
The problem is the way your tring to compile the program.
This site gives a good overview of what you need to compile the program properly.

http://developer.kde.org/documentati...tml#ch02list01

I hope that helps.

Zackarya
 
Old 03-17-2006, 01:14 PM   #3
richikiki
Member
 
Registered: Mar 2005
Location: Montréal, Québec, Canada
Distribution: Slackware 12.1 x32, 13.1 x64
Posts: 90

Original Poster
Rep: Reputation: 15
Red face

Thanks Zackarya,

Unfortunatly I have read that documentation and the info provided is not good.
For example if you look a the code they post over there is not working are missing '}' and the include is not correctly.

I was using Kdevelop to create a proyect I just want to know how to compile this using command line.
Now that my code is ok I just need to know how to compile it.
In my stand point I can compile it but it doesn't run it.
Using the Makefile didn't resolve my problem neither.
I realize the next:

Makefile
[HTML]INCL= -I$(QTDIR)/include -I$(KDEDIR)/include
CFLAGS= -O2 -fno-strength-reduce
LFLAGS= -L$(QTDIR)/lib -L$(KDEDIR)/include -L/usr/X11R6/lib
LIBS= -lkdecore -lkdeui -lqt -lX11 -lXext -ldl
CC=g++

test2: test2.o
$(CC) $(LFLAGS) -o test2 test2.o $(LIBS)

test2.o: test2.cpp

clean:
rm -f test2
rm -f test2.o

.SUFFIXES: .cpp

.cpp.o:
$(CC) -c $(CFLAGS) $(INCL) -o $@ $<
[/HTML]



The right compilation command line should be something like:


[HTML]
ricardo@phoenix:$ make test2
g++ -L/usr/lib/qt/lib -L/opt/kde/include -L/usr/X11R6/lib -o test2 test2.o -lkdecore -lkdeui -lqt -lX11 -lXext -ldl
/usr/lib/gcc-lib/i486-slackware-linux/3.3.4/../../../../i486-slackware-linux/bin/ld: cannot find -lkdecore
collect2: ld returned 1 exit status
make: *** [test2] Error 1
dir:~/programming/test
ricardo@phoenix:$[/HTML]

Well my problem is that using the -lXXX isn't found on my system.
Does anyone have clue what I'm missing?.
 
Old 03-17-2006, 01:34 PM   #4
geeman2.0
Member
 
Registered: Feb 2005
Location: Ontario, Canada
Distribution: Gentoo, Slackware
Posts: 345

Rep: Reputation: 30
The problem is that you're passing the -c flag to g++.
This indicates that g++ will create an object file, NOT an executable.

If you remove this flag from your original statement then it will create an executable named test2.o

Note that giving an executable file a .o extension is a bad naming practice.
 
Old 03-17-2006, 02:59 PM   #5
zackarya
Member
 
Registered: Jul 2003
Distribution: OpenSuse 10, Debian
Posts: 152

Rep: Reputation: 30
I was able to get it to compile using

g++ test2.cpp -I/opt/kde3/include -I/usr/lib/qt3/include -L/opt/kde3/lib -I/usr/lib/qt3/lib -lkdeui -o test2

You'll need to change the paths. It creates the file test2.

Hope that helps.

Zackarya
 
Old 03-17-2006, 03:22 PM   #6
richikiki
Member
 
Registered: Mar 2005
Location: Montréal, Québec, Canada
Distribution: Slackware 12.1 x32, 13.1 x64
Posts: 90

Original Poster
Rep: Reputation: 15
Unhappy

Thanks for the clarification geeman2.0

Well I guess I'm close to done it. hahaha

I'm figure out something:

I was looking at the Makefile that I created and I found this:

Code:
dir:~/programming/test
ricardo@phoenix:$ make clean
rm -f test2
rm -f test2.o

ricardo@phoenix:$ make test2
g++ -c -O2 -fno-strength-reduce -I/usr/lib/qt/include -I/opt/kde/include -o test2.o test2.cpp
test2.cpp: In function `int main(int, char**)':
test2.cpp:11: warning: `__comp_ctor' is deprecated (declared at
   /opt/kde/include/kapplication.h:196)
g++ -L/usr/lib/qt/lib -L/opt/kde/lib -L/usr/X11R6/lib -o test2 test2.o -lkdecore -lkdeui -lqt -lX11 -lXext -ldl
/usr/lib/gcc-lib/i486-slackware-linux/3.3.4/../../../../i486-slackware-linux/bin/ld: cannot find -lqt
collect2: ld returned 1 exit status
make: *** [test2] Error 1
dir:~/programming/test
I was playing with this and I thing that the Makefile work in 2 steps:
1) Created test2.o which is an object file, not an executable.
2) Then this file test2.o should be linking with the libraries in order to created the execute. Linking all together in a file but for some reason on the paths the compiler is not able to find my libraries.

I'm close I'm sure any other idea.
 
Old 03-17-2006, 03:47 PM   #7
richikiki
Member
 
Registered: Mar 2005
Location: Montréal, Québec, Canada
Distribution: Slackware 12.1 x32, 13.1 x64
Posts: 90

Original Poster
Rep: Reputation: 15
Talking

Finally:

Well the solution to this was:


Code:
dir:~/programming/test
ricardo@phoenix:$ g++ test2.cpp -I/opt/kde/include -I/usr/lib/qt/include -L/opt/kde/lib -I/usr/lib/qt/lib -lkdeui -o test2
test2.cpp: In function `int main(int, char**)':
test2.cpp:11: warning: `__comp_ctor' is deprecated (declared at
   /opt/kde/include/kapplication.h:196)
dir:~/programming/test
ricardo@phoenix:$ dir
total 52
drwxr-xr-x  2 ricardo users  4096 Mar 17 20:13 ./
drwxr-xr-x  9 ricardo users  4096 Mar 17 18:05 ../
-rw-r--r--  1 ricardo users   365 Mar 17 19:01 Makefile
-rw-r--r--  1 ricardo users   369 Mar 17 16:31 Makefile~
-rw-r--r--  1 ricardo users   151 Mar 17 14:15 ricky.txt
-rw-r--r--  1 ricardo users   693 Mar 17 15:01 test.cpp
-rw-r--r--  1 ricardo users   692 Mar 17 14:51 test.cpp~
-rwxr-xr-x  1 ricardo users 16151 Mar 17 20:13 test2*
-rw-r--r--  1 ricardo users   366 Mar 17 18:56 test2.cpp
-rw-r--r--  1 ricardo users   898 Mar 17 18:55 test2.cpp~
dir:~/programming/test
ricardo@phoenix:$ ./test2
dir:~/programming/test
ricardo@phoenix:$
Heeeee is working finally

A better aproach is:

Code:
ricardo@phoenix:$ echo $KDEDIR
/opt/kde
dir:~/programming/test
ricardo@phoenix:$ echo $QTDIR
/usr/lib/qt
dir:~/programming/test
ricardo@phoenix:$ g++ test2.cpp -I$KDEDIR/include -I$QTDIR/include -L$KDEDIR/lib -I$QTDIR/lib -lkdeui -o test2
test2.cpp: In function `int main(int, char**)':
test2.cpp:11: warning: `__comp_ctor' is deprecated (declared at
   /opt/kde/include/kapplication.h:196)
dir:~/programming/test
ricardo@phoenix:$ ./test2
dir:~/programming/test
ricardo@phoenix:$
Which is more less what is doing the Makefile.
I still having the warning from the pre-compiler, I should better to continue reading the documentation for KDE 3.4.0.
Thanks zackarya and geeman2.0 for your advices.
 
  


Reply


Thread Tools Search this Thread
Search this Thread:

Advanced Search

Posting Rules
You may not post new threads
You may not post replies
You may not post attachments
You may not edit your posts

BB code is On
Smilies are On
[IMG] code is Off
HTML code is Off


Similar Threads
Thread Thread Starter Forum Replies Last Post
Run program before KDE startup carl.waldbieser Linux - Software 8 06-30-2006 09:15 PM
KDE 3.5.1 libkopete_videodevice_la.all_cpp.cpp doesn't compile pda_h4x0r Linux - Newbie 2 02-11-2006 04:41 PM
debian dpkg cpp depends on cpp error darkleaf Linux - Software 2 06-25-2004 02:47 AM
compiling kino, gtk test program cant run vance Linux - Software 1 06-02-2003 05:36 AM
need a shell program cpp file GoboFraggle Programming 1 04-02-2003 11:28 PM


All times are GMT -5. The time now is 09:37 PM.

Main Menu
Advertisement
My LQ
Write for LQ
LinuxQuestions.org is looking for people interested in writing Editorials, Articles, Reviews, and more. If you'd like to contribute content, let us know.
Main Menu
Syndicate
RSS1  Latest Threads
RSS1  LQ News
Twitter: @linuxquestions
identi.ca: @linuxquestions
Facebook: linuxquestions Google+: linuxquestions
Open Source Consulting | Domain Registration