Page 2 of 2 FirstFirst 12
Results 21 to 28 of 28

Thread: project with a dll and a testprog (doesn't compile)

  1. #21
    Join Date
    Feb 2006
    Location
    Romania
    Posts
    2,744
    Thanks
    8
    Thanked 541 Times in 521 Posts
    Qt products
    Qt4
    Platforms
    Unix/X11 Windows

    Default Re: project with a dll and a testprog (doesn't compile)

    Yes. You didn't export anything for the library so the linker didn't need to create a lib.
    You have to add Q_DECL_EXPORT to every class you want to export.
    Something like:
    Qt Code:
    1. //==========================================================//
    2. // //
    3. // Diplomprojekt Calina (platformuebergreifende 3d GUI) //
    4. // //
    5. //==========================================================//
    6. // Autoren: Adam Celarek (diplom_arbeit at xibo at) //
    7. // Patrick Freninger () //
    8. // Sebastian Raggl () //
    9. //==========================================================//
    10.  
    11. /***************************************************************************
    12.  * This program is free software; you can redistribute it and/or modify *
    13.  * it under the terms of the GNU General Public License as published by *
    14.  * the Free Software Foundation; either version 2 of the License, or *
    15.  * (at your option) any later version. *
    16.  * *
    17.  * This program is distributed in the hope that it will be useful, *
    18.  * but WITHOUT ANY WARRANTY; without even the implied warranty of *
    19.  * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the *
    20.  * GNU General Public License for more details. *
    21.  * *
    22.  * You should have received a copy of the GNU General Public License *
    23.  * along with this program; if not, write to the *
    24.  * Free Software Foundation, Inc., *
    25.  * 59 Temple Place - Suite 330, Boston, MA 02111-1307, USA. *
    26.  ***************************************************************************/
    27. #ifndef CALINAGLWIDGET_H
    28. #define CALINAGLWIDGET_H
    29.  
    30. #include <QGLWidget>
    31. #include "helper.h"
    32.  
    33. namespace calina {
    34.  
    35. /**
    36.  * @brief
    37.  *
    38.  *
    39.  *
    40.  * @author Adam Celarek <testman@xibo.at>
    41.  * @todo Dokumentation von da Klassn.. Wegn Prototyp deadline keine Zeit..
    42.  */
    43.  
    44. class World;
    45.  
    46. class [B]Q_DECL_EXPORT[/B] GLWidget : public QGLWidget {
    47. Q_OBJECT
    48. public:
    49. GLWidget(WidgetList& widgetList, QObject *parent = 0);
    50. ~GLWidget();
    51.  
    52. void initializeGL();
    53. void resizeGL(int w, int h);
    54. void paintGL();
    55. World* parentWorld() const;
    56.  
    57. private:
    58. WidgetList& p_widgetList;
    59. };
    60.  
    61. }
    62.  
    63. #endif
    To copy to clipboard, switch view to plain text mode 

    I added them and got:
    Generating Code...
    cl -c -nologo -Zm300 -Zi -MDd -GR -EHsc -W3 -w34100 -w34189 -DUNICODE -D
    WIN32 -DQT_LARGEFILE_SUPPORT -DQT_DLL -DQT_XML_LIB -DQT_OPENGL_LIB -DQT_GUI_LIB
    -DQT_CORE_LIB -DQT_THREAD_SUPPORT -I"c:\Qt\4.3.0rc1\include\QtCore" -I"c:\Qt\4.3
    .0rc1\include\QtCore" -I"c:\Qt\4.3.0rc1\include\QtGui" -I"c:\Qt\4.3.0rc1\include
    \QtGui" -I"c:\Qt\4.3.0rc1\include\QtOpenGL" -I"c:\Qt\4.3.0rc1\include\QtOpenGL"
    -I"c:\Qt\4.3.0rc1\include\QtXml" -I"c:\Qt\4.3.0rc1\include\QtXml" -I"c:\Qt\4.3.0
    rc1\include" -I"." -I"c:\Qt\4.3.0rc1\include\ActiveQt" -I"debug" -I"." -I"c:\Qt\
    4.3.0rc1\mkspecs\default" -Fodebug\ @D:\DOCUME~1\Marcel\LOCALS~1\Temp\nm783.tmp
    moc_glwidget.cpp
    moc_graphicsobject.cpp
    moc_layout.cpp
    moc_widget.cpp
    Generating Code...
    link /LIBPATH:"c:\Qt\4.3.0rc1\lib" /NOLOGO /DEBUG /DLL /OUT:debug\calina
    .dll @D:\DOCUME~1\Marcel\LOCALS~1\Temp\nm784.tmp
    Creating library debug\calina.lib and object debug\calina.exp

    D:\Documents and Settings\Marcel\Desktop\calina\calina\calina>

  2. #22
    Join Date
    Jan 2006
    Location
    travelling
    Posts
    1,116
    Thanks
    8
    Thanked 127 Times in 121 Posts
    Qt products
    Qt4
    Platforms
    Unix/X11 Windows

    Default Re: project with a dll and a testprog (doesn't compile)

    Quote Originally Posted by marcel View Post
    Yes. You didn't export anything for the library so the linker didn't need to create a lib.
    You have to add Q_DECL_EXPORT to every class you want to export.
    Nice catch! however the solution isn't that simple... If Q_DECL_EXPORT is put then the linking of any prog against that lib will most probably fail... Either you already have a kind of config header file which is included by all other headers or you got to create one. Then place something like this in it :
    Qt Code:
    1. #ifdef _CALINA_LIB_BUILD_
    2. #if defined(QT_DLL) || defined(QT_SHARED)
    3. #define CALINA_EXPORT Q_DECL_EXPORT
    4. #else
    5. #define CALINA_EXPORT
    6. #endif
    7. #else
    8. #define CALINA_EXPORT Q_DECL_IMPORT
    9. #endif
    To copy to clipboard, switch view to plain text mode 
    Then place "DEFINES += CALINA_LIB_BUILD" inside the project file of the dll.
    And finally update all headers of the dll, as suggested by marcel but using CALINA_EXPORT instead of Q_DECL_EXPORT...
    Current Qt projects : QCodeEdit, RotiDeCode

  3. #23
    Join Date
    Feb 2006
    Location
    Romania
    Posts
    2,744
    Thanks
    8
    Thanked 541 Times in 521 Posts
    Qt products
    Qt4
    Platforms
    Unix/X11 Windows

    Default Re: project with a dll and a testprog (doesn't compile)

    It's even simpler, but I skipped this part because I figured he will always build the library alone, so only Q_DECL_EXPORT will be needed.
    Just add this to a header and include it in all the exported classes headers:
    Qt Code:
    1. #ifndef CALINA_GLOBAL_H
    2. #define CALINA_GLOBAL_H
    3.  
    4. #include <Qt/qglobal.h>
    5.  
    6. #ifdef CALINA_LIB
    7. # define CALINA_EXPORT Q_DECL_EXPORT
    8. #else
    9. # define CALINA_EXPORT Q_DECL_IMPORT
    10. #endif
    11.  
    12. #endif // CALINA_GLOBAL_H
    To copy to clipboard, switch view to plain text mode 
    You will have to prepend CALINA_EXPORT instead of Q_DECL_EXPORT.
    Also you have to add CALINA_LIB to the list of preprocessor definitions each time you want to build the lib.

    Regards

  4. #24
    Join Date
    Jan 2006
    Location
    travelling
    Posts
    1,116
    Thanks
    8
    Thanked 127 Times in 121 Posts
    Qt products
    Qt4
    Platforms
    Unix/X11 Windows

    Default Re: project with a dll and a testprog (doesn't compile)

    Quote Originally Posted by marcel View Post
    It's even simpler, but I skipped this part because I figured he will always build the library alone, so only Q_DECL_EXPORT will be needed.
    Just add this to a header and include it in all the exported classes headers:
    I don't recommend making it that simple because in case someone wants to embed the lib in another program (not link) then he will face weird linking errors (either he put the CALINA_BUILD and he is supposed to export symbols but how does an app achieve that? or he forget it and the linker search for exported symbols in an import library that of course does not exist...
    Current Qt projects : QCodeEdit, RotiDeCode

  5. #25
    Join Date
    Feb 2006
    Location
    Romania
    Posts
    2,744
    Thanks
    8
    Thanked 541 Times in 521 Posts
    Qt products
    Qt4
    Platforms
    Unix/X11 Windows

    Default Re: project with a dll and a testprog (doesn't compile)

    Yes, you have your point too.
    I guess he will use whatever he needs from what we've posted, since everything is pretty much covered.

    Regards

  6. The following user says thank you to marcel for this useful post:

    aMan (25th July 2007)

  7. #26
    Join Date
    Jul 2006
    Posts
    79
    Thanks
    13
    Thanked 2 Times in 2 Posts
    Qt products
    Qt4
    Platforms
    Unix/X11 Windows

    Default Re: project with a dll and a testprog (doesn't compile)

    Thank you for your answers, I'll try it tomorrow..

    I suppose that macro is only needed on windows and vs, right? I had no problems on Linux or on MinGW. How does this work with the gcc, why vs needs the macros and gcc not?

  8. #27
    Join Date
    Jan 2006
    Location
    travelling
    Posts
    1,116
    Thanks
    8
    Thanked 127 Times in 121 Posts
    Qt products
    Qt4
    Platforms
    Unix/X11 Windows

    Default Re: project with a dll and a testprog (doesn't compile)

    Quote Originally Posted by aMan View Post
    I suppose that macro is only needed on windows and vs, right? I had no problems on Linux or on MinGW. How does this work with the gcc, why vs needs the macros and gcc not?
    The macro is not needed on other OS than Windows (I'm sure about Linux but I have not tested under Mac...). As it is needed on one platform it becomes needed on all (I mean putting the CALINA_EXPORT in front of your classes decl). Hopefully Qt is smart enough to leave Q_DECL_EXPORT and Q_DECL_IMPORT empty (while defined) on platforms that do not need them
    Current Qt projects : QCodeEdit, RotiDeCode

  9. The following user says thank you to fullmetalcoder for this useful post:

    aMan (25th July 2007)

  10. #28
    Join Date
    Jul 2006
    Posts
    79
    Thanks
    13
    Thanked 2 Times in 2 Posts
    Qt products
    Qt4
    Platforms
    Unix/X11 Windows

    Default Re: project with a dll and a testprog (doesn't compile)

    Thank you, you are greate..
    It works now..

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.