Linux-在编译时链接vs在运行时针对std ::库链接

首先是问题:
我需要一种无需在/etc/ld.so.conf.d中放置配置文件的方法,以允许客户端使用默认安装的gcc在RHEL5.7和RHEL6.1上针对我的SDK进行构建.在这种情况下,设置LD_LIBRARY_PATH不起作用.还有其他方法可以使客户链接到我的SDK,而不必向他们提供有关如何配置其系统的知识库文章吗?请阅读下面的说明.

第二个主题:

我负责在RHEL5和RHEL6上构建运行时SDK.我的RHEL5.7盒和RHEL6.1盒一样是标准的未注册安装.但是,在我的RHEL6盒子上,我自己编译了gcc:

[mehoggan@hoggant35002 ~]$cat /etc/redhat-release; gcc --version
Red Hat Enterprise Linux Server release 5.7 (Tikanga)
gcc (GCC) 4.1.2 20080704 (Red Hat 4.1.2-51)
Copyright (C) 2006 Free Software Foundation, Inc.
This is free software; see the source for copying conditions.  There is NO
warranty; not even for MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOS

[mehoggan@hogganz400 session2]$cat /etc/redhat-release; gcc --version
Red Hat Enterprise Linux Server release 6.1 (Santiago)
gcc (GCC) 4.5.2
Copyright (C) 2010 Free Software Foundation, Inc.
This is free software; see the source for copying conditions.  There is NO
warranty; not even for MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE

我无法提供我要链接的.so和.a文件.但是,我将尝试描述正在发生的事情.使用相同的源并将其针对我的SDK构建并运行.我得到以下结果:

RHEL 6 Box:

[mehoggan@hogganz400 session2]$ls -l
total 1848
-rw-rw-r-- 1 mehoggan mehoggan     189 Nov  3 13:02 main.cpp
-rw-rw-r-- 1 mehoggan mehoggan     845 Nov  3 13:02 mainwindow.cpp
-rw-rw-r-- 1 mehoggan mehoggan     288 Nov  3 13:02 mainwindow.h
-rwxrwxr-x 1 mehoggan mehoggan   25818 Nov  4 09:26 Session2
-rw-rw-r-- 1 mehoggan mehoggan     649 Nov  3 13:02 Session2.pro
-rw-rw-r-- 1 mehoggan mehoggan 1847296 Nov  3 13:02 vc90.pdb
[mehoggan@hogganz400 session2]$qmake
[mehoggan@hogganz400 session2]$cat Session2.pro 
#-------------------------------------------------
#
# Project created by QtCreator 2011-10-21T09:32:55
#
#-------------------------------------------------

QT += core gui

TARGET = Session2
TEMPLATE = app


SOURCES += main.cpp\
        mainwindow.cpp

HEADERS  += mainwindow.h

