This forum has been archived. All content is frozen. Please use KDE Discuss instead.

"undefined reference to" error [SOLVED]

Tags: None
(comma "," separated)
Musikolo
Registered Member
Posts
27
Karma
0
OS
Hi mates,

I'm working on a project where I would like to reorganize a bit everything in different modules. What I pretend is to to have the code of each module in a separate folder. To do so, I'm doing a HelloWorld-like test and I have found no way to get rid of the next error:

Code: Select all
... etc ...
Linking CXX executable kvirustotal
/usr/bin/cmake -E cmake_link_script CMakeFiles/kvirustotal.dir/link.txt --verbose=1                                                                                                                                                         
/usr/bin/c++    -Wnon-virtual-dtor -Wno-long-long -ansi -Wundef -Wcast-align -Wchar-subscripts -Wall -W -Wpointer-arith -Wformat-security -fno-exceptions -DQT_NO_EXCEPTIONS -fno-check-new -fno-common -Werror=return-type -Woverloaded-virtual -fno-threadsafe-statics -fvisibility=hidden -fvisibility-inlines-hidden -g -O2 -fno-reorder-blocks -fno-schedule-insns -fno-inline  -Wl,--enable-new-dtags  CMakeFiles/kvirustotal.dir/kvirustotal_automoc.o CMakeFiles/kvirustotal.dir/taskschedulerjob.o CMakeFiles/kvirustotal.dir/taskscheduler.o CMakeFiles/kvirustotal.dir/settingsdialog.o CMakeFiles/kvirustotal.dir/welcomepage.o CMakeFiles/kvirustotal.dir/welcomewizard.o CMakeFiles/kvirustotal.dir/filehasher.o CMakeFiles/kvirustotal.dir/reportrowviewhandler.o CMakeFiles/kvirustotal.dir/urlreport.o CMakeFiles/kvirustotal.dir/servicebasicreply.o CMakeFiles/kvirustotal.dir/abstractreport.o CMakeFiles/kvirustotal.dir/taskviewhandler.o CMakeFiles/kvirustotal.dir/taskrowviewhandler.o CMakeFiles/kvirustotal.dir/reportviewhandler.o CMakeFiles/kvirustotal.dir/httpconnector.o CMakeFiles/kvirustotal.dir/filereport.o CMakeFiles/kvirustotal.dir/mainwindow.o CMakeFiles/kvirustotal.dir/main.o CMakeFiles/kvirustotal.dir/settings.o  -o kvirustotal -rdynamic -L/home/musikolo/workspace-qt/kvirustotal/build/lib /usr/lib/libkdeui.so.5.6.0 /usr/lib/libkfile.so.4.6.0 -lqjson -lqca lib/libkvirustotal_core.so /usr/lib/libkio.so.5.6.0 /usr/lib/libQtNetwork.so /usr/lib/libQtXml.so /usr/lib/libkdeui.so.5.6.0 /usr/lib/libQtGui.so /usr/lib/libQtSvg.so /usr/lib/libkdecore.so.5.6.0 /usr/lib/libQtDBus.so /usr/lib/libQtCore.so -lpthread -Wl,-rpath,/home/musikolo/workspace-qt/kvirustotal/build/lib:
CMakeFiles/kvirustotal.dir/mainwindow.o: In function `MainWindow':
/home/musikolo/workspace-qt/kvirustotal/mainwindow.cpp:56: undefined reference to `HelloCore::HelloCore()'
/home/musikolo/workspace-qt/kvirustotal/mainwindow.cpp:56: undefined reference to `HelloCore::~HelloCore()'
collect2: ld returned 1 exit status
make[2]: *** [kvirustotal] Error 1
make[2]: Leaving directory `/home/musikolo/workspace-qt/kvirustotal/build'
make[1]: *** [CMakeFiles/kvirustotal.dir/all] Error 2
make[1]: Leaving directory `/home/musikolo/workspace-qt/kvirustotal/build'
make: *** [all] Error 2


[musikolo@MyPC build]$ ls -l lib/
total 116
-rwxr-xr-x 1 musikolo users 115805 Jul 10 02:36 libkvirustotal_core.so


[musikolo@MyPC build]$ grep HelloCore lib/libkvirustotal_core.so
Binary file lib/libkvirustotal_core.so matches


I have created a new folder named "core" where I would like to put all core code. Currently I have just created a very simple class called HelloCore that how prints a "Hello Core!" message.

This the file $/core/CMakeLists.txt file:
Code: Select all
set(kvirustotal_core_SRCS
      hellocore.cpp)

set(kvirustotal_core_LIBS
      ${KDE4_KDECORE_LIBS}
      ${KDE4_KDEUI_LIBS}
      ${KDE4_KUTILS_LIBS})

kde4_add_library(kvirustotal_core SHARED ${kvirustotal_core_SRCS})
target_link_libraries(kvirustotal_core ${kvirustotal_core_LIBS})


And this is the main CMakeLists.txt:
Code: Select all
project(KVirusTotal)
cmake_minimum_required(VERSION 2.6)

#if you don't want the full compiler output, remove the following line
SET(CMAKE_VERBOSE_MAKEFILE ON)

find_package(KDE4 REQUIRED)
find_package(QCA2 REQUIRED)

set(CMAKE_BUILD_TYPE Debug)
#set(CMAKE_BUILD_TYPE Release)

include_directories(
      ${CMAKE_SOURCE_DIR}/core/
      ${CMAKE_BINARY_DIR}/core/
      ${KDE4_INCLUDES}
      ${QCA2_INCLUDE_DIR}
      ${CMAKE_CURRENT_BINARY_DIR})

add_subdirectory(core)
add_subdirectory(resources)
add_subdirectory(translations)

set(kvirustotal_SRCS
      taskschedulerjob.cpp
      taskscheduler.cpp
      settingsdialog.cpp
      welcomepage.cpp
      welcomewizard.cpp
      filehasher.cpp
      reportrowviewhandler.cpp
      urlreport.cpp
      servicebasicreply.cpp
      abstractreport.cpp
      taskviewhandler.cpp
      taskrowviewhandler.cpp
      reportviewhandler.cpp
      reportviewhandler.cpp
      httpconnector.cpp
      filereport.cpp
      mainwindow.cpp
      main.cpp)

kde4_add_kcfg_files(kvirustotal_SRCS settings.kcfgc)
kde4_add_ui_files(kvirustotal_SRCS mainwindow.ui)
qt4_automoc(${kvirustotal_SRCS})

kde4_add_executable(kvirustotal ${kvirustotal_SRCS})

set( kvirustotal_LIBS
      ${KDE4_KDEUI_LIBS}
      ${KDE4_LIBS}
      ${KDE4_KFILE_LIBRARY}
      qjson
      qca
      kvirustotal_core)

target_link_libraries(kvirustotal ${kvirustotal_LIBS})
install( TARGETS kvirustotal  ${INSTALL_TARGETS_DEFAULT_ARGS} )
install( FILES kvirustotal.desktop  DESTINATION ${XDG_APPS_INSTALL_DIR} )


Any clue about what I have done wrong? :-\

Thanks in advance. :)

Last edited by Musikolo on Sun Jul 10, 2011 5:36 pm, edited 1 time in total.
Musikolo
Registered Member
Posts
27
Karma
0
OS
Hi guys,

I found the solution here: http://techbase.kde.org/Development/Tutorials/Creating_Libraries

Thanks everyone. ;)


Bookmarks



Who is online

Registered users: bartoloni, Bing [Bot], Evergrowing, Google [Bot]