PDA

View Full Version : Linking myLib with myApp



vermarajeev
19th February 2007, 06:10
Hi,

I have problem linking mylib with myapp

Here is what I have done
Unzip samplePro.zip to get samplePro directory

In the directory samplePro, I have two more directories
namely lib-->contains mylibrary
and app-->contains myApplication

The directories contains
lib directory-->lib.pro, mylib.cpp, mylib.h
app directory-->main.cpp, scribble.cpp, scribble.h, scribble.pro

I tried linking mylib to myapp, but getting some errors.

-->What I want???
Whenever my application runs myLib should compile first (if any changes are made), create lib.a, should be linked to myApp then app.exe should be created.

Please tell me where I'm going wrong.

wysota
19th February 2007, 09:22
Your library will be named "libcrypt" so you have to have -lcrypt instead of -llib.

vermarajeev
19th February 2007, 09:58
Your library will be named "libcrypt" so you have to have -lcrypt instead of -llib.

I dont know I just replied but the post got lost. If you see doubt post please forgive.

Oh! I have corrected myself...Thank you wysota.

There is still another problem.
I have defined myLib.h and myLib.cpp in lib directory. I have defined a method called getString() which return HELLO WORLD.

When I call this method in main.cpp defined in app directory I get unreferneced parameter "test::getString()".

Then I made the function inline in myLib.h...It worked. Why is that happening????

Also I want myApp to depend on myLib ie. when I say
qmake scribble.pro
make clean
make

First myLib should compile and create "crypt" then myApp should create "scribble.exe".

Now I have to do seperately.
ie. I have to do for myLib

qmake myLib.pro
make clean
make
Creates crypt

Then I have to say

qmake scribble.pro
make clean
make

Created scribble.exe
This is not a good idea

Thanks for your understanding

wysota
19th February 2007, 13:00
I have defined myLib.h and myLib.cpp in lib directory. I have defined a method called getString() which return HELLO WORLD.

When I call this method in main.cpp defined in app directory I get unreferneced parameter "test::getString()".

Then I made the function inline in myLib.h...It worked. Why is that happening????

You're using Windows, right? I think you need to export each symbol in the library and import it in your application.

Ask google for dllexport and dllimport. Also take a look at qmake docs (or Qt sources) as it's also telling how to do that. I think you can also search the forum for dllimport - that may give you the quickest result.


Also I want myApp to depend on myLib ie. when I say
qmake scribble.pro
make clean
make

First myLib should compile and create "crypt" then myApp should create "scribble.exe".
I'm not good at this, I never managed to do it properly, but I know it's possible.

You'll probably need DEPENDPATH variable and TARGET.depends should be set on the library (the command to build it, like "cd ../app; make"), but I can't tell you more. Maybe others had more luck with it.


Now I have to do seperately.
ie. I have to do for myLib

qmake myLib.pro
make clean
make
Creates crypt

Then I have to say

qmake scribble.pro
make clean
make

Created scribble.exe
This is not a good idea

A quick workaround is to operate on the top level project file and add the "ordered" keyword to the CONFIG variable. This will then build all targets (subdirs) and build them according to the order specified in the SUBDIRS variable.

CONFIG+=ordered
SUBDIRS=lib app

vermarajeev
19th February 2007, 13:55
You're using Windows, right? I think you need to export each symbol in the library and import it in your application.

I'm using both, I dont have problems on windows but on linux I'm getting those errors....

wysota
19th February 2007, 14:08
I'm using both, I dont have problems on windows but on linux I'm getting those errors....
I see... that ".exe" thing misled me. In that case you're probably not linking with the library. Be sure to set correct -L and -l parameters in LIBS (-L should be before -l).

vermarajeev
20th February 2007, 06:37
I see... that ".exe" thing misled me. In that case you're probably not linking with the library. Be sure to set correct -L and -l parameters in LIBS (-L should be before -l).

No, I changed

unix:LIBS += -lcrypt -L/root/Desktop/rajeev/samplePro/lib
to

unix:LIBS += -L/root/Desktop/rajeev/samplePro/lib -lcrypt

It doesnt work.
Please check the updated zipped file

wysota
20th February 2007, 12:40
First a side note - are you sure this is a good idea to use the root account for your daily tasks (especially for running the desktop)?

Now for the problems:
1. getString() implementation is not part of the test class, you forgot the "test::" part.
2. Change those absolute paths to ../lib.
3. Change libs to: LIBS += ../lib/libcrypt.a

vermarajeev
20th February 2007, 13:53
First a side note - are you sure this is a good idea to use the root account for your daily tasks (especially for running the desktop)?

I didint get what you mean????Please clarify

wysota
20th February 2007, 14:02
/root/Desktop/rajeev/samplePro/lib
You're using your superuser account to do non-maintanance tasks. This is considered a stability (and sometimes also security) risk. To be honest the desktop shouldn't even start for the root user. And you certainly shouldn't use the root account when programming - this is very error prone and very risky - you can render your system unusable (you might delete files crucial for your system by accident or lock the operating system and not be able to unlock it as the root account doesn't have some limitations regular accounts have).

vermarajeev
20th February 2007, 14:48
You're using your superuser account to do non-maintanance tasks. This is considered a stability (and sometimes also security) risk. To be honest the desktop shouldn't even start for the root user. And you certainly shouldn't use the root account when programming - this is very error prone and very risky - you can render your system unusable (you might delete files crucial for your system by accident or lock the operating system and not be able to unlock it as the root account doesn't have some limitations regular accounts have).


Hi wysota,
Thanks... I didnt know that...I'll correct and create my own account for personal use...

Thanks..

By the way you are awesome.. I fixed that problem....It was my mistake.....

wysota
20th February 2007, 14:51
By the way you are awesome.

Thanks, but I'm really just a regular (lazy) guy :)