#Modify the path accordingly
CONFIG += debug_and_release
INCLUDEPATH += "/home/mehoggan/arcgis/runtime_sdk/qt10.1/SDK/include"
CONFIG(debug, debug|release) {
  LIBS += -L"/home/mehoggan/arcgis/runtime_sdk/qt10.1/SDK/bin" \
          -lArcGISQtd
} else {
  LIBS += -L"/home/mehoggan/arcgis/runtime_sdk/qt10.1/SDK/bin" \
          -lArcGISQt
}
[mehoggan@hogganz400 session2]$make
make -f Makefile.Release
make[1]: Entering directory `/home/mehoggan/arcgis/runtime_sdk/qt10.1/SDK/workshops/session2'
g++ -c -m64 -pipe -O2 -Wall -W -D_REENTRANT -DQT_NO_DEBUG -DQT_GUI_LIB -DQT_CORE_LIB -I/home/mehoggan/QtSDK/Desktop/Qt/474/gcc/mkspecs/default -I. -I/home/mehoggan/QtSDK/Desktop/Qt/474/gcc/include/QtCore -I/home/mehoggan/QtSDK/Desktop/Qt/474/gcc/include/QtGui -I/home/mehoggan/QtSDK/Desktop/Qt/474/gcc/include -I../../include -Irelease -o release/main.o main.cpp
g++ -c -m64 -pipe -O2 -Wall -W -D_REENTRANT -DQT_NO_DEBUG -DQT_GUI_LIB -DQT_CORE_LIB -I/home/mehoggan/QtSDK/Desktop/Qt/474/gcc/mkspecs/default -I. -I/home/mehoggan/QtSDK/Desktop/Qt/474/gcc/include/QtCore -I/home/mehoggan/QtSDK/Desktop/Qt/474/gcc/include/QtGui -I/home/mehoggan/QtSDK/Desktop/Qt/474/gcc/include -I../../include -Irelease -o release/mainwindow.o mainwindow.cpp
/home/mehoggan/QtSDK/Desktop/Qt/474/gcc/bin/moc -DQT_NO_DEBUG -DQT_GUI_LIB -DQT_CORE_LIB -I/home/mehoggan/QtSDK/Desktop/Qt/474/gcc/mkspecs/default -I. -I/home/mehoggan/QtSDK/Desktop/Qt/474/gcc/include/QtCore -I/home/mehoggan/QtSDK/Desktop/Qt/474/gcc/include/QtGui -I/home/mehoggan/QtSDK/Desktop/Qt/474/gcc/include -I../../include -Irelease mainwindow.h -o release/moc_mainwindow.cpp
g++ -c -m64 -pipe -O2 -Wall -W -D_REENTRANT -DQT_NO_DEBUG -DQT_GUI_LIB -DQT_CORE_LIB -I/home/mehoggan/QtSDK/Desktop/Qt/474/gcc/mkspecs/default -I. -I/home/mehoggan/QtSDK/Desktop/Qt/474/gcc/include/QtCore -I/home/mehoggan/QtSDK/Desktop/Qt/474/gcc/include/QtGui -I/home/mehoggan/QtSDK/Desktop/Qt/474/gcc/include -I../../include -Irelease -o release/moc_mainwindow.o release/moc_mainwindow.cpp
g++ -m64 -Wl,-O1 -Wl,-rpath,/home/mehoggan/QtSDK/Desktop/Qt/474/gcc/lib -o Session2 release/main.o release/mainwindow.o release/moc_mainwindow.o    -L/home/mehoggan/QtSDK/Desktop/Qt/474/gcc/lib -L/home/mehoggan/arcgis/runtime_sdk/qt10.1/SDK/bin -lArcGISQt -lQtGui -lQtCore -lpthread 
make[1]: Leaving directory `/home/mehoggan/arcgis/runtime_sdk/qt10.1/SDK/workshops/session2'
[mehoggan@hogganz400 session2]$echo ${LD_LIBRARY_PATH} 
/home/mehoggan/arcgis/runtime_sdk/qt10.1/ArcGISRuntime10.1/LocalServerLx/bin/wine/lib64:/home/mehoggan/arcgis/runtime_sdk/qt10.1/ArcGISRuntime10.1/LocalServerLx/bin/wine/lib64/wine:/home/mehoggan/arcgis/runtime_sdk/qt10.1/ArcGISRuntime10.1/LocalServerLx/bin/wine/lib64/wine/supp:/home/mehoggan/arcgis/runtime_sdk/qt10.1/ArcGISRuntime10.1/LocalServerLx/bin/wine/lib64:/home/mehoggan/arcgis/runtime_sdk/qt10.1/ArcGISRuntime10.1/LocalServerLx/bin/wine/lib64/wine:/home/mehoggan/arcgis/runtime_sdk/qt10.1/ArcGISRuntime10.1/LocalServerLx/bin/wine/lib64/wine/supp:
[mehoggan@hogganz400 session2]$./Session2 
./Session2: /usr/lib64/libstdc++.so.6: version `GLIBCXX_3.4.14' not found (required by /home/mehoggan/arcgis/runtime_sdk/qt10.1/SDK/bin/libArcGISQt.so.1)

如果我运行以下命令:export LD_LIBRARY_PATH = /usr/local/lib64:${LD_LIBRARY_PATH}; ./Session2或在应用程序运行的/etc/ld.so.conf.d中将libstdc的编译版本设置为路径.

RHEL5 Box:

[mehoggan@hoggant35002 session2]$ls -l
total 1852
-rw-rw-r-- 1 mehoggan mehoggan     189 Nov  3 15:21 main.cpp
-rw-rw-r-- 1 mehoggan mehoggan     845 Nov  3 15:21 mainwindow.cpp
-rw-rw-r-- 1 mehoggan mehoggan     288 Nov  3 15:21 mainwindow.h
-rw-rw-r-- 1 mehoggan mehoggan     649 Nov  3 15:21 Session2.pro
-rw-rw-r-- 1 mehoggan mehoggan   25151 Nov  3 15:51 Session2.pro.user
-rw-rw-r-- 1 mehoggan mehoggan 1847296 Nov  3 15:21 vc90.pdb
[mehoggan@hoggant35002 session2]$qmake
[mehoggan@hoggant35002 session2]$ls -l ./Session2.pro
-rw-rw-r-- 1 mehoggan mehoggan 649 Nov  3 15:21 ./Session2.pro
[mehoggan@hoggant35002 session2]$cat ./Session2.pro
#-------------------------------------------------
#
# Project created by QtCreator 2011-10-21T09:32:55
#
#-------------------------------------------------

QT += core gui

TARGET = Session2
TEMPLATE = app


SOURCES += main.cpp\
        mainwindow.cpp

HEADERS  += mainwindow.h

#Modify the path accordingly
CONFIG += debug_and_release
INCLUDEPATH += "/home/mehoggan/arcgis/runtime_sdk/qt10.1/SDK/include"
CONFIG(debug, debug|release) {
  LIBS += -L"/home/mehoggan/arcgis/runtime_sdk/qt10.1/SDK/bin" \
          -lArcGISQtd
} else {
  LIBS += -L"/home/mehoggan/arcgis/runtime_sdk/qt10.1/SDK/bin" \
          -lArcGISQt
}
[mehoggan@hoggant35002 session2]$make
make -f Makefile.Release
make[1]: Entering directory `/home/mehoggan/arcgis/runtime_sdk/qt10.1/SDK/workshops/session2'
g++ -c -m64 -pipe -O2 -Wall -W -D_REENTRANT -DQT_NO_DEBUG -DQT_GUI_LIB -DQT_CORE_LIB -I/home/mehoggan/QtSDK/Desktop/Qt/474/gcc/mkspecs/default -I. -I/home/mehoggan/QtSDK/Desktop/Qt/474/gcc/include/QtCore -I/home/mehoggan/QtSDK/Desktop/Qt/474/gcc/include/QtGui -I/home/mehoggan/QtSDK/Desktop/Qt/474/gcc/include -I../../include -Irelease -o release/main.o main.cpp
g++ -c -m64 -pipe -O2 -Wall -W -D_REENTRANT -DQT_NO_DEBUG -DQT_GUI_LIB -DQT_CORE_LIB -I/home/mehoggan/QtSDK/Desktop/Qt/474/gcc/mkspecs/default -I. -I/home/mehoggan/QtSDK/Desktop/Qt/474/gcc/include/QtCore -I/home/mehoggan/QtSDK/Desktop/Qt/474/gcc/include/QtGui -I/home/mehoggan/QtSDK/Desktop/Qt/474/gcc/include -I../../include -Irelease -o release/mainwindow.o mainwindow.cpp
/home/mehoggan/QtSDK/Desktop/Qt/474/gcc/bin/moc -DQT_NO_DEBUG -DQT_GUI_LIB -DQT_CORE_LIB -I/home/mehoggan/QtSDK/Desktop/Qt/474/gcc/mkspecs/default -I. -I/home/mehoggan/QtSDK/Desktop/Qt/474/gcc/include/QtCore -I/home/mehoggan/QtSDK/Desktop/Qt/474/gcc/include/QtGui -I/home/mehoggan/QtSDK/Desktop/Qt/474/gcc/include -I../../include -Irelease mainwindow.h -o release/moc_mainwindow.cpp
g++ -c -m64 -pipe -O2 -Wall -W -D_REENTRANT -DQT_NO_DEBUG -DQT_GUI_LIB -DQT_CORE_LIB -I/home/mehoggan/QtSDK/Desktop/Qt/474/gcc/mkspecs/default -I. -I/home/mehoggan/QtSDK/Desktop/Qt/474/gcc/include/QtCore -I/home/mehoggan/QtSDK/Desktop/Qt/474/gcc/include/QtGui -I/home/mehoggan/QtSDK/Desktop/Qt/474/gcc/include -I../../include -Irelease -o release/moc_mainwindow.o release/moc_mainwindow.cpp
g++ -m64 -Wl,-O1 -Wl,-rpath,/home/mehoggan/QtSDK/Desktop/Qt/474/gcc/lib -o Session2 release/main.o release/mainwindow.o release/moc_mainwindow.o    -L/home/mehoggan/QtSDK/Desktop/Qt/474/gcc/lib -L/home/mehoggan/arcgis/runtime_sdk/qt10.1/SDK/bin -lArcGISQt -lQtGui -lQtCore -lpthread
/home/mehoggan/QtSDK/Desktop/Qt/474/gcc/lib/libQtGui.so: undefined reference to `FT_Library_SetLcdFilter'
/home/mehoggan/arcgis/runtime_sdk/qt10.1/SDK/bin/libArcGISQt.so: undefined reference to `std::_List_node_base::_M_unhook()@GLIBCXX_3.4.14'
/home/mehoggan/arcgis/runtime_sdk/qt10.1/SDK/bin/libArcGISQt.so: undefined reference to `std::basic_ostream<char, std::char_traits<char> >& std::__ostream_insert<char, std::char_traits<char> >(std::basic_ostream<char, std::char_traits<char> >&, char const*, long)@GLIBCXX_3.4.9'
/home/mehoggan/arcgis/runtime_sdk/qt10.1/SDK/bin/libArcGISQt.so: undefined reference to `std::_List_node_base::_M_hook(std::_List_node_base*)@GLIBCXX_3.4.14'
/home/mehoggan/QtSDK/Desktop/Qt/474/gcc/lib/libQtGui.so: undefined reference to `FcFreeTypeQueryFace'
/home/mehoggan/arcgis/runtime_sdk/qt10.1/SDK/bin/libArcGISQt.so: undefined reference to `std::basic_ostream<char, std::char_traits<char> >& std::basic_ostream<char, std::char_traits<char> >::_M_insert<double>(double)@GLIBCXX_3.4.9'
/home/mehoggan/arcgis/runtime_sdk/qt10.1/SDK/bin/libArcGISQt.so: undefined reference to `std::ctype<char>::_M_widen_init() const@GLIBCXX_3.4.11'
collect2: ld returned 1 exit status
make[1]: *** [Session2] Error 1
make[1]: Leaving directory `/home/mehoggan/arcgis/runtime_sdk/qt10.1/SDK/workshops/session2'
make: *** [release] Error 2

