[prev in list] [next in list] [prev in thread] [next in thread] 

List:       kde-devel
Subject:    Re: Custom EXPORT macro won't expand when included outside lib
From:       Luiz_Romário_Santana_Rios <luizromario () gmail ! com>
Date:       2012-09-15 14:26:53
Message-ID: CABCW-kr0rn_ZECPjj-Rw_cD058DGwSVCC7wv4PP0t0gX98BP6Q () mail ! gmail ! com
[Download RAW message or body]

2012/9/12 Sandro Andrade <sandroandrade@kde.org>:
> On Wed, Sep 12, 2012 at 7:13 PM, Luiz Romário Santana Rios
> <luizromario@gmail.com> wrote:
> > 2012/9/11 Sandro Andrade <sandroandrade@kde.org>:
> > > On Mon, Sep 10, 2012 at 9:29 PM, Luiz Romário Santana Rios
> > > <luizromario@gmail.com> wrote:
> > > > Hi.
> > > > 
> > > > So, I recently started to write a "pluggable" library. You can check it from
> > > > here:
> > > > http://quickgit.kde.org/index.php?p=scratch%2Fromariorios%2Flibkodri.git&a=summary
> > > >                 
> > > > .
> > > > 
> > > > It was all good until I tried to write a dummy plugin for it (currently
> > > > available in the dummy_packagesource branch of the above repo). It was a
> > > > pretty trivial plugin, it just implemented the pure virtual functions from
> > > > the interface. But I kept getting this error:
> > > > 
> > > > [100%] Building CXX object
> > > > packagesources/CMakeFiles/kodri_packagesource_dummy.dir/dummypackagesource.o
> > > > In file included from
> > > > /home/kde4/kde-master-install/include/kodri/abstractpackagesource.h:29:0,
> > > > from
> > > > /home/kde4/kdesrc/libkodri/packagesources/dummypackagesource.h:23,
> > > > from
> > > > /home/kde4/kdesrc/libkodri/packagesources/dummypackagesource.cpp:20:
> > > > /home/kde4/kde-master-install/include/kodri/version.h:31:28: error: expected
> > > > initializer before ‘:’ token
> > > > /home/kde4/kdesrc/libkodri/packagesources/dummypackagesource.cpp:1381:1:
> > > > error: expected ‘}’ at end of input
> > > > make[2]: **
> > > > [packagesources/CMakeFiles/kodri_packagesource_dummy.dir/dummypackagesource.o]
> > > >  Erro 1
> > > > make[1]: ** [packagesources/CMakeFiles/kodri_packagesource_dummy.dir/all]
> > > > Erro 2
> > > > make: ** [all] Erro 2
> > > > 
> > > > I then suspected that the KODRI_EXPORT macro wasn't being expanded when the
> > > > exported classes were included outside the library. Then I manually replaced
> > > > KODRI_EXPORT by __attribute__ ((visibility("default")) and, as I suspected,
> > > > the error vanished. Of course, other errors appeared afterwards, but I'll
> > > > try to solve them later.
> > > > 
> > > > My question is: why doesn't the macro expand? I followed the techbase
> > > > tutorial on creating new libraries step by step, so I can't see where I got
> > > > it wrong.
> > > 
> > > It doesn't expand because you have a wrong kodri_export.h:
> > > 
> > > #ifndef KODRI_EXPORT
> > > # if defined(MAKE_KODRI_LIB)
> > > #  define KODRI_EXPORT KDE_EXPORT
> > > # else
> > > #  define KODRI_IMPORT KDE_IMPORT
> > > # endif
> > > #endif
> > > 
> > > It should be:
> > > 
> > > #ifndef KODRI_EXPORT
> > > # if defined(MAKE_KODRI_LIB)
> > > #  define KODRI_EXPORT KDE_EXPORT
> > > # else
> > > #  define KODRI_EXPORT KDE_IMPORT
> > > # endif
> > > #endif
> > Whoops...
> > 
> > Thank you, I'd take ages to notice that.
> > 
> > > 
> > > Besides that, I'd rearrange CMakeLists.txt's in order to have lib and
> > > plugin as sibling sub-CMakeLists.txt (or even as separated projects).
> > > Find a possible refactoring at:
> > > 
> > > http://d01.megashares.com/dl/dTjbpUz/libkodri-refactored.tar.gz
> > I'll take a look at it.
> > 
> > > 
> > > Plugin's CMakeLists.txt also contains some errors:
> > > 
> > > target_link_libraries(kodri_packagesource_dummy ${KDE4_CORE_LIBS}
> > > ${KDE4_KODRI_LIBS})
> > > 
> > > The correct var is ${KDE4_KDECORE_LIBS}. ${KDE4_KODRI_LIBS} isn't
> > > automatically generated
> > > at all. You should write a cmake module in order to detect your library.
> > I have this in CMakeLists.txt:37:
> > 
> > install(TARGETS kodri EXPORT kdelibsLibraryTargets
> > ${INSTALL_TARGETS_DEFAULT_ARGS})
> > 
> > Doesn't it do the job?
> 
> Not completely. If you try to build the plugin in an environment which
> doesn't have your
> lib installed, cmake won't detect that. You'll get only a compiler error.
> 
> See for example:
> https://projects.kde.org/projects/extragear/kdevelop/kdevelop/repository/revisions/master/entry/cmake/modules/FindKDevPlatform.cmake
> 

True. Now I remember seeing something like this when taking a look at
KTelepathy.

Thanks.

> 
> That will allow you to use a:
> 
> find_package(Kodri 1.0.0 REQUIRED)
> 
> in the plugin's CMakeLists.txt. If it's not found cmake will early detect that.
> 
> []s,
> Sandro
> 
> > 
> > Thanks for the pointers.
> > 
> > > 
> > > Sandro
> > > 
> > > > 
> > > > Best regards.
> > > > 
> > > > --
> > > > Luiz Romário Santana Rios
> > > > 
> > > > 
> > > > > > Visit http://mail.kde.org/mailman/listinfo/kde-devel#unsub to unsubscribe
> > > > > > <<
> > > > 
> > > 
> > > > > Visit http://mail.kde.org/mailman/listinfo/kde-devel#unsub to unsubscribe \
> > > > > <<
> > 
> > 
> > 
> > --
> > Luiz Romário Santana Rios
> > 
> > > > Visit http://mail.kde.org/mailman/listinfo/kde-devel#unsub to unsubscribe <<
> 
> > > Visit http://mail.kde.org/mailman/listinfo/kde-devel#unsub to unsubscribe <<



-- 
Luiz Romário Santana Rios

> > Visit http://mail.kde.org/mailman/listinfo/kde-devel#unsub to unsubscribe <<


[prev in list] [next in list] [prev in thread] [next in thread] 

Configure | About | News | Add a list | Sponsored by KoreLogic