0
我交叉編譯一個ARM Cortex A8軟件並使用CMAKE工具生成Makefile。linux交叉編譯鏈接器問題與`g_thread_init'和`org_freedesktop_DBus_request_name'undefined引用
我的CMakeLists.txt文件如下使用以下命令
cmake_minimum_required(VERSION 2.8)
PROJECT(sierra-software)
include_directories($ENV{PREFIX}/include/sierra)
include_directories($ENV{PREFIX}/include/glib-2.0)
include_directories($ENV{PREFIX}/lib/glib-2.0/include)
include_directories($ENV{PREFIX}/include)
include_directories($ENV{PREFIX}/include/dbus-1.0)
include_directories($ENV{PREFIX}/lib/dbus-1.0/include)
find_package(PkgConfig)
# target_include_directories(sierra PUBLIC $<BUILD_INTERFACE:$ENV{PREFIX}/include>
# use, i.e. don't skip the full RPATH for the build tree
# SET(CMAKE_SKIP_BUILD_RPATH FALSE)
# when building, don't use the install RPATH already
# (but later on when installing)
# SET(CMAKE_BUILD_WITH_INSTALL_RPATH FALSE)
# the RPATH to be used when installing
# SET(CMAKE_INSTALL_RPATH "/home/deep/projects/code/build/lib")
IF(CMAKE_CROSSCOMPILING)
set(CMAKE_INSTALL_PREFIX $ENV{PREFIX})
# add_definitions(-g)
# SET(CMAKE_BUILD_WITH_INSTALL_RPATH FALSE)
SET(CMAKE_INSTALL_RPATH "${CMAKE_INSTALL_PREFIX}/lib")
# SET(CMAKE_INSTALL_RPATH_USE_LINK_PATH FALSE)
# add_definitions(-O3 -Wall -c -fmessage-length=0)
ELSE(CMAKE_CROSSCOMPILING)
add_definitions(-DSIMULATE_FIFOS -O3 -g)
set(CMAKE_INSTALL_PREFIX /home/host/satsys/usr)
ENDIF(CMAKE_CROSSCOMPILING)
include_directories(${GTHREAD_INCLUDE_DIRS} ${DBUS_GLIB_INCLUDE_DIRS} ${GLIB2_INCLUDE_DIRS})
link_directories(${GTHREAD_LIBRARY_DIRS} ${DBUS_GLIB_LIBRARY_DIRS} ${GLIB2_LIBRARY_DIRS})
include_directories(NetSerSel/src TrackingData/src ClientExternalGPS/src AlsaSierraConf/src Discretes/src alsa_relay/src smsHandle/src DBUSBaseConnection/src ClientModemsCommunication/src)
add_subdirectory(NetSerSel)
add_subdirectory(Discretes)
add_subdirectory(TrackingData)
add_subdirectory(ClientExternalGPS)
add_subdirectory(AlsaSierraConf)
add_subdirectory(alsa_relay)
add_subdirectory(smsHandle)
add_subdirectory(ModemsManagement)
add_subdirectory(TrackingManagement)
add_subdirectory(serveur_sierra)
add_subdirectory(ModemTalk)
add_subdirectory(DspicTalk)
add_subdirectory(send_msg)
add_subdirectory(get_data)
我生成的Makefile
[linux-devkit]:~/projects/code/src/sierra-software> cmake -DCMAKE_TOOLCHAIN_FILE=./arm.cmake
-- The C compiler identification is GNU 4.7.3
-- The CXX compiler identification is GNU 4.7.3
-- Check for working C compiler: /home/deep/ti-sdk-am335x-evm-07.00.00.00/linux-devkit/sysroots/i686-arago-linux/usr/bin/arm-linux-gnueabihf-gcc
-- Check for working C compiler: /home/deep/ti-sdk-am335x-evm-07.00.00.00/linux-devkit/sysroots/i686-arago-linux/usr/bin/arm-linux-gnueabihf-gcc -- works
-- Detecting C compiler ABI info
-- Detecting C compiler ABI info - failed
-- Check for working CXX compiler: /home/deep/ti-sdk-am335x-evm-07.00.00.00/linux-devkit/sysroots/i686-arago-linux/usr/bin/arm-linux-gnueabihf-g++
-- Check for working CXX compiler: /home/deep/ti-sdk-am335x-evm-07.00.00.00/linux-devkit/sysroots/i686-arago-linux/usr/bin/arm-linux-gnueabihf-g++ -- works
-- Detecting CXX compiler ABI info
-- Detecting CXX compiler ABI info - failed
-- Found PkgConfig: /home/deep/ti-sdk-am335x-evm-07.00.00.00/linux-devkit/sysroots/i686-arago-linux/usr/bin/pkg-config (found version "0.25")
-- checking for module 'alsa'
-- found alsa, version 1.0.26
-- checking for module 'dbus-1'
-- found dbus-1, version 1.6.8
-- checking for module 'glib-2.0'
-- found glib-2.0, version 2.34.3
-- checking for module 'dbus-glib-1'
-- found dbus-glib-1, version 0.100.2
-- checking for module 'gthread-2.0'
-- found gthread-2.0, version 2.34.3
-- checking for module 'glib-2.0'
-- found glib-2.0, version 2.34.3
-- Configuring done
-- Generating done
-- Build files have been written to: /home/deep/projects/code/src/sierra-software
當我使用make命令它提供了以下錯誤 [
linux-devkit]:~/projects/code/src/sierra-software> make
Scanning dependencies of target NetSerSel
[ 2%] Building C object NetSerSel/CMakeFiles/NetSerSel.dir/src/libNetSerSel.c.o
Linking C static library libNetSerSel.a
[ 2%] Built target NetSerSel
Scanning dependencies of target Discretes
[ 5%] Building C object Discretes/CMakeFiles/Discretes.dir/src/libDiscretes.c.o
Linking C static library libDiscretes.a
[ 5%] Built target Discretes
Scanning dependencies of target TrackingData
[ 7%] Building C object TrackingData/CMakeFiles/TrackingData.dir/src/libTrackingData.c.o
Linking C static library libTrackingData.a
[ 7%] Built target TrackingData
Scanning dependencies of target ClientExternalGPS
[ 10%] Building C object ClientExternalGPS/CMakeFiles/ClientExternalGPS.dir/src/libClientSharedExtGPSInfo.c.o
Linking C static library libClientExternalGPS.a
[ 10%] Built target ClientExternalGPS
Scanning dependencies of target AlsaSierraConf
[ 12%] Building C object AlsaSierraConf/CMakeFiles/AlsaSierraConf.dir/src/AlsaSierraConf.c.o
Linking C static library libAlsaSierraConf.a
[ 12%] Built target AlsaSierraConf
Scanning dependencies of target alsa_relay
[ 15%] Building C object alsa_relay/CMakeFiles/alsa_relay.dir/src/alsa_relay.c.o
Linking C static library libalsa_relay.a
[ 15%] Built target alsa_relay
Scanning dependencies of target smsHandle
[ 17%] Building C object smsHandle/CMakeFiles/smsHandle.dir/src/smsHandle.c.o
Linking C static library libsmsHandle.a
[ 17%] Built target smsHandle
Scanning dependencies of target ModemsManagement
[ 20%] Building C object ModemsManagement/CMakeFiles/ModemsManagement.dir/src/marshaller.c.o
[ 22%] Building C object ModemsManagement/CMakeFiles/ModemsManagement.dir/src/libGSM.c.o
[ 25%] Building C object ModemsManagement/CMakeFiles/ModemsManagement.dir/src/libIridium.c.o
[ 27%] Building C object ModemsManagement/CMakeFiles/ModemsManagement.dir/src/Tools.c.o
[ 30%] Building C object ModemsManagement/CMakeFiles/ModemsManagement.dir/src/libsms.c.o
[ 32%] Building C object ModemsManagement/CMakeFiles/ModemsManagement.dir/src/libDspic.c.o
[ 35%] Building C object ModemsManagement/CMakeFiles/ModemsManagement.dir/src/libGC864.c.o
[ 37%] Building C object ModemsManagement/CMakeFiles/ModemsManagement.dir/src/main.c.o
[ 40%] Building C object ModemsManagement/CMakeFiles/ModemsManagement.dir/src/libSharedDevicesInfo.c.o
[ 42%] Building C object ModemsManagement/CMakeFiles/ModemsManagement.dir/src/libSharedModemsInfo.c.o
[ 45%] Building C object ModemsManagement/CMakeFiles/ModemsManagement.dir/src/libDBusModemsManagement.c.o
/home/deep/projects/code/src/sierra-software/ModemsManagement/src/libDBusModemsManagement.c: In function ‘InitDbus’:
/home/deep/projects/code/src/sierra-software/ModemsManagement/src/libDBusModemsManagement.c:149:2: warning: ‘g_type_init’ is deprecated (declared at /home/deep/projects/code/build/include/glib-2.0/gobject/gtype.h:681) [-Wdeprecated-declarations]
/home/deep/projects/code/src/sierra-software/ModemsManagement/src/libDBusModemsManagement.c:150:2: warning: ‘g_thread_init’ is deprecated (declared at /home/deep/projects/code/build/include/glib-2.0/glib/deprecated/gthread.h:265) [-Wdeprecated-declarations]
[ 47%] Building C object ModemsManagement/CMakeFiles/ModemsManagement.dir/src/libSMSmanagement.c.o
[ 50%] Building C object ModemsManagement/CMakeFiles/ModemsManagement.dir/src/libSBD960x.c.o
[ 52%] Building C object ModemsManagement/CMakeFiles/ModemsManagement.dir/src/libModem.c.o
[ 55%] Building C object ModemsManagement/CMakeFiles/ModemsManagement.dir/src/DList.c.o
[ 57%] Building C object ModemsManagement/CMakeFiles/ModemsManagement.dir/src/SFifo.c.o
[ 60%] Building C object ModemsManagement/CMakeFiles/ModemsManagement.dir/src/libThuraya.c.o
[ 62%] Building C object ModemsManagement/CMakeFiles/ModemsManagement.dir/src/DiscretesFifo.c.o
[ 65%] Building C object ModemsManagement/CMakeFiles/ModemsManagement.dir/src/MList.c.o
[ 67%] Building C object ModemsManagement/CMakeFiles/ModemsManagement.dir/src/pduconv.c.o
[ 70%] Building C object ModemsManagement/CMakeFiles/ModemsManagement.dir/src/KList.c.o
Linking C executable ModemsManagement
CMakeFiles/ModemsManagement.dir/src/libDBusModemsManagement.c.o: In function `InitDbus':
libDBusModemsManagement.c:(.text+0x162c): undefined reference to `g_thread_init'
libDBusModemsManagement.c:(.text+0x17b0): undefined reference to `org_freedesktop_DBus_request_name'
collect2: error: ld returned 1 exit status
ModemsManagement/CMakeFiles/ModemsManagement.dir/build.make:590: recipe for target 'ModemsManagement/ModemsManagement' failed
make[2]: *** [ModemsManagement/ModemsManagement] Error 1
CMakeFiles/Makefile2:429: recipe for target 'ModemsManagement/CMakeFiles/ModemsManagement.dir/all' failed
make[1]: *** [ModemsManagement/CMakeFiles/ModemsManagement.dir/all] Error 2
Makefile:117: recipe for target 'all' failed
make: *** [all] Error 2
編制項目
錯誤顯示清楚該問題與連接012有關我已經檢查libgthread.so工具鏈lib文件夾的路徑以及libgib-2.0.so庫包含正確。
請建議如何解決這個未定義的參考問題。
**鏈接**使用'target_link_libraries'命令執行,但它在您提供的代碼中不存在。 – Tsyvarev
是target_link_libraries都包含在子目錄,其中的CMakeLists.txt在ModemsManagement目錄包括例如 target_link_libraries(ModemsManagement並行線程$ {DBUS_LIBRARIES} $ {GLIB_LIBRARIES} $ {DBUS_GLIB_LIBRARIES} $ {} ALSA_LIBRARIES alsa_relay sierra_fifo asound在AlsaSierraConf NetSerSel分立ClientExternalGPS MZ) 安裝(TARGETS調制解調器管理 運行時目的地bin ) – Deep
請提供[mcve]。如果沒有查看您使用的確切命令(和參數),則很難提出建議。目前你的代碼包含了很多與問題無關的東西(比如安裝功能)並且錯過了重要的信息(比如'pkg_check_modules()'調用或者調整pthread)。通過[編輯]你的文章,而不是評論。 – Tsyvarev