मैं यह कहूंगा कि मैं लगभग सीमेक मामले में पूरी तरह से गूंगा हूं।सीएमके target_link_libraries मेरी लाइब्रेरी को लिंक नहीं कर रहा है
मैं निम्नलिखित एक डेवलप 4.1 परियोजना के लिए CMakeLists.txt
:
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})
जब मैं अपने प्रोजेक्ट बनाने की कोशिश मैं देख रहा हूँ:
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 ***
सब कुछ मैंने पढ़ा है का कहना है कि add_executable
और target_link_libraries
की तरह दिखना चाहिए मेरी फ़ाइल की आखिरी दो पंक्तियां:
add_executable(uart ${uart_SRCS})
target_link_libraries(uart ${SERIALDEVICE_LIB})
अगर मैं के रूप में इसे छोड़ने CMakeLists.txt
की उन दो पंक्तियों में परिवर्तन:
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})
मैं देख रहा हूँ:
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 ***
स्पष्ट रूप से पता चलता है कि target_link_libraries
मेरी qserialdeviced
लिंक नहीं है।
qserialdeviced
सही ढंग से /usr/lib/libqserialdeviced.so
को simlinked और आसानी से अगर मैं मैन्युअल Makefile में जोड़ पाया /usr/lib/libqserialdeviced.so.1.0.0
पर है।
मैं स्पष्ट रूप से करने की कोशिश की:
target_link_libraries(-lqserialdeviced)
कोई परिवर्तन नहीं होता
।
मैं भी करने की कोशिश की:
if ("${SERIALDEVICE_LIB}" STREQUAL "SERIALDEVICE_LIB-NOTFOUND")
message(FATAL_ERROR "'qserialdeviced' wasn't found!")
else()
message("'qserialdeviced' found: " ${SERIALDEVICE_LIB})
endif()
लेकिन इस परीक्षण सफल होता है। पुस्तकालय पाया गया है:
'qserialdeviced' found: /usr/lib/libqserialdeviced.so
क्या कोई मुझे समझने में मदद कर सकता है कि यहां क्या होता है?
मैं लिनक्स फेडोरा 13, सेमेक संस्करण 2.8.0, जीसीसी (जीसीसी) 4.4.5 20101112 (रेड हैट 4.4.5-2) और केडीएफएल-4.1.0-1.fc13.x86_64 का उपयोग कर रहा हूं।
धन्यवाद मैं अग्रिम।
संपादित करें:
@DatChu ने सुझाव दिया है, मैं विभाजित मेरी CMakeLists.txt
मेरी उपनिर्देशिका और सब कुछ भर में अब मुझे समझ में आता है।
धन्यवाद हमेशा!
नहीं, मैं यह सेट नहीं किया है, लेकिन 'add_executable (UART src/main.cpp src/uart.cpp की तरह कुछ करने की कोशिश की ...) '। मैंने रोका क्योंकि मुझे 'add_subdirectory (src) 'के बाद सभी स्रोत फ़ाइलों के नाम दोहराने के लिए कोई चालाक नहीं है। क्या ऐसा करने का कोई बेहतर तरीका है? जब मैंने सभी ".cpp" फ़ाइलों को मैन्युअल रूप से जोड़ने का प्रयास किया तो भी मुझे इरॉस का जिक्र करना होगा। अगर आप चाहते हैं, तो मैं अपनी पोस्ट में त्रुटि डाल सकता हूं। धन्यवाद। – j4x
यदि आप अभी मूलभूत CMakeLists.txt को अपडेट कर सकते हैं तो आपके पास अभी क्या है + आपकी परियोजना में फाइलें, मैं सुझाव दे सकता हूं कि आपको सीएमके –
के लिए क्या चाहिए, कृपया 'फ़ाइल (ग्लोब ...) 'के उपयोग की अनुशंसा न करें: http://www.cmake.org/pipermail/cmake/2010-July/037984.html और http://www.cmake.org/pipermail/cmake/2010- सितंबर/039562.html –