Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

'undefined reference to' with cmake

Tags:

c++

cmake

So, I am trying to write an applet for school, and part of it requires using cmake. I have two different classes contained in their own files, and I use them as part of the main class. I have included their headers as such in the main project header:

#include /path/to/header/1.h
#include /path/to/header/2.h

The problem I have is that when I run make after I've run cmake, I get undefined reference errors for any instance in which I try to use one of the two libraries. I know that it has to do with linker errors, but since I'm new to cmake, I'm not exactly sure what the proper way to use TARGET_LINK_LIBRARIES would be.

EDIT

After linking/associating my libraries, I have the following:

CMakeLists.txt:

# A name for the project
project(plasma-engine-gdrive)

# Find the required libaries
find_package(KDE4 REQUIRED)
include(KDE4Defaults)

add_definitions (${QT_DEFINITIONS} ${KDE4_DEFINITIONS}, -std=c++0x)
include_directories(
   ${CMAKE_SOURCE_DIR}
   ${CMAKE_BINARY_DIR}
   ${KDE4_INCLUDES}
   ./include
   ./lib
   )

set (GOOGLE_LIBS include/atom_helper.h include/util/string_utils.h include/client/doc_list_service.h include/client/service.h)
set (GOOGLE_SRCS include/atom_helper.cc include/util/string_utils.cc include/client/doc_list_service.cc include/client/service.cc)

# We add our source code here
set(gdrive_engine_SRCS gdriveengine.cpp)

add_library (DataWrapper include/DataWrapper.cpp include/DataWrapper.h)
add_library (GData ${GOOGLE_SRCS} ${GOOGLE_LIBS})

# Now make sure all files get to the right place
kde4_add_plugin(plasma_engine_gdrive ${gdrive_engine_SRCS})
target_link_libraries(plasma_engine_gdrive
                      GData
                      DataWrapper
                      ${KDE4_KDECORE_LIBS}
                      ${KDE4_PLASMA_LIBS})

install(TARGETS plasma_engine_gdrive
        DESTINATION ${PLUGIN_INSTALL_DIR})

install(FILES plasma-engine-gdrive.desktop
        DESTINATION ${SERVICES_INSTALL_DIR})

There are also too many errors to put here. Here's a few:

/usr/include/c++/4.6/bits/stl_map.h:467: undefined reference to `Glib::ustring::ustring()'
lib/libGData.a(atom_helper.o): In function `pair<Glib::ustring, Glib::ustring, void>':
/usr/include/c++/4.6/bits/stl_pair.h:132: undefined reference to `Glib::ustring::ustring(Glib::ustring const&)'
/usr/include/c++/4.6/bits/stl_pair.h:132: undefined reference to `Glib::ustring::ustring(Glib::ustring const&)'
lib/libGData.a(atom_helper.o): In function `pair<Glib::ustring, Glib::ustring>':
/usr/include/c++/4.6/bits/stl_pair.h:137: undefined reference to `Glib::ustring::ustring(Glib::ustring const&)'
/usr/include/c++/4.6/bits/stl_pair.h:137: undefined reference to `Glib::ustring::ustring(Glib::ustring const&)'
like image 609
hal7df Avatar asked Dec 26 '22 03:12

hal7df


1 Answers

I was working with some others and I got it compiled!

All I really needed was to provide the name of the library and put it into target_link_libraries like so:

target_link_libraries(plasma_engine_gdrive
                      DataWrapper
                      GData
                      xml++-2.6
                      curl
                      glibmm-2.4
                      ${KDE4_KDECORE_LIBS}
                      ${KDE4_PLASMA_LIBS})

My dad, being completely unfamiliar with CMake, went and dug out the link.txt within the CMake build structure. There, he just added the following after the -o flag:

-lxml++-2.6
-lcurl
-lglibmm-2.4

When I saw that, I thought I might try to do that linking through CMakeLists.txt -- and it worked.

like image 102
hal7df Avatar answered Jan 04 '23 04:01

hal7df