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@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?
Thanks in advance!
Regards,
Damir
--
Powered by www.kitware.com
Please keep messages on-topic and check the CMake FAQ at:
http://www.cmake.org/Wiki/CMake_FAQ
Kitware offers various services to support the CMake community. For more
information on each offering, please visit:
CMake Support: http://cmake.org/cmake/help/support.html
CMake Consulting: http://cmake.org/cmake/help/consulting.html
CMake Training Courses: http://cmake.org/cmake/help/training.html
Visit other Kitware open-source projects at
http://www.kitware.com/opensource/opensource.html
Follow this link to subscribe/unsubscribe:
https://cmake.org/mailman/listinfo/cmake