Results 1 to 7 of 7

Thread: Problem with dependency on shared library and internal class

  1. #1
    Join Date
    Jan 2015
    Location
    Barquisimeto, Venezuela
    Posts
    24
    Thanks
    2
    Qt products
    Qt4 Qt5
    Platforms
    Unix/X11 Android

    Question Problem with dependency on shared library and internal class

    Hello again friends, this time I come here, with the following question:

    I have the following project structure:
    Qt Code:
    1. editor/
    2. Editor.pro // is a subdirs project
    3. Bin /
    4. Bin.pro // is a subdirs project
    5. com/
    6. com.pro // is a subdirs project
    7. Common /
    8. Common.pro // is a subdirs project
    9. Language /
    10. Language.pro // is a subdirs project
    11. Core /
    12. Core.pro // is a share library project
    13. Php /
    14. Php.pro // is a share library project Depends on core.pro
    15. Project /
    16. Project.pro // is a share library project Depends on language.pro
    17. Examples /
    18. Examples.pro // is a subdirs project
    19. Createproject /
    20. Createproject.pro // Depends on project.pro
    To copy to clipboard, switch view to plain text mode 

    And the following are the respective configurations of the .pro files that I indicated in the previous structure:

    Editor.pro
    Qt Code:
    1. TEMPLATE = subdirs
    2.  
    3. SUBDIRS += \
    4. bin \
    5. com \
    6. common \
    7. examples
    8.  
    9. bin.depends = com
    10. com.depends = common
    11. common.depends = com
    12. examples.depends = common
    To copy to clipboard, switch view to plain text mode 
    Common.pro
    Qt Code:
    1. TEMPLATE = subdirs
    2.  
    3. SUBDIRS += \
    4. actions \
    5. addons \
    6. codeeditor \
    7. codegenerator \
    8. files \
    9. highlighter \
    10. language \
    11. project \
    12. utils \
    13. workspace
    14.  
    15. actions.depends = addons
    16. addons.depends = actions files language project utils
    17. project.depends = language
    18. workspace.depends = codeeditor
    To copy to clipboard, switch view to plain text mode 
    Language.pro
    Qt Code:
    1. TEMPLATE = subdirs
    2.  
    3. SUBDIRS += \
    4. core \
    5. php
    6.  
    7. php.depends = core
    To copy to clipboard, switch view to plain text mode 
    Core.pro
    Qt Code:
    1. #-------------------------------------------------
    2. #
    3. # Project created by QtCreator 2017-02-12T18:09:20
    4. #
    5. #-------------------------------------------------
    6.  
    7. QT -= gui
    8.  
    9. CONFIG += c++11
    10.  
    11. greaterThan(QT_MAJOR_VERSION, 4): QT +=
    12.  
    13. TARGET = core
    14. TEMPLATE = lib
    15.  
    16. DEFINES += CORE_LIBRARY
    17.  
    18. # The following define makes your compiler emit warnings if you use
    19. # any feature of Qt which as been marked as deprecated (the exact warnings
    20. # depend on your compiler). Please consult the documentation of the
    21. # deprecated API in order to know how to port your code away from it.
    22. DEFINES += QT_DEPRECATED_WARNINGS
    23.  
    24. # You can also make your code fail to compile if you use deprecated APIs.
    25. # In order to do so, uncomment the following line.
    26. # You can also select to disable deprecated APIs only up to a certain version of Qt.
    27. #DEFINES += QT_DISABLE_DEPRECATED_BEFORE=0x060000 # disables all the APIs deprecated before Qt 6.0.0
    28.  
    29. SOURCES += Core.cpp \
    30. model/ClassAbs.cpp \
    31. model/MethodAbs.cpp \
    32. model/ModelObj.cpp \
    33. model/ParamAbs.cpp
    34.  
    35. HEADERS += Core.h\
    36. core_global.h \
    37. model/ClassAbs.h \
    38. model/MethodAbs.h \
    39. model/ModelObj.h \
    40. model/ParamAbs.h
    41.  
    42. DESTDIR = ../
    43.  
    44. unix {
    45. target.path = /usr/lib
    46. INSTALLS += target
    47. }
    To copy to clipboard, switch view to plain text mode 
    Php.pro
    Qt Code:
    1. #-------------------------------------------------
    2. #
    3. # Project created by QtCreator 2017-02-12T18:09:45
    4. #
    5. #-------------------------------------------------
    6.  
    7. QT -= gui
    8.  
    9. CONFIG += c++11
    10.  
    11. greaterThan(QT_MAJOR_VERSION, 4): QT += xml xmlpatterns
    12.  
    13. TARGET = php
    14. TEMPLATE = lib
    15.  
    16. DEFINES += PHP_LIBRARY
    17.  
    18. # The following define makes your compiler emit warnings if you use
    19. # any feature of Qt which as been marked as deprecated (the exact warnings
    20. # depend on your compiler). Please consult the documentation of the
    21. # deprecated API in order to know how to port your code away from it.
    22. DEFINES += QT_DEPRECATED_WARNINGS
    23.  
    24. # You can also make your code fail to compile if you use deprecated APIs.
    25. # In order to do so, uncomment the following line.
    26. # You can also select to disable deprecated APIs only up to a certain version of Qt.
    27. #DEFINES += QT_DISABLE_DEPRECATED_BEFORE=0x060000 # disables all the APIs deprecated before Qt 6.0.0
    28.  
    29. DEPENDPATH += . ../core \
    30. ../../../com/ecosoftware/console \
    31. ../../utils \
    32. ../../project
    33. INCLUDEPATH += . ../core \
    34. ../../../com/ecosoftware/console \
    35. ../../utils \
    36. ../../project
    37.  
    38. LIBS''= -L -lcore
    39.  
    40. SOURCES += Php.cpp \
    41. controller/PhpDef.cpp \
    42. controller/PhpLoadLanguage.cpp \
    43. controller/PhpParser.cpp \
    44. controller/PhpUtils.cpp \
    45. model/Attribute.cpp \
    46. model/Class.cpp \
    47. model/Const.cpp \
    48. model/PhpClassTypeModelAbs.cpp \
    49. model/Restriction.cpp \
    50. model/Trait.cpp \
    51. model/Interface.cpp \
    52. model/Method.cpp \
    53. model/Param.cpp
    54.  
    55. HEADERS += Php.h\
    56. php_global.h \
    57. controller/PhpDef.h \
    58. controller/PhpLoadLanguage.h \
    59. controller/PhpParser.h \
    60. controller/PhpUtils.h \
    61. model/Attribute.h \
    62. model/Class.h \
    63. model/Const.h \
    64. model/Param.h \
    65. model/PhpClassTypeModelAbs.h \
    66. model/Restriction.h \
    67. model/Interface.h \
    68. model/Method.h \
    69. model/Trait.h
    70.  
    71. DESTDIR = ../
    72.  
    73. unix {
    74. target.path = /usr/lib
    75. INSTALLS += target
    76. }
    To copy to clipboard, switch view to plain text mode 
    Project.pro
    Qt Code:
    1. #-------------------------------------------------
    2. #
    3. # Project created by QtCreator 2017-02-12T18:33:25
    4. #
    5. #-------------------------------------------------
    6.  
    7. QT -= gui
    8.  
    9. CONFIG += c++11
    10.  
    11. greaterThan(QT_MAJOR_VERSION, 4): QT += widgets xml xmlpatterns
    12.  
    13. TARGET = project
    14. TEMPLATE = lib
    15.  
    16. DEFINES += PROJECT_LIBRARY
    17.  
    18. # The following define makes your compiler emit warnings if you use
    19. # any feature of Qt which as been marked as deprecated (the exact warnings
    20. # depend on your compiler). Please consult the documentation of the
    21. # deprecated API in order to know how to port your code away from it.
    22. DEFINES += QT_DEPRECATED_WARNINGS
    23.  
    24. # You can also make your code fail to compile if you use deprecated APIs.
    25. # In order to do so, uncomment the following line.
    26. # You can also select to disable deprecated APIs only up to a certain version of Qt.
    27. #DEFINES += QT_DISABLE_DEPRECATED_BEFORE=0x060000 # disables all the APIs deprecated before Qt 6.0.0
    28.  
    29. DEPENDPATH += . ../language/core \
    30. ../language/php
    31.  
    32. INCLUDEPATH += . ../language/core \
    33. ../language/php
    34.  
    35. SOURCES += \
    36. view/ProjectDlg.cpp \
    37. controller/Manifest.cpp \
    38. controller/ProjectBuilder.cpp \
    39. model/Project.cpp
    40.  
    41. HEADERS +=\
    42. project_global.h \
    43. view/ProjectDlg.h \
    44. controller/Manifest.h \
    45. controller/ProjectBuilder.h \
    46. model/Project.h
    47.  
    48. DESTDIR = ../
    49.  
    50. unix {
    51. target.path = /usr/lib
    52. INSTALLS += target
    53. }
    54.  
    55. FORMS += \
    56. view/ProjectDlg.ui
    To copy to clipboard, switch view to plain text mode 
    Examples.pro
    Qt Code:
    1. TEMPLATE = subdirs
    2.  
    3. SUBDIRS += \
    4. createproject
    To copy to clipboard, switch view to plain text mode 
    Createproject.pro
    Qt Code:
    1. #-------------------------------------------------
    2. #
    3. # Project created by QtCreator 2017-02-13T12:14:49
    4. #
    5. #-------------------------------------------------
    6.  
    7. QT += core gui
    8.  
    9. CONFIG += c++11
    10.  
    11. greaterThan(QT_MAJOR_VERSION, 4): QT += widgets xml xmlpatterns
    12.  
    13. TARGET = createproject
    14. TEMPLATE = app
    15.  
    16. # The following define makes your compiler emit warnings if you use
    17. # any feature of Qt which as been marked as deprecated (the exact warnings
    18. # depend on your compiler). Please consult the documentation of the
    19. # deprecated API in order to know how to port your code away from it.
    20. DEFINES += QT_DEPRECATED_WARNINGS
    21.  
    22. # You can also make your code fail to compile if you use deprecated APIs.
    23. # In order to do so, uncomment the following line.
    24. # You can also select to disable deprecated APIs only up to a certain version of Qt.
    25. #DEFINES += QT_DISABLE_DEPRECATED_BEFORE=0x060000 # disables all the APIs deprecated before Qt 6.0.0
    26.  
    27. DEPENDPATH += . ../../common/project
    28.  
    29. INCLUDEPATH += . ../../common/project
    30.  
    31. LIBS''= -L../../common -lproject
    32.  
    33. SOURCES += main.cpp\
    34. mainwindow.cpp
    35.  
    36. HEADERS += mainwindow.h
    37.  
    38. FORMS += mainwindow.ui
    To copy to clipboard, switch view to plain text mode 

    All this, for the following, if I build each library separately no problem, all compile.

    But when I decide to compile createproject (which is a test executable) to test the correct execution of the code and the links to the libraries, I get the following error:

    Qt Code:
    1. ../../../../editor/common/language/php/model/Attribute.h:8:28: fatal error: model / ModelObj.h: No such file or directory
    2. #include "model / ModelObj.h"
    3. ^
    To copy to clipboard, switch view to plain text mode 
    I have reviewed everything and from what I see, everything is fine, or so I think. Even if I build createproject without run command, if it compiles.

    I'm working on
    Debian 9 64bit
    Qt 5.7.1
    QtCreator 4.2.0

    What can I be doing wrong? If you need any additional information let me know.

    Thanks in advance for your answers and help.

  2. #2
    Join Date
    Jan 2006
    Location
    Graz, Austria
    Posts
    8,416
    Thanks
    37
    Thanked 1,544 Times in 1,494 Posts
    Qt products
    Qt3 Qt4 Qt5
    Platforms
    Unix/X11 Windows

    Default Re: Problem with dependency on shared library and internal class

    Does your INCLUDEPATH contain the directory that has the "model" directory as its child?

    Cheers,
    _

    P.S: your Editor.pro has a circular dependency
    Qt Code:
    1. com.depends = common
    2. common.depends = com
    To copy to clipboard, switch view to plain text mode 

  3. #3
    Join Date
    Jan 2015
    Location
    Barquisimeto, Venezuela
    Posts
    24
    Thanks
    2
    Qt products
    Qt4 Qt5
    Platforms
    Unix/X11 Android

    Default Re: Problem with dependency on shared library and internal class

    Hi anda_skoa, thanks for your quick reply.

    I apologize for not explaining this detail of relationship between libraries.

    The php library depends on the core library within the subproject language. That's where the problem comes to me.

    Answering your question, yes. As you can see in php.pro, in the INCLUDEPATH is the core library on which it depends, where the model directory is part of core.

    Regarding the circular dependency, yes, I know that I have it, and I have to solve that inconsistency, but it's because I have a test code and implemented it directly in a project base class to test the operation and see how to decouple that section of code .

  4. #4
    Join Date
    Jan 2006
    Location
    Graz, Austria
    Posts
    8,416
    Thanks
    37
    Thanked 1,544 Times in 1,494 Posts
    Qt products
    Qt3 Qt4 Qt5
    Platforms
    Unix/X11 Windows

    Default Re: Problem with dependency on shared library and internal class

    You'll have to check the compiler invocation output, i.e. check if the -I directives include the path to the "core" directory.

    Btw, your code snippets and your directory tree overview do not match, you Php.pro add "../core" but in your directory tree it is "../Core"

    Cheers,
    _

  5. #5
    Join Date
    Jan 2015
    Location
    Barquisimeto, Venezuela
    Posts
    24
    Thanks
    2
    Qt products
    Qt4 Qt5
    Platforms
    Unix/X11 Android

    Default Re: Problem with dependency on shared library and internal class

    Hello anda_skoa, checking the code about your comment, because it is only a transcription error.

    But I tell you something very curious and strange at the same time.

    All the code that I put in the first post, was only a portion of all the code that I have programmed, only for purposes of my problem I reduced to those few files.

    But the curious detail is that I took only the subprojects involved in the subproject project and language, to make use of them separately and test their operation and what was the surprise, which compiled and executed everything without problems.

    What I can think of is that the problem is given by the cyclical dependence I have among the subprojects, which you referred to.

    Qt Code:
    1. Com.depends = common
    2. Common.depends = com
    To copy to clipboard, switch view to plain text mode 

    But at the same time it generates some noise, since in particular the project and language subprojects do not depend on the subproject com.

    If you consider any other reason why this problem may occur, I would like to read your opinion.

    Thanks in advance.

  6. #6
    Join Date
    Jan 2015
    Location
    Barquisimeto, Venezuela
    Posts
    24
    Thanks
    2
    Qt products
    Qt4 Qt5
    Platforms
    Unix/X11 Android

    Smile Re: Problem with dependency on shared library and internal class

    Hello everyone.

    Reacting the post, to comment that I have finally been able to solve the problem of dependencies between libraries that I have been presenting for some weeks that I decided to reorganize my project by subprojects and / or libraries.

    To freshen up a bit, the problem came to me when my main application called a bookstore, but the latter in turn called another bookstore.

    The solution that I have achieved after researching and studying the documentation of qmake, which did not guide me much, especially in the link between multiple dependencies of bookstores.

    Well, to the point. The solution is given by the following considerations.

    If a library or application needs a library, the documentation tells us to do the following, in the .pro of our library and / or application:

    Qt Code:
    1. DEPENDPATH + =. /Path/to/my/lib1
    2.  
    3. INCLUDEPATH + =. /Path/to/my/lib1
    4.  
    5. LIBS + = -L /path/to/my/lib1 -llib1
    To copy to clipboard, switch view to plain text mode 

    But what happens if our library lib1, needs another library, say lib2, according to the documentation we should put:

    Qt Code:
    1. DEPENDPATH + =. /Path/to/my/lib2
    2.  
    3. INCLUDEPATH + =. /Path/to/my/lib2
    4.  
    5. LIBS + = -L /path/to/my/lib2 -llib2
    To copy to clipboard, switch view to plain text mode 

    So far all "OK", but when we decide to do a test run, to verify the correct operation of our libraries, shows us the following error:

    Qt Code:
    1. /Path/to/my/executable: error while loading shared libraries: lib2.so.1: can not open shared object file: No such file or directory
    To copy to clipboard, switch view to plain text mode 

    Here was where I lost in the documentation, because I did not get information related to this type of cases, and although, I got in huge amount of forums, information like this:

    Qt Code:
    1. Export LD_LIBRARY_PATH = /path/to/root/installation/directory/lib/root/
    To copy to clipboard, switch view to plain text mode 

    He was not happy, considering that he could do everything from qmake, and indeed it is.

    The only thing to do is to add the same lines in this case, from our lib1 library in our application and / or "top level" library, so the .pro of our application and / or "top level" Would be as follows:

    Qt Code:
    1. DEPENDPATH + =. \
    2. /Path/to/my/otherLibs \
    3. /Path/to/my/lib2
    4.  
    5. INCLUDEPATH + =. \
    6. /Path/to/my/otherLibs \
    7. /Path/to/my/lib2
    8.  
    9. LIBS + = -L/path/to/my/otherLibs -lotherLibs \
    10. -L/path/to/my/lib2 -llib2
    To copy to clipboard, switch view to plain text mode 

    And with this we have solved the problem of loading of shared libraries, or at least I have worked this way.

    I hope I'm not making a mistake with this explanation, and if I'm wrong I'm open to criticism and / or advice.

    In the same way, I hope it will help somebody else who has these same problems.

  7. #7
    Join Date
    Jan 2006
    Location
    Graz, Austria
    Posts
    8,416
    Thanks
    37
    Thanked 1,544 Times in 1,494 Posts
    Qt products
    Qt3 Qt4 Qt5
    Platforms
    Unix/X11 Windows

    Default Re: Problem with dependency on shared library and internal class

    Each library will usually have a ".pri" files (Qt project include) that adds the necessary elements to each variable.

    The application then simply includes those and thus gets the full modification.

    E.g. in your case, which apparently has headers and library in the source directory

    Qt Code:
    1. INCLUDEPATH += $$PWD
    2. DEPENDPATH += $$PWD
    3. LIBS += -l$$PWD -lnameoflib
    To copy to clipboard, switch view to plain text mode 

    Cheers,
    _

Similar Threads

  1. Problem using QWT shared library
    By klenze in forum Qwt
    Replies: 1
    Last Post: 5th December 2011, 11:39
  2. Qmake fails to set shared library dependency
    By jkv in forum Qt Programming
    Replies: 5
    Last Post: 3rd September 2009, 14:44
  3. qmake: dependency of application on common shared library
    By PeterWurmsdobler in forum Qt Programming
    Replies: 5
    Last Post: 27th March 2009, 17:13
  4. so shared library problem
    By mtrpoland in forum Newbie
    Replies: 3
    Last Post: 13th August 2007, 22:51
  5. shared library problem
    By nhatkhang in forum KDE Forum
    Replies: 9
    Last Post: 28th November 2006, 05:07

Tags for this Thread

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.