This forum has been archived. All content is frozen. Please use KDE Discuss instead.
Only forum.kde.org related discussions fall in the scope of the Forum Feedback area. Please take a minute to find the appropriate section for your query before posting here.

cmake error (?) with QtNetwork

Tags: None
(comma "," separated)
User avatar
tinosezc
Registered Member
Posts
14
Karma
0
OS

cmake error (?) with QtNetwork

Sat Jun 08, 2013 8:37 am
I found a problem in building project with QtNetwork
May be must be inserted in bug list, KDE or cmake ?,

starting from a KDE Graphical template i build this project

Code: Select all
kgraphicaltest.h

#include "ui_prefs_base.h"
#include <QtNetwork>


class KGraphicalTestView;
class KToggleAction;
class KUrl;

class KGraphicalTest : public KXmlGuiWindow
{
    Q_OBJECT
public:
    /**
     * Default Constructor
     */
    KGraphicalTest();

    /**
     * Default Destructor
     */
    virtual ~KGraphicalTest();

private slots:
    void fileNew();
    void optionsPreferences();

private:
    void setupActions();


    QUdpSocket *udpSocket;



private:
    Ui::prefs_base ui_prefs_base ;
    KGraphicalTestView *m_view;

    KToggleAction *m_toolbarAction;
    KToggleAction *m_statusbarAction;
};

#endif // _KGraphicalTest_H_

--------------------------------------------------------
kgraphicaltest.cpp

#include "kgraphicaltest.h"
#include "kgraphicaltestview.h"
#include "settings.h"
#include "ui_prefs_base.h"

#include <QtGui/QDropEvent>

#include <KConfigDialog>
#include <KStatusBar>

#include <KAction>
#include <KActionCollection>
#include <KStandardAction>

#include <KLocale>

KGraphicalTest::KGraphicalTest()
    : KXmlGuiWindow(),
      m_view(new KGraphicalTestView(this))
{
     ................

   
    udpSocket = new QUdpSocket(this);

}

-------------------------------------

cmakelists.txt

set(kgraphicaltest_SRCS
   kgraphicaltest.cpp
   main.cpp
   kgraphicaltestview.cpp
 )

kde4_add_ui_files(kgraphicaltest_SRCS kgraphicaltestview_base.ui prefs_base.ui)

kde4_add_kcfg_files(kgraphicaltest_SRCS settings.kcfgc )

kde4_add_executable(kgraphicaltest ${kgraphicaltest_SRCS})

target_link_libraries(kgraphicaltest ${KDE4_KDEUI_LIBS} ${QT_QTDECLARATIVE_LIBRARY} )

install(TARGETS kgraphicaltest ${INSTALL_TARGETS_DEFAULT_ARGS} )


########### install files ###############

install( PROGRAMS kgraphicaltest.desktop  DESTINATION ${XDG_APPS_INSTALL_DIR} )
install( FILES kgraphicaltest.kcfg  DESTINATION  ${KCFG_INSTALL_DIR} )
install( FILES kgraphicaltestui.rc  DESTINATION  ${DATA_INSTALL_DIR}/kgraphicaltest )

add_subdirectory(qml)
-------------------------------------------

from build.make
...............
# External object files for target kgraphicaltest
kgraphicaltest_EXTERNAL_OBJECTS =

src/kgraphicaltest: src/CMakeFiles/kgraphicaltest.dir/kgraphicaltest_automoc.o
src/kgraphicaltest: src/CMakeFiles/kgraphicaltest.dir/kgraphicaltest.o
src/kgraphicaltest: src/CMakeFiles/kgraphicaltest.dir/main.o
src/kgraphicaltest: src/CMakeFiles/kgraphicaltest.dir/kgraphicaltestview.o
src/kgraphicaltest: src/CMakeFiles/kgraphicaltest.dir/settings.o
src/kgraphicaltest: src/CMakeFiles/kgraphicaltest.dir/build.make
src/kgraphicaltest: /usr/lib/libkdeui.so.5.10.3
src/kgraphicaltest: /usr/lib/libQtDeclarative.so
src/kgraphicaltest: /usr/lib/libkdecore.so.5.10.3
src/kgraphicaltest: /usr/lib/libQtDBus.so
src/kgraphicaltest: /usr/lib/libQtCore.so
src/kgraphicaltest: /usr/lib/libQtGui.so
src/kgraphicaltest: /usr/lib/libQtSvg.so
src/kgraphicaltest: src/CMakeFiles/kgraphicaltest.dir/link.txt
   @$(CMAKE_COMMAND) -E cmake_echo_color --switch=$(COLOR) --red --bold "Linking CXX executable kgraphicaltest"
   cd /workarea/projects/KGraphicalTest/build/src && $(CMAKE_COMMAND) -E cmake_link_script CMakeFiles/kgraphicaltest.dir/link.txt --verbose=$(VERBOSE)
   cd /workarea/projects/KGraphicalTest/build/src && /usr/bin/cmake -D_filename=/workarea/projects/KGraphicalTest/build/src/kgraphicaltest.shell -D_library_path_variable=LD_LIBRARY_PATH -D_ld_library_path="/workarea/projects/KGraphicalTest/build/lib/./:/usr/local/lib:/usr/lib:/usr/lib" -D_executable=/workarea/projects/KGraphicalTest/build/src/kgraphicaltest -P /usr/share/apps/cmake/modules/kde4_exec_via_sh.cmake


