[CMake] Fwd: Problem with creating shared library

Eric Noulard eric.noulard at gmail.com
Wed Aug 15 11:13:25 EDT 2018


---------- Forwarded message ---------
From: Eric Noulard <eric.noulard at gmail.com>
Date: mer. 15 août 2018 à 17:13
Subject: Re: [CMake] Problem with creating shared library
To: <damir_porobic at live.com>


May be check the list of symbol in the lib.
KImageAnnotator::KImageAnnotator(QPixmap const&)
may really not be there (only declared in some header and not defined
anywhere).

Does the KImageAnnotator library have unit tests in its project?
If no executable linked to the ilb you won't discover the link error until
you try to link something to the lib.

This is a kind wild guess, don't take it personally :-)

Le mer. 15 août 2018 à 16:21, Damir Porobic <damir_porobic at live.com> a
écrit :

> Thanks for the feedback.
>
>
> It looks like this line is failing:
>
> /usr/bin/c++    -std=c++0x -fno-operator-names -fno-exceptions -Wall
> -Wextra -Wcast-align -Wchar-subscripts -Wformat-security -Wno-long-long
> -Wpointer-arith -Wundef -Wnon-virtual-dtor -Woverloaded-virtual
> -Werror=return-type  -Wl,--enable-new-dtags
> CMakeFiles/testApp.dir/main.cpp.o
> CMakeFiles/testApp.dir/testApp_automoc.cpp.o  -o testApp
> /usr/local/lib64/libkImageAnnotator.so.0.0.1
> /usr/lib64/libKF5CoreAddons.so.5.32.0 /usr/lib64/libKF5I18n.so.5.32.0
> /usr/lib64/libKF5WidgetsAddons.so.5.32.0 /usr/lib64/libQt5Widgets.so.5.6.2
> /usr/lib64/libQt5Gui.so.5.6.2 /usr/lib64/libQt5Core.so.5.6.2
> -Wl,-rpath,/usr/local/lib64
>
> The lib at /usr/local/lib64/libkImageAnnotator.so.0.0.1 seems to be
> correct, according to the sudo make install output from the lib
>
>
> Install the project...
> -- Install configuration: "Debug"
> -- Installing: /usr/local/lib64/libkImageAnnotator.so.0.0.1
> -- Installing: /usr/local/lib64/libkImageAnnotator.so.1
> -- Set runtime path of "/usr/local/lib64/libkImageAnnotator.so.0.0.1" to
> "/usr/local/lib64"
> -- Installing: /usr/local/lib64/libkImageAnnotator.so
> ...
> -- Installing:
> /usr/local/share/kImageAnnotatorConfig/cmake/kImageAnnotatorConfig.cmake
> -- Installing:
> /usr/local/share/kImageAnnotatorConfig/cmake/kImageAnnotatorConfig-debug.cmake
>
>
>
> Don't know if this is OK, but it looks like the debug and the non-debug
> cmake versions are used:
>
> /usr/local/share/kImageAnnotatorConfig/cmake/kImageAnnotatorConfig.cmake(3):
> if(${CMAKE_MAJOR_VERSION}.${CMAKE_MINOR_VERSION} LESS 2.5 )
> /usr/local/share/kImageAnnotatorConfig/cmake/kImageAnnotatorConfig.cmake(6):
> cmake_policy(PUSH )
> /usr/local/share/kImageAnnotatorConfig/cmake/kImageAnnotatorConfig.cmake(7):
> cmake_policy(VERSION 2.6 )
> /usr/local/share/kImageAnnotatorConfig/cmake/kImageAnnotatorConfig.cmake(13):
> set(CMAKE_IMPORT_FILE_VERSION 1 )
> /usr/local/share/kImageAnnotatorConfig/cmake/kImageAnnotatorConfig.cmake(16):
> set(_targetsDefined )
> /usr/local/share/kImageAnnotatorConfig/cmake/kImageAnnotatorConfig.cmake(17):
> set(_targetsNotDefined )
> /usr/local/share/kImageAnnotatorConfig/cmake/kImageAnnotatorConfig.cmake(18):
> set(_expectedTargets )
> /usr/local/share/kImageAnnotatorConfig/cmake/kImageAnnotatorConfig.cmake(19):
> foreach(_expectedTarget kImageAnnotator )
> /usr/local/share/kImageAnnotatorConfig/cmake/kImageAnnotatorConfig.cmake(20):
> list(APPEND _expectedTargets ${_expectedTarget} )
> /usr/local/share/kImageAnnotatorConfig/cmake/kImageAnnotatorConfig.cmake(21):
> if(NOT TARGET ${_expectedTarget} )
> /usr/local/share/kImageAnnotatorConfig/cmake/kImageAnnotatorConfig.cmake(22):
> list(APPEND _targetsNotDefined ${_expectedTarget} )
> /usr/local/share/kImageAnnotatorConfig/cmake/kImageAnnotatorConfig.cmake(24):
> if(TARGET ${_expectedTarget} )
> /usr/local/share/kImageAnnotatorConfig/cmake/kImageAnnotatorConfig.cmake(28):
> if(${_targetsDefined} STREQUAL ${_expectedTargets} )
> /usr/local/share/kImageAnnotatorConfig/cmake/kImageAnnotatorConfig.cmake(36):
> if(NOT ${_targetsDefined} STREQUAL  )
> /usr/local/share/kImageAnnotatorConfig/cmake/kImageAnnotatorConfig.cmake(39):
> unset(_targetsDefined )
> /usr/local/share/kImageAnnotatorConfig/cmake/kImageAnnotatorConfig.cmake(40):
> unset(_targetsNotDefined )
> /usr/local/share/kImageAnnotatorConfig/cmake/kImageAnnotatorConfig.cmake(41):
> unset(_expectedTargets )
> /usr/local/share/kImageAnnotatorConfig/cmake/kImageAnnotatorConfig.cmake(45):
> get_filename_component(_IMPORT_PREFIX ${CMAKE_CURRENT_LIST_FILE} PATH )
> /usr/local/share/kImageAnnotatorConfig/cmake/kImageAnnotatorConfig.cmake(46):
> get_filename_component(_IMPORT_PREFIX ${_IMPORT_PREFIX} PATH )
> /usr/local/share/kImageAnnotatorConfig/cmake/kImageAnnotatorConfig.cmake(47):
> get_filename_component(_IMPORT_PREFIX ${_IMPORT_PREFIX} PATH )
> /usr/local/share/kImageAnnotatorConfig/cmake/kImageAnnotatorConfig.cmake(48):
> get_filename_component(_IMPORT_PREFIX ${_IMPORT_PREFIX} PATH )
> /usr/local/share/kImageAnnotatorConfig/cmake/kImageAnnotatorConfig.cmake(49):
> if(_IMPORT_PREFIX STREQUAL / )
> /usr/local/share/kImageAnnotatorConfig/cmake/kImageAnnotatorConfig.cmake(54):
> add_library(kImageAnnotator SHARED IMPORTED )
> /usr/local/share/kImageAnnotatorConfig/cmake/kImageAnnotatorConfig.cmake(56):
> set_target_properties(kImageAnnotator PROPERTIES
> INTERFACE_INCLUDE_DIRECTORIES ${_IMPORT_PREFIX}/include
> INTERFACE_LINK_LIBRARIES
> Qt5::Widgets;KF5::CoreAddons;KF5::I18n;KF5::WidgetsAddons )
> /usr/local/share/kImageAnnotatorConfig/cmake/kImageAnnotatorConfig.cmake(61):
> if(CMAKE_VERSION VERSION_LESS 2.8.12 )
> /usr/local/share/kImageAnnotatorConfig/cmake/kImageAnnotatorConfig.cmake(66):
> get_filename_component(_DIR ${CMAKE_CURRENT_LIST_FILE} PATH )
> /usr/local/share/kImageAnnotatorConfig/cmake/kImageAnnotatorConfig.cmake(67):
> file(GLOB CONFIG_FILES ${_DIR}/kImageAnnotatorConfig-*.cmake )
> /usr/local/share/kImageAnnotatorConfig/cmake/kImageAnnotatorConfig.cmake(68):
> foreach(f ${CONFIG_FILES} )
> /usr/local/share/kImageAnnotatorConfig/cmake/kImageAnnotatorConfig.cmake(69):
> include(${f} )
> /usr/local/share/kImageAnnotatorConfig/cmake/kImageAnnotatorConfig-debug.cmake(6):
> set(CMAKE_IMPORT_FILE_VERSION 1 )
> /usr/local/share/kImageAnnotatorConfig/cmake/kImageAnnotatorConfig-debug.cmake(9):
> set_property(TARGET kImageAnnotator APPEND PROPERTY IMPORTED_CONFIGURATIONS
> DEBUG )
> /usr/local/share/kImageAnnotatorConfig/cmake/kImageAnnotatorConfig-debug.cmake(10):
> set_target_properties(kImageAnnotator PROPERTIES IMPORTED_LOCATION_DEBUG
> ${_IMPORT_PREFIX}/lib64/libkImageAnnotator.so.0.0.1 IMPORTED_SONAME_DEBUG
> libkImageAnnotator.so.1 )
> /usr/local/share/kImageAnnotatorConfig/cmake/kImageAnnotatorConfig-debug.cmake(15):
> list(APPEND _IMPORT_CHECK_TARGETS kImageAnnotator )
> /usr/local/share/kImageAnnotatorConfig/cmake/kImageAnnotatorConfig-debug.cmake(16):
> list(APPEND _IMPORT_CHECK_FILES_FOR_kImageAnnotator
> ${_IMPORT_PREFIX}/lib64/libkImageAnnotator.so.0.0.1 )
> /usr/local/share/kImageAnnotatorConfig/cmake/kImageAnnotatorConfig-debug.cmake(19):
> set(CMAKE_IMPORT_FILE_VERSION )
> /usr/local/share/kImageAnnotatorConfig/cmake/kImageAnnotatorConfig.cmake(73):
> set(_IMPORT_PREFIX )
> /usr/local/share/kImageAnnotatorConfig/cmake/kImageAnnotatorConfig.cmake(76):
> foreach(target ${_IMPORT_CHECK_TARGETS} )
> /usr/local/share/kImageAnnotatorConfig/cmake/kImageAnnotatorConfig.cmake(77):
> foreach(file ${_IMPORT_CHECK_FILES_FOR_${target}} )
> /usr/local/share/kImageAnnotatorConfig/cmake/kImageAnnotatorConfig.cmake(78):
> if(NOT EXISTS ${file} )
> /usr/local/share/kImageAnnotatorConfig/cmake/kImageAnnotatorConfig.cmake(90):
> unset(_IMPORT_CHECK_FILES_FOR_${target} )
> /usr/local/share/kImageAnnotatorConfig/cmake/kImageAnnotatorConfig.cmake(92):
> unset(_IMPORT_CHECK_TARGETS )
> /usr/local/share/kImageAnnotatorConfig/cmake/kImageAnnotatorConfig.cmake(98):
> set(CMAKE_IMPORT_FILE_VERSION )
> /usr/local/share/kImageAnnotatorConfig/cmake/kImageAnnotatorConfig.cmake(99):
> cmake_policy(POP )
>
> It looks like the correct cmake files are used.
>
> Any more ideas?
>
> Regards,
> Damir
>
> ------------------------------
> *From:* Eric Noulard <eric.noulard at gmail.com>
> *Sent:* Wednesday, August 15, 2018 12:18
> *To:* damir_porobic at live.com
> *Cc:* CMake Mailinglist
> *Subject:* Re: [CMake] Problem with creating shared library
>
>
>
> Le mer. 15 août 2018 à 10:32, Damir Porobic <damir_porobic at live.com> a
> écrit :
>
> Hi Folks,
>
>
> I'm trying to write a shared library and run into an issue where I can't
> find any clues to where the problem is.
>
> I have a project with following structure:
>
>
> src/
>
>     dir1/
>
>         file1.h
>
>         file1.cpp
>
>     dir2/
>
>         file2.h
>         file2.cpp
>
>
>
> Now I have this CMakeList:
>
> cmake_minimum_required(VERSION 3.5)
>
> project(kImageAnnotator VERSION 0.0.1 LANGUAGES CXX)
>
> ...
>
>
> add_library(${PROJECT_NAME} SHARED ${kimageannotator_SRCS})
> target_link_libraries(${PROJECT_NAME} Qt5::Widgets KF5::CoreAddons
> KF5::I18n KF5::WidgetsAddons)
>
> target_include_directories(${PROJECT_NAME} PUBLIC
> $<BUILD_INTERFACE:${CMAKE_CURRENT_SOURCE_DIR}> $<INSTALL_INTERFACE:include>)
>
> set_target_properties(${PROJECT_NAME} PROPERTIES VERSION
> ${PROJECT_VERSION} SOVERSION 1)
>
> set(kimageannotator_CONFIG ${PROJECT_NAME}Config)
>
> install(TARGETS ${PROJECT_NAME} EXPORT ${kimageannotator_CONFIG}
>         ARCHIVE  DESTINATION ${CMAKE_INSTALL_LIBDIR}
>         LIBRARY  DESTINATION ${CMAKE_INSTALL_LIBDIR}
>         RUNTIME  DESTINATION ${CMAKE_INSTALL_BINDIR})
> install(DIRECTORY ${CMAKE_CURRENT_SOURCE_DIR} DESTINATION
> ${CMAKE_INSTALL_INCLUDEDIR}/${PROJECT_NAME})
>
> install(EXPORT ${kimageannotator_CONFIG} DESTINATION
> share/${kimageannotator_CONFIG}/cmake)
>
> export(TARGETS ${PROJECT_NAME} FILE ${kimageannotator_CONFIG}.cmake)
>
>
> In another test project, I add the library like this:
> ...
> find_package(kImageAnnotator REQUIRED)
>
> add_executable(testApp main.cpp)
> target_link_libraries(testApp Qt5::Widgets kImageAnnotator)
>
>
> Now when I try to build my test project, I get this:
>
> dporobic at linux ~/projects/testApp/build
> $ cmake .. && make
> -- Could not set up the appstream test. appstreamcli is missing.
> -- Configuring done
> -- Generating done
> -- Build files have been written to: /home/dporobic/projects/testApp/build
> [ 25%] Automatic moc for target testApp
> [ 25%] Built target testApp_automoc
> Scanning dependencies of target testApp
> [ 50%] Building CXX object CMakeFiles/testApp.dir/main.cpp.o
> [ 75%] Building CXX object CMakeFiles/testApp.dir/testApp_automoc.cpp.o
> [100%] Linking CXX executable testApp
> CMakeFiles/testApp.dir/main.cpp.o: In function `main':
> main.cpp:(.text+0x8e): undefined reference to
> `KImageAnnotator::KImageAnnotator(QPixmap const&)'
> collect2: error: ld returned 1 exit status
> CMakeFiles/testApp.dir/build.make:120: recipe for target 'testApp' failed
> make[2]: *** [testApp] Error 1
> CMakeFiles/Makefile2:67: recipe for target 'CMakeFiles/testApp.dir/all'
> failed
> make[1]: *** [CMakeFiles/testApp.dir/all] Error 2
> Makefile:94: recipe for target 'all' failed
> make: *** [all] Error 2
>
> Any idea how I could/should troubleshoot such issue?
>
>
> Try to compile in verbose mode
>
> make VERBOSE=1
>
> and have a look at the culprit link line.
> You should see the reference to your previously built shared lib.
>
> Check whether this lib is where it should be (may be you didn't install
> it?)
>
> then check which kImageAnnotatorConfig.cmake file is used by the testApp
> project in order to see if any
> [wrong and not up to date] test & trial version of this file is lying
> around.
>
>
> --
> Eric
>


-- 
Eric


-- 
Eric
-------------- next part --------------
An HTML attachment was scrubbed...
URL: <https://cmake.org/pipermail/cmake/attachments/20180815/1e4eebdd/attachment-0001.html>


More information about the CMake mailing list