linux交叉编译链接器问题,未定义引用`g_thread_init'和`org_freedesktop_DBus_request_name'

时间:2016-04-05 12:11:18

标签: linux cmake cross-compiling linker-errors glib

我为ARM cortex A8交叉编译一个软件,并使用CMAKE工具生成Makefile。

我的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

错误清楚地表明该问题与链接有关 我已经检查了 libgthread.so 工具链lib文件夹的路径,并且 libgib-2.0.so 库包含正确。

请建议如何解决此未定义的引用问题。

1 个答案:

答案 0 :(得分:-1)

我已经在项目中做了一些工作,只是注释从该文件中出现错误的地方调用该函数

//g_thread_init(NULL);

`并使用zlib和libffi的依赖项编译代码。