When project is built I get error message
undefined reference to symbol '_ZN10QUdpSocketC1EP7QObject'
note: '_ZN10QUdpSocketC1EP7QObject' is defined in DSO /usr/lib/libQtNetwork.so.4 so try adding it to the linker command line


so I insert in the cmakelists.txt
${QT_QTNETWORK_LIBRARY}


Code: Select all
cmakelists.txt modifified

set(kgraphicaltest_SRCS
   kgraphicaltest.cpp
   main.cpp
   kgraphicaltestview.cpp
 )

kde4_add_ui_files(kgraphicaltest_SRCS kgraphicaltestview_base.ui prefs_base.ui)

kde4_add_kcfg_files(kgraphicaltest_SRCS settings.kcfgc )

kde4_add_executable(kgraphicaltest ${kgraphicaltest_SRCS})

target_link_libraries(kgraphicaltest ${KDE4_KDEUI_LIBS} ${QT_QTDECLARATIVE_LIBRARY} ${QT_QTNETWORK_LIBRARY} )

install(TARGETS kgraphicaltest ${INSTALL_TARGETS_DEFAULT_ARGS} )


########### install files ###############

install( PROGRAMS kgraphicaltest.desktop  DESTINATION ${XDG_APPS_INSTALL_DIR} )
install( FILES kgraphicaltest.kcfg  DESTINATION  ${KCFG_INSTALL_DIR} )
install( FILES kgraphicaltestui.rc  DESTINATION  ${DATA_INSTALL_DIR}/kgraphicaltest )

------------------------------------------

the build.make became
.....................................
# External object files for target kgraphicaltest
kgraphicaltest_EXTERNAL_OBJECTS =

src/kgraphicaltest: src/CMakeFiles/kgraphicaltest.dir/kgraphicaltest_automoc.o
src/kgraphicaltest: src/CMakeFiles/kgraphicaltest.dir/kgraphicaltest.o
src/kgraphicaltest: src/CMakeFiles/kgraphicaltest.dir/main.o
src/kgraphicaltest: src/CMakeFiles/kgraphicaltest.dir/kgraphicaltestview.o
src/kgraphicaltest: src/CMakeFiles/kgraphicaltest.dir/settings.o
src/kgraphicaltest: src/CMakeFiles/kgraphicaltest.dir/build.make
src/kgraphicaltest: /usr/lib/libkdeui.so.5.10.3
src/kgraphicaltest: /usr/lib/libQtDeclarative.so
src/kgraphicaltest: /usr/lib/libQtNetwork.so
src/kgraphicaltest: /usr/lib/libkdecore.so.5.10.3
src/kgraphicaltest: /usr/lib/libQtDBus.so
src/kgraphicaltest: /usr/lib/libQtCore.so
src/kgraphicaltest: /usr/lib/libQtGui.so
src/kgraphicaltest: /usr/lib/libQtSvg.so
src/kgraphicaltest: src/CMakeFiles/kgraphicaltest.dir/link.txt
   @$(CMAKE_COMMAND) -E cmake_echo_color --switch=$(COLOR) --red --bold "Linking CXX executable kgraphicaltest"
   cd /workarea/projects/KGraphicalTest/build/src && $(CMAKE_COMMAND) -E cmake_link_script CMakeFiles/kgraphicaltest.dir/link.txt --verbose=$(VERBOSE)
   cd /workarea/projects/KGraphicalTest/build/src && /usr/bin/cmake -D_filename=/workarea/projects/KGraphicalTest/build/src/kgraphicaltest.shell -D_library_path_variable=LD_LIBRARY_PATH -D_ld_library_path="/workarea/projects/KGraphicalTest/build/lib/./:/usr/local/lib:/usr/lib:/usr/lib" -D_executable=/workarea/projects/KGraphicalTest/build/src/kgraphicaltest -P /usr/share/apps/cmake/modules/kde4_exec_via_sh.cmake


the missing library is inserted
src/kgraphicaltest: /usr/lib/libQtNetwork.so

the project is built.

Who is making mistake because with other objects ( widget or .. ) the corrisponding librarries are correctly inserted.
User avatar
bcooksley
Administrator
Posts
19765
Karma
87
OS

Re: cmake error (?) with QtNetwork

Sat Jun 08, 2013 10:24 am
It is probably an omission, as it would have initially worked until CMake / KDE binary building policies were tightened. This change meant that libraries now had to be explicitly linked, and not implicitly linked.

The bug in this case is in the template code.


KDE Sysadmin
[img]content/bcooksley_sig.png[/img]


Bookmarks



Who is online

Registered users: abc72656, Bing [Bot], daret, Google [Bot], lockheed, Sogou [Bot], Yahoo [Bot]