[CMake] Problem linking to shared library (inside project) after upgrade to cmake 2.6

Yogesh Marwaha yogeshm.007 at gmail.com
Sun Jul 13 14:27:19 EDT 2008


2008/7/13 Bill Hoffman <bill.hoffman at kitware.com>:
> Little t usually means local linkage, so that would be why you can not see
> the symbols from an external library.  I don't think this is a CMake issue,
> but rather a C++ issue of some sort.  What does the header file for
> GApplication and the .cxx file look like?
>

There is not much in the GApplicatin header/source.

Here is the header:

#ifndef GAPPLICATION_H
#define GAPPLICATION_H
#include <KApplication>
class GApplication: public KApplication{
Q_OBJECT
public:
    GApplication();
    ~GApplication();
private slots:
    void init();
};
#endif

Here is the source:
#include "myapplication.h"

#include "gravity.h"
#include "taglib/fileref.h"
#include "gfiletyperesolver.h"
#include "playlistiohandler.h"
#include "gdevicehandler.h"
#include <KDE/KGlobalAccel>
#include <KDE/KMessage>
#include <KDE/KPassivePopupMessageHandler>
GApplication::GApplication() : KApplication( true ){
    setApplicationName("Gravity");
    KMessage::setMessageHandler(new KPassivePopupMessageHandler());
    KGlobalAccel::self()->setEnabled(true);
    TagLib::FileRef::addFileTypeResolver(new GFileTypeResolver);
    Gravity::self();
    Gravity::self()->systemTrayIcon();
}
GApplication::~GApplication(){
    Gravity::self()->deleteSelf();
}
void GApplication::init(){
}
#include "myapplication.moc"


=====================
CMakeFiles/Gravity.dir/main.o: In function `main':
/home/yogesh/gravity/app/main.cpp:10: undefined reference to
`GApplication::GApplication()'
/home/yogesh/gravity/app/main.cpp:12: undefined reference to `Gravity::self()'
/home/yogesh/gravity/app/main.cpp:12: undefined reference to
`Gravity::gUIInterfaceManager() const'
/home/yogesh/gravity/app/main.cpp:13: undefined reference to
`GApplication::~GApplication()'
collect2: ld returned 1 exit status
make[2]: *** [app/Gravity] Error 1
make[1]: *** [app/CMakeFiles/Gravity.dir/all] Error 2
make: *** [all] Error 2
=====================
The above linking error is shown when *app* folder is processed which
has only one main.cpp file: -
#include <KDE/KCmdLineArgs>
#include <KDE/KAboutData>
#include <QString>
#include "gravity.h"
#include "myapplication.h"
int main(int argc, char **argv){
    KAboutData aboutData("gravity", "gravity", ki18n("Gravity"),
"0.1", ki18n("Media player"),  KAboutData::License_LGPL_V2);
    KCmdLineArgs::init(argc, argv, &aboutData);
    GApplication app;
    app.disableSessionManagement();
    Gravity::self()->gUIInterfaceManager();
    return app.exec();
}

...thats why there are only four references to complaint about, and
the make quits.

If I change CMakeLists.txt in base folder to process *modules* folder
before *app* then there are hundreds of similar errors shown.

Just to check (not to prove anything) I created another project
(plain/c++) using similar setup which creates a shared library and an
executable which links to that shared library. It got
compiled/linked/installed/executed as expected.

I can supply a copy of complete source code if someone has KDE4
installed (for development) and wants to try it.

-- 
Yogesh M


More information about the CMake mailing list