I'm trying to link a C++ project to the RCpp library; the file is called Rcpp.so, not the linux-default libRcpp.so. Furthermore, the library resides at the non-standard location /usr/lib/R/site-library/Rcpp/libs.
So I tried using a combination of find_library and target_link_libraries:
cmake_minimum_required(VERSION 3.8)
project("R-Tests")
find_library(RCPP
NAMES Rcpp.so
HINTS /usr/lib/R/site-library/Rcpp/libs
)
if (NOT RCPP)
message(FATAL_ERROR "Could not find Rcpp - exiting.")
else()
message("Found Rcpp: " ${RCPP})
endif()
# test target
add_executable(rcpptest main.cpp)
target_link_libraries(rcpptest ${RCPP})
Configuring works fine, CMake outputs:
Found Rcpp: /usr/lib/R/site-library/Rcpp/libs/Rcpp.so
However, during build, CMake passes -lRcpp to the compiler, which causes the compilation to fail, since the library file is not named libRcpp.so but instead Rcpp.so:
[100%] Linking CXX executable rcpptest
/usr/bin/cmake -E cmake_link_script CMakeFiles/rcpptest.dir/link.txt --verbose=1
c++ CMakeFiles/rcpptest.dir/main.cpp.o -o rcpptest -L/usr/lib/R/site-library/Rcpp/libs -Wl,-rpath,/usr/lib/R/site-library/Rcpp/libs -lRcpp
/usr/bin/ld: cannot find -lRcpp
collect2: error: ld returned 1 exit status
Since the message line prints the full path to the Rcpp.so file just fine, is there any way to let target_link_libraries just add this path to the compiler instead of a combination of -L and -l?
According to this question, this should be disabled by adding cmake_policy(SET CMP0060 NEW); however, I can't see any change in the behavior of CMake if I set this to NEW or OLD.
You may have been bitten by the OLD (default) behavior of CMP0060, which converts absolute paths back to -lfoo.
Alternatively, define and use an IMPORTED target:
add_library(Rcpp SHARED IMPORTED)
set_property(TARGET Rcpp PROPERTY IMPORTED_LOCATION /usr/lib/R/site-library/Rcpp/libs/Rcpp.so)
target_link_libraries(rcpptest Rcpp)
Related
I'm trying to use wxWidgets on an arm64 macOS with vcpkg, CMake, and VS Code. Everything is wired up correctly because other vcpkg libraries include, link, and run fine. But, when I try to use wxWidgets there's a linking error.
My CMakeLists.txt:
cmake_minimum_required(VERSION 3.22.0)
project(main VERSION 0.1.0)
add_executable(main main.cpp)
set_property(TARGET main PROPERTY CXX_STANDARD 17)
find_package(wxWidgets REQUIRED)
include(${wxWidgets_USE_FILE})
target_include_directories(main PRIVATE ${wxWidgets_INCLUDE_DIRS})
target_link_libraries(main PRIVATE ${wxWidgets_LIBRARIES})
The CMake error I get:
[build] [ 50%] Linking CXX executable main
[build] ld: library not found for -llibjpeg.a>
[build] clang: error: linker command failed with exit code 1 (use -v to see invocation)
The value of the wxWidgets_LIBRARIES list (set by find_package(wxWidgets REQUIRED)):
-L/Users/myname/cpp/vcpkg/packages/wxwidgets_arm64-osx/lib;-pthread;/Users/myname/cpp/vcpkg/packages/wxwidgets_arm64-osx/lib/libwx_osx_cocoau_xrc-3.1.a;/Users/myname/cpp/vcpkg/packages/wxwidgets_arm64-osx/lib/libwx_osx_cocoau_qa-3.1.a;/Users/myname/cpp/vcpkg/packages/wxwidgets_arm64-osx/lib/libwx_baseu_net-3.1.a;/Users/myname/cpp/vcpkg/packages/wxwidgets_arm64-osx/lib/libwx_osx_cocoau_html-3.1.a;/Users/myname/cpp/vcpkg/packages/wxwidgets_arm64-osx/lib/libwx_osx_cocoau_core-3.1.a;/Users/myname/cpp/vcpkg/packages/wxwidgets_arm64-osx/lib/libwx_baseu_xml-3.1.a;/Users/myname/cpp/vcpkg/packages/wxwidgets_arm64-osx/lib/libwx_baseu-3.1.a;-lwx_osx_cocoau_core-3.1;libjpeg.a>;libjpeg.a>;libpng.a>;libpng16d.a>;libz.a>;libz.a>;libtiff.a>;libtiffd.a>;liblzma.a>;liblzma.a>;libjpeg.a>;libjpeg.a>;libz.a>;libz.a>;m;-framework AudioToolbox;-framework WebKit;-lwx_baseu-3.1;libexpat.a>;libexpat.a>;libz.a>;libz.a>;-lwxregexu-3.1;libiconv.tbd;-framework CoreFoundation;-framework Security;-framework Carbon;-framework Cocoa;-framework IOKit;-framework QuartzCore;TIFF::TIFF;expat::expat;ZLIB::ZLIB;png_static
I don't have much experience with CMake, so I don't know what the right angle bracket is for, but is that the problem? Could its being the first non-full-path file in the list mean that it doesn't know where to look?
-L is for directories, and -l is for individual library files. I see you have mixed .a files with directories. You'll need to fix that.
Your best bet is to debug cmake configure with --trace-expand and see who is setting wxWidgets_LIBRARIES to a incomplete and very strange generator expression libjpeg.a>;libjpeg.a>;libpng.a>;libpng16d.a>;
Another suspicious thing is that your library paths contain packages/wxwidgets_arm64-osx which indicates either wrong usage of vcpkg or there is a -config.cmake involved which was not fixed by vcpkg. (everything vcpkg finds via cmake should be living in /installed/<triplet>)
Ubuntu shows: /usr/bin/ld: cannot find -llibswmm5, ,when i use the CMakeLists.txt below. To figure out what CMake has done,i use make VERBOSE=1, it showd the address problem, even after i tried export LD_LIBRARY_PATH='pwd'
[ 50%] Linking CXX executable Tutorial
/usr/bin/cmake -E cmake_link_script CMakeFiles/Tutorial.dir/link.txt --verbose=1
/usr/bin/c++ CMakeFiles/Tutorial.dir/tutorial.cxx.o -o Tutorial -llibswmm5
/usr/bin/ld: cannot find -llibswmm5
collect2: error: ld returned 1 exit status
i tried the two versions below (according to modern CMake, find_librarires() is encouraged to use), i thought they should work, but none of them work:(. I am a starter for CMake. If anyone could give some comments on this small problem, it would be much appreciate.
cmake_minimum_required(VERSION 3.10)
project(Tutorial)
add_executable(Tutorial tutorial.cxx)
link_directories(${PROJECT_BINARY_DIR})
target_link_libraries(Tutorial libswmm5)
cmake_minimum_required(VERSION 3.10)
project(Tutorial)
add_executable(Tutorial tutorial.cxx)
find_library(SWMM5_LIBRARY
NAMES
libswmm5
HINTS
${PROJECT_BINARY_DIR}/prebuilt/
)
if ( NOT SWMM5_LIBRARY )
message( WARNING "SWMM library NOT FOUND")
else()
message( STATUS "SWMM library : ${SWMM5_LIBRARY}")
endif(SWMM5_LIBRARY)
target_link_libraries(Tutorial ${SWMM5_LIBRARY} )
when I use CMakeLists.txt with:
find_library(cryptoppV libcryptopp.a)
target_link_libraries(${PROJenter code hereECT_NAME} ${cryptoppV})
then i can find a library under /usr/local/lib,and make the C++ programe right and got the right result.
but when i replace it with:
-- find_library(cryptoppV libcryptopp.a)
target_link_libraries(${PROJECT_NAME} cryptopp)
then i got the error message:
ld: library not found for -lcryptopp
why cmake do not link /usr/local/lib by default? did i do something wrong?
-- add by aijinsong Oct 7, 2018 6:37 AM
i'm in more confused. when the CMakeLists.txt was:
set(SOURCE_FILES main.cpp)
add_executable(${PROJECT_NAME} ${SOURCE_FILES})
find_package(Boost 1.58 REQUIRED thread)
target_link_libraries(${PROJECT_NAME} Boost::thread)
find_library(cryptoppV libcryptopp.a)
target_link_libraries(${PROJECT_NAME} ${cryptoppV})
the compiler can find cryptopp/sha.h. but when the CMakeLists.txt was:
set(SOURCE_FILES main.cpp)
add_executable(${PROJECT_NAME} ${SOURCE_FILES})
## find_package(Boost 1.58 REQUIRED thread)
## target_link_libraries(${PROJECT_NAME} Boost::thread)
find_library(cryptoppV libcryptopp.a)
target_link_libraries(${PROJECT_NAME} ${cryptoppV})
the error message was:
fatal error: 'cryptopp/sha.h' file not found
#include <cryptopp/sha.h>
when the CMakeLists.txt was:
set(SOURCE_FILES main.cpp)
add_executable(${PROJECT_NAME} ${SOURCE_FILES})
find_package(Boost 1.58 REQUIRED thread)
## target_link_libraries(${PROJECT_NAME} Boost::thread)
find_library(cryptoppV libcryptopp.a)
target_link_libraries(${PROJECT_NAME} ${cryptoppV})
the error message was still:
fatal error: 'cryptopp/sha.h' file not found
#include <cryptopp/sha.h>
why i use cryptopp that the cmake ask me to link with library Boost::thread? i'm in more confused.
-- add by aijinsong Oct 7, 2018 11:56 AM
And if i use g++ main.cpp -o main -lcryptopp, i can get the right result. This shows that the library cryptopp has been installed correcttly, and g++ can find the library. why when i do it by make, it can't find the library?
-- add for KamilCuk start
-- add by aijinsong at Oct 7, 2018 3:27 PM
when i make it by make VERBOSE=1, i got the following message:
cd /Users/aijinsong/Documents/projects/com.aijs.cxx/bolochain/src && /usr/local/Cellar/cmake/3.12.3/bin/cmake -E cmake_link_script CMakeFiles/bolochain.dir/link.txt --verbose=1
and the text in link.txt is:
/Applications/Xcode.app/Contents/Developer/Toolchains/XcodeDefault.xctoolchain/usr/bin/c++ -g -isysroot /Applications/Xcode.app/Contents/Developer/Platforms/MacOSX.platform/Developer/SDKs/MacOSX10.14.sdk -Wl,-search_paths_first -Wl,-headerpad_max_install_names CMakeFiles/bolochain.dir/main.cpp.o -o bolochain /usr/local/lib/libboost_thread-mt.dylib -lcryptopp /usr/local/lib/libboost_chrono-mt.dylib /usr/local/lib/libboost_system-mt.dylib /usr/local/lib/libboost_date_time-mt.dylib /usr/local/lib/libboost_atomic-mt.dylib
this command cause the failure link but when i edit it like following, then c++ link command process very well:
/Applications/Xcode.app/Contents/Developer/Toolchains/XcodeDefault.xctoolchain/usr/bin/c++ -g -Wl,-search_paths_first -Wl,-headerpad_max_install_names CMakeFiles/bolochain.dir/main.cpp.o -o bolochain /usr/local/lib/libboost_thread-mt.dylib -lcryptopp /usr/local/lib/libboost_chrono-mt.dylib /usr/local/lib/libboost_system-mt.dylib /usr/local/lib/libboost_date_time-mt.dylib /usr/local/lib/libboost_atomic-mt.dylib
just delete:
-isysroot /Applications/Xcode.app/Contents/Developer/Platforms/MacOSX.platform/Developer/SDKs/MacOSX10.14.sdk
I'm still working on this problem.
-- add for KamilCuk end
Fist, Thanks #Kamil Cuk. The argument -VERBOSE=1 was so useful that I can get more detail messages that show me what happens when I use make.
The point is that when I use cmake under OSX system. It will generate a txt be named 'link.txt' which includes commands and part of it is as the following:
-isysroot /Applications/Xcode.app/Contents/Developer/Platforms/MacOSX.platform/Developer/SDKs/MacOSX10.14.sdk
when I delete this part, the commands will execute right. but when I add this line, the commands execute wrong. so the point is that this line maybe limited the search path of c++. Thanks #tsyvarev . You are right, -isysroot limited the c++ linkers searches /usr/local/lib.
Second, I did't find out how to remove the line -isysroot ... generated by OSX cmake. So, I need to find another solution.
When I search more information about find_package/include_directories/target_link_libraries, I found out that find_package need a FindXXX.cmake file to help it to find out the header file and libraries of the target. So I googled a FindCyptoPP.cmake file. and in this file it find out tow vars, one hold the value of cryptopp's header directory path, and one hold the value of cryptopp's library path. Then I use include_directories/target_link_libraries as following, the problem
war solved.
find_package(CryptoPP)
include_directories(${CRYPTOPP_INCLUDE_DIRS})
target_link_libraries(${PROJECT_NAME} ${CRYPTOPP_LIBRARIES})
and then when I use make -VERBOSE = 1, I fond that the output was a little different when I use the CMakeLists.txt as following:
target_link_libraries(${PROJECT_NAME} cryptopp)
When I use three lines, the output contains a line /usr/local/lib/libcryptopp.dylib. When I use one line, the output contains a line -lcryptopp.
So, with the command line -isysroot, the command line -lcryptopp will search library under the directory defined by -isysroot, and under the directory, there is no library named cryptopp but under /usr/local/lib. But with command line /usr/local/lib/libcryptopp.dylib, it gaves the absolute path of the library, so the linkes just do the linking task and need not search. Thanks #Kamil Cuk again.
Thrid, I knew include_directories/target_link_libraries are two separate steps which one is used for include header file and one is used for link libraries.
Still, there were some problems not soled:
- how to remove -isysroot?
- how to create a FindXXX.cmake file?
- how to make /usr/local/lib as a default search directory and was it a practice way to do so?
I will continue working on them, and come back a few days or weeks later.
I have a cmake project where I want to add a class containing the matlab engine. For compiling it I need to include two libraries eng and mx, which I do by adding
target_link_libraries( ${TARGET} /usr/local/MATLAB/R2013b/bin/glnxa64/libeng.so)
target_link_libraries( ${TARGET} /usr/local/MATLAB/R2013b/bin/glnxa64/libmx.so)
to my CMakeLists.txt file.
However there are also lots of other old versions of libraries in /usr/local/MATLAB/R2013b/bin/glnxa64/, which seem
to be automatically added to the path as well when calling the above command. I think this causes the compiler to not find my
normal libraries anymore and produces an error.
How can I include only the two above libraries, and not all the others in the glnxa64 folder?
The warning shown after running cmake . :
CMake Warning at CMakeLists.txt:23 (add_executable):
Cannot generate a safe runtime search path for target CCDWidget because
files in some directories may conflict with libraries in implicit
directories:
runtime library [libboost_program_options.so.1.49.0] in /usr/lib may be hidden by files in:
/usr/local/MATLAB/R2013b/bin/glnxa64
runtime library [libboost_system.so.1.49.0] in /usr/lib may be hidden by files in:
/usr/local/MATLAB/R2013b/bin/glnxa64
runtime library [libboost_filesystem.so.1.49.0] in /usr/lib may be hidden by files in:
/usr/local/MATLAB/R2013b/bin/glnxa64
runtime library [libboost_regex.so.1.49.0] in /usr/lib may be hidden by files in:
/usr/local/MATLAB/R2013b/bin/glnxa64
Some of these libraries may not be found correctly.
And the error message during linking:
Linking CXX executable CCDWidget
/usr/lib/x86_64-linux-gnu/libharfbuzz.so.0: undefined reference to `FT_Face_GetCharVariantIndex'
/usr/lib/x86_64-linux-gnu/libharfbuzz.so.0: undefined reference to `FT_Get_Advance'
collect2: error: ld returned 1 exit status
make[2]: *** [CCDWidget] Error 1
make[1]: *** [CMakeFiles/CCDWidget.dir/all] Error 2
make: *** [all] Error 2
Below is my full CMakeLists.txt file. Lines commented out with two ## are alternatives that I tried before and didn't solve my problem.
I also added LINK_PRIVATE to the target_link_libraries command as shown in the code below, which didn't make a difference.
The option PRIVATE alone seems to be not accepted by my cmake version, as it changed the error meassage to
/usr/bin/ld: cannot find -lPRIVATE
collect2: error: ld returned 1 exit status
When the #eng line is commented out, the compilation and linking works without errors
(when calling the matlab engine is also commented out in Readout.cpp), so the error must be produced by that line.
#Specify the version being used as well as the language
cmake_minimum_required(VERSION 2.6)
##cmake_policy(SET CMP0003 NEW)
#Name your project here
project(CCDWidget)
set(TARGET CCDWidget)
set(MAIN_SOURCES CCDWidget.cpp main.cc CCDControl.cpp VideoWindow.cpp ImageWindow.cpp ThisMeasurement.cpp KineticSeries.cpp FastKinetics.cpp Readout.cpp)
##SET(CMAKE_FIND_ROOT_PATH_MODE_LIBRARY ONLY)
#set_source_files_properties(Readout.cpp PROPERTIES COMPILE_FLAGS "-I/usr/local/MATLAB/R2013b/extern/include -I/usr/local/MATLAB/R2013b/simulink/include -DMATLAB_MEX_FILE -ansi -D_GNU_SOURCE -I/usr/local/MATLAB/R2013b/extern/include/cpp -I/usr/local/MATLAB/R2013b/extern/include -DGLNXA64 -DGCC -DMX_COMPAT_32 -DNDEBUG -Wno-effc++")
find_package(Boost COMPONENTS program_options system filesystem regex REQUIRED)
find_package(PkgConfig REQUIRED)
pkg_check_modules(GTKMM gtkmm-3.0)
include_directories( ${GTKMM_INCLUDE_DIRS} )
include_directories( ${Boost_INCLUDE_DIR} )
include_directories( ${PROJECT_SOURCE_DIR} )
##link_directories(/usr/local/MATLAB/R2013b/bin/glnxa64)
##target_link_libraries( ${TARGET} eng)
##target_link_libraries( ${TARGET} mx)
set(CMAKE_CXX_FLAGS "--std=c++11")
add_executable( ${TARGET} ${MAIN_SOURCES} )
target_link_libraries( ${TARGET} ${GTKMM_LIBRARIES} )
target_link_libraries( ${TARGET} ${Boost_LIBRARIES} )
target_link_libraries( ${TARGET} LINK_PRIVATE /usr/local/MATLAB/R2013b/bin/glnxa64/libeng.so) # eng
#target_link_libraries( ${TARGET} LINK_PRIVATE /usr/local/MATLAB/R2013b/bin/glnxa64/libmx.so ) # mx
target_link_libraries( ${TARGET} andor )
You could try using an imported target:
add_library(eng SHARED IMPORTED)
set_property(TARGET eng PROPERTY IMPORTED_LOCATION /usr/local/MATLAB/R2013b/bin/glnxa64/libeng.so)
...
add_executable( ${TARGET} ${MAIN_SOURCES} )
...
target_link_libraries(${TARGET} eng)
For debugging you could try to build with "make VERBOSE=1".
This will show you the used gcc command line.
CMake probably transforms your target_link_libraries command to something like:
g++ ... -L/usr/local/MATLAB/R2013b/bin/glnxa64 -leng ...
gcc then finds some boost libraries in this folder.
I'll begin stating that I'm almost complete dumb in Cmake matter.
I have the following CMakeLists.txt for a Kdevelop 4.1 project:
project(uart)
find_package(KDE4 REQUIRED)
include (KDE4Defaults)
include_directories( ${KDE4_INCLUDES} ${QT_INCLUDES} src/include src/include/QSerialDevce )
add_subdirectory(doc)
add_subdirectory(src)
add_subdirectory(icons)
link_directories(/usr/lib)
find_library(SERIALDEVICE_LIB qserialdeviced)
add_executable(uart ${uart_SRCS})
target_link_libraries(uart ${SERIALDEVICE_LIB})
When I try to build my project I see:
uart/build> make -j2
-- Found Qt-Version 4.6.3 (using /usr/bin/qmake-qt4)
-- Found X11: /usr/lib64/libX11.so
-- Found KDE 4.5 include dir: /usr/include/kde4
-- Found KDE 4.5 library dir: /usr/lib64/kde4/devel
-- Found the KDE4 kconfig_compiler4 preprocessor: /usr/bin/kconfig_compiler4
-- Found automoc4: /usr/bin/automoc4
CMake Error at CMakeLists.txt:16 (add_executable):
add_executable called with incorrect number of arguments
CMake Error: Attempt to add link library "/usr/lib/libqserialdeviced.so" to target "uart" which is not built by this project.
-- Configuring incomplete, errors occurred!
make: *** [cmake_check_build_system] Error 1
*** Failed ***
Everything I read says that add_executable and target_link_libraries should look like the last two lines of my file:
add_executable(uart ${uart_SRCS})
target_link_libraries(uart ${SERIALDEVICE_LIB})
If I change those two lines of CMakeLists.txt leaving it as:
project(uart)
find_package(KDE4 REQUIRED)
include (KDE4Defaults)
include_directories( ${KDE4_INCLUDES} ${QT_INCLUDES} src/include src/include/QSerialDevce )
add_subdirectory(doc)
add_subdirectory(src)
add_subdirectory(icons)
link_directories(/usr/lib)
find_library(SERIALDEVICE_LIB qserialdeviced)
target_link_libraries(${SERIALDEVICE_LIB})
I see:
uart/build> make -j2
-- Found Qt-Version 4.6.3 (using /usr/bin/qmake-qt4)
-- Found X11: /usr/lib64/libX11.so
-- Found KDE 4.5 include dir: /usr/include/kde4
-- Found KDE 4.5 library dir: /usr/lib64/kde4/devel
-- Found the KDE4 kconfig_compiler4 preprocessor: /usr/bin/kconfig_compiler4
-- Found automoc4: /usr/bin/automoc4
-- Configuring done
-- Generating done
-- Build files have been written to: uart/build
[ 11%] Built target doc-handbook
[ 11%] Built target uart_automoc
Linking CXX executable uart
CMakeFiles/uart.dir/uart.o: In function `uart::setupSerial()':
uart/src/uart.cpp:126: undefined reference to `AbstractSerial::AbstractSerial(QObject*)'
CMakeFiles/uart.dir/uart.o: In function `uart::setupEnumerator()':
uart/src/uart.cpp:108: undefined reference to `SerialDeviceEnumerator::SerialDeviceEnumerator(QObject*)'
CMakeFiles/uart.dir/uart.o: In function `uart::setupSerial()':
uart_/uart/src/uart.cpp:136: undefined reference to `AbstractSerial::enableEmitStatus(bool)'
CMakeFiles/uart.dir/uart.o: In function `uart::setupEnumerator()':
uart_/uart/src/uart.cpp:112: undefined reference to `SerialDeviceEnumerator::setEnabled(bool)'
collect2: ld returned 1 exit status
make[2]: *** [src/uart] Error 1
make[1]: *** [src/CMakeFiles/uart.dir/all] Error 2
make: *** [all] Error 2
*** Failed ***
That clearly shows that target_link_libraries is not linking my qserialdeviced.
qserialdeviced is at /usr/lib/libqserialdeviced.so.1.0.0, correctly simlinked to /usr/lib/libqserialdeviced.so and easily found if I manually add it in the Makefile.
I obviously tried:
target_link_libraries(-lqserialdeviced)
with no change.
I also tried:
if ("${SERIALDEVICE_LIB}" STREQUAL "SERIALDEVICE_LIB-NOTFOUND")
message(FATAL_ERROR "'qserialdeviced' wasn't found!")
else()
message("'qserialdeviced' found: " ${SERIALDEVICE_LIB})
endif ()
But this test succeeds. The library is found:
'qserialdeviced' found: /usr/lib/libqserialdeviced.so
Can anybody please help me to understand what happens here?
I am using Linux Fedora 13, cmake version 2.8.0, gcc (GCC) 4.4.5 20101112 (Red Hat 4.4.5-2) and kdevelop-4.1.0-1.fc13.x86_64.
Thanks i advance.
EDIT:
As suggested by #DatChu, I split my CMakeLists.txt across my subdirectories and everything makes sense to me now.
Thanks everbody!
For the original CMakeLists.txt file, the problem is not with target_link_libraries but with add_executable
add_executable(uart ${uart_SRCS})
where did you set your uart_SRCS variable? Do you have
set(uart_SRCS src/blahblah.cpp src/somethingblahblah.cpp)
I think you might misunderstand what add_subdirectory does. It does not add the source files inside. It tells CMake to descend into that folder and look for another CMakeLists.txt. You typically use it when you have a sub-project inside of your project folder.
If you have many source files which you don't want to manually set, you can also do
file(GLOB uart_SRCS src/*.cpp src/*.c)
The downside is you need to manually re-run CMake in order for it to detect new files. See Jack's comment on why this might not be what you want to use.
Your CMakeLists.txt will most likely be
project(uart)
find_package(Qt4 REQUIRED)
include (${QT_USE_FILE})
find_package(KDE4 REQUIRED)
include (KDE4Defaults)
include_directories( ${KDE4_INCLUDES} ${QT_INCLUDES} src/include src/include/QSerialDevice )
link_directories(/usr/lib)
file(GLOB uart_SRCS src/*.cpp src/*.h)
file(GLOB uart_HDRS include/*.h include/QSerialDevice/*.h)
find_library(SERIALDEVICE_LIB qserialdeviced)
add_executable(uart ${uart_SRCS} ${uart_HDRS})
target_link_libraries(uart ${SERIALDEVICE_LIB} ${QT_LIBRARIES})
This isn't really a direct solution, but I was having such difficulty with "undefined reference" errors (solved previously by linking the appropriate libraries, but not in this case), until I just discovered something - an incompatibility with c vs cpp somehow. The files that defined these reference functions were in .c files (which would default cmake to compile with a C compiler.) and my file referencing these functions is a .cpp file (using g++ compiler or whatever your environment c++ compiler is). Once I changed the .c file to .cpp the "undefined reference" errors disappeared. Above it looks like your uart file is .cpp, but maybe check what the other files are and try this method. It's probably not the appropriate solution or even one at all, but this might get you through the day and moving forward.