Results 1 to 12 of 12

Thread: Linking myLib with myApp

  1. #1
    Join Date
    Sep 2006
    Posts
    339
    Thanks
    15
    Thanked 21 Times in 16 Posts
    Qt products
    Qt3 Qt4
    Platforms
    Unix/X11 Windows

    Default Linking myLib with myApp

    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.
    Attached Files Attached Files

  2. #2
    Join Date
    Jan 2006
    Location
    Warsaw, Poland
    Posts
    33,359
    Thanks
    3
    Thanked 5,015 Times in 4,792 Posts
    Qt products
    Qt3 Qt4 Qt5 Qt/Embedded
    Platforms
    Unix/X11 Windows Android Maemo/MeeGo
    Wiki edits
    10

    Default Re: Linking myLib with myApp

    Your library will be named "libcrypt" so you have to have -lcrypt instead of -llib.

  3. #3
    Join Date
    Sep 2006
    Posts
    339
    Thanks
    15
    Thanked 21 Times in 16 Posts
    Qt products
    Qt3 Qt4
    Platforms
    Unix/X11 Windows

    Default Re: Linking myLib with myApp

    Quote Originally Posted by wysota View Post
    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
    Qt Code:
    1. qmake myLib.pro
    2. make clean
    3. make
    To copy to clipboard, switch view to plain text mode 
    Creates crypt

    Then I have to say
    Qt Code:
    1. qmake scribble.pro
    2. make clean
    3. make
    To copy to clipboard, switch view to plain text mode 
    Created scribble.exe
    This is not a good idea

    Thanks for your understanding

  4. #4
    Join Date
    Jan 2006
    Location
    Warsaw, Poland
    Posts
    33,359
    Thanks
    3
    Thanked 5,015 Times in 4,792 Posts
    Qt products
    Qt3 Qt4 Qt5 Qt/Embedded
    Platforms
    Unix/X11 Windows Android Maemo/MeeGo
    Wiki edits
    10

    Default Re: Linking myLib with myApp

    Quote Originally Posted by vermarajeev View Post
    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
    Qt Code:
    1. qmake myLib.pro
    2. make clean
    3. make
    To copy to clipboard, switch view to plain text mode 
    Creates crypt

    Then I have to say
    Qt Code:
    1. qmake scribble.pro
    2. make clean
    3. make
    To copy to clipboard, switch view to plain text mode 
    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.

    text Code:
    1. CONFIG+=ordered
    2. SUBDIRS=lib app
    To copy to clipboard, switch view to plain text mode 

  5. #5
    Join Date
    Sep 2006
    Posts
    339
    Thanks
    15
    Thanked 21 Times in 16 Posts
    Qt products
    Qt3 Qt4
    Platforms
    Unix/X11 Windows

    Default Re: Linking myLib with myApp

    Quote Originally Posted by wysota View Post
    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....

  6. #6
    Join Date
    Jan 2006
    Location
    Warsaw, Poland
    Posts
    33,359
    Thanks
    3
    Thanked 5,015 Times in 4,792 Posts
    Qt products
    Qt3 Qt4 Qt5 Qt/Embedded
    Platforms
    Unix/X11 Windows Android Maemo/MeeGo
    Wiki edits
    10

    Default Re: Linking myLib with myApp

    Quote Originally Posted by vermarajeev View Post
    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).

  7. #7
    Join Date
    Sep 2006
    Posts
    339
    Thanks
    15
    Thanked 21 Times in 16 Posts
    Qt products
    Qt3 Qt4
    Platforms
    Unix/X11 Windows

    Default Re: Linking myLib with myApp

    Quote Originally Posted by wysota View Post
    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
    Qt Code:
    1. unix:LIBS += -lcrypt -L/root/Desktop/rajeev/samplePro/lib
    To copy to clipboard, switch view to plain text mode 
    to
    Qt Code:
    1. unix:LIBS += -L/root/Desktop/rajeev/samplePro/lib -lcrypt
    To copy to clipboard, switch view to plain text mode 

    It doesnt work.
    Please check the updated zipped file
    Attached Files Attached Files

  8. #8
    Join Date
    Jan 2006
    Location
    Warsaw, Poland
    Posts
    33,359
    Thanks
    3
    Thanked 5,015 Times in 4,792 Posts
    Qt products
    Qt3 Qt4 Qt5 Qt/Embedded
    Platforms
    Unix/X11 Windows Android Maemo/MeeGo
    Wiki edits
    10

    Default Re: Linking myLib with myApp

    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

  9. #9
    Join Date
    Sep 2006
    Posts
    339
    Thanks
    15
    Thanked 21 Times in 16 Posts
    Qt products
    Qt3 Qt4
    Platforms
    Unix/X11 Windows

    Default Re: Linking myLib with myApp

    Quote Originally Posted by wysota View Post
    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

  10. #10
    Join Date
    Jan 2006
    Location
    Warsaw, Poland
    Posts
    33,359
    Thanks
    3
    Thanked 5,015 Times in 4,792 Posts
    Qt products
    Qt3 Qt4 Qt5 Qt/Embedded
    Platforms
    Unix/X11 Windows Android Maemo/MeeGo
    Wiki edits
    10

    Default Re: Linking myLib with myApp

    Qt Code:
    1. /root/Desktop/rajeev/samplePro/lib
    To copy to clipboard, switch view to plain text mode 
    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).

  11. The following user says thank you to wysota for this useful post:

    vermarajeev (20th February 2007)

  12. #11
    Join Date
    Sep 2006
    Posts
    339
    Thanks
    15
    Thanked 21 Times in 16 Posts
    Qt products
    Qt3 Qt4
    Platforms
    Unix/X11 Windows

    Default Re: Linking myLib with myApp

    Quote Originally Posted by wysota View Post
    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.....

  13. #12
    Join Date
    Jan 2006
    Location
    Warsaw, Poland
    Posts
    33,359
    Thanks
    3
    Thanked 5,015 Times in 4,792 Posts
    Qt products
    Qt3 Qt4 Qt5 Qt/Embedded
    Platforms
    Unix/X11 Windows Android Maemo/MeeGo
    Wiki edits
    10

    Default Re: Linking myLib with myApp

    Quote Originally Posted by vermarajeev View Post
    By the way you are awesome.
    Thanks, but I'm really just a regular (lazy) guy

Similar Threads

  1. Replies: 4
    Last Post: 20th February 2006, 09:11

Bookmarks

Posting Permissions

  • You may not post new threads
  • You may not post replies
  • You may not post attachments
  • You may not edit your posts
  •  
Digia, Qt and their respective logos are trademarks of Digia Plc in Finland and/or other countries worldwide.