这将是一篇非常长的文章,我想我已经提供了足够的资源来开始提供帮助.如果您需要任何具体帮助,请告诉我.

我要针对的libstdc信息的最后一点.

RHEL6:
[mehoggan@hogganz400 session2]$strings /usr/local/lib64/libstdc++.so.6 | grep GLIB
GLIBCXX_3.4
GLIBCXX_3.4.1
GLIBCXX_3.4.2
GLIBCXX_3.4.3
GLIBCXX_3.4.4
GLIBCXX_3.4.5
GLIBCXX_3.4.6
GLIBCXX_3.4.7
GLIBCXX_3.4.8
GLIBCXX_3.4.9
GLIBCXX_3.4.10
GLIBCXX_3.4.11
GLIBCXX_3.4.12
GLIBCXX_3.4.13
GLIBCXX_3.4.14
GLIBC_2.2.5
GLIBC_2.3
GLIBC_2.3.2
GLIBCXX_FORCE_NEW
GLIBCXX_DEBUG_MESSAGE_LENGTH

RHEL5:

[mehoggan@hoggant35002 session2]$strings /usr/lib64/libstdc++.so.6 | grep GLIBC
GLIBCXX_3.4
GLIBCXX_3.4.1
GLIBCXX_3.4.2
GLIBCXX_3.4.3
GLIBCXX_3.4.4
GLIBCXX_3.4.5
GLIBCXX_3.4.6
GLIBCXX_3.4.7
GLIBCXX_3.4.8
GLIBC_2.3
GLIBC_2.3.2
GLIBC_2.4
GLIBC_2.2.5
GLIBCXX_FORCE_NEW
最佳答案
看来您的Qt库(libQtGui.so和libArcGISQt​​.so)具有对GLIBCXX_3.4.14的依赖,它在RHEL 5盒中不存在,可能是因为您在RHEL 6盒上构建并安装了它(Qt).您需要在RHEL 5上构建Qt,或在RHEL 5框中提供对更新的3.4.14库的访问.任何想要运行您的二进制文件的人都将需要访问针对其构建的共享库的正确版本.

为了“访问”一个库,它需要在相关机器上可读,并位于在ld.so.conf中配置的位置,该位置在运行该应用程序的LD_LIBRARY_PATH envvar中,或配置为通过-rpath链接选项可执行文件.

我发现非常有用的一个链接选项是-Wl,-rpath,’$ORIGIN’.这将使应用程序在包含可执行文件的目录中查找动态库以及ld.so.conf(并优先于ld.so.conf).因此,您可以构建一个可执行文件,并向人们提供一个带有可执行文件和一堆.so动态库的文件包,并告诉他们“要么在您的计算机上安装.so文件,要么将它们全部与可执行文件放在同一目录中, ”,然后他们就可以运行可执行文件而不会带来太多麻烦.这允许单个二进制软件包,几乎可以在任何Linux变体上使用.

请注意,当您将此选项放在Makefile中时,通常需要使用-Wl,-rpath,’$$ORIGIN’,因为make会将$视为变量扩展($$扩展为$). qmake可能是相同的.

转载注明原文:Linux-在编译时链接vs在运行时针对std ::库链接 - 代码日志