Reputation: 75
I am building a Shared Library (.so) on Linux and I am compiling and linking in an object that is not dynamically linking in certain functions. These functions are "extern 'C'" functions. They are appearing in the normal symbol table of the shared object but not the external functions list or the dynamic functions list. I am compiling and linking using g++. I have turned off compiler optimizations. Is there special flag that needs to be set in order to get the functions to appear?
Edit: The command I use to link the object files together is this:
g++ -m64 -rpath,/usr/local/Trolltech/Qt-4.8.2/lib -shared -Wl,-soname,libQtCommercialChart.so.1 -o libQtCommercialChart.so.1.0.0 ../build/release/lib/chartdataset.o ../build/release/lib/chartpresenter.o ../build/release/lib/charttheme.o ../build/release/lib/domain.o ../build/release/lib/qchart.o ../build/release/lib/qchartview.o ../build/release/lib/qabstractseries.o ../build/release/lib/chartbackground.o ../build/release/lib/chartelement.o ../build/release/lib/scroller.o ../build/release/lib/chartlayout.o ../build/release/lib/versiontracker.o ../build/release/lib/axisanimation.o ../build/release/lib/xyanimation.o ../build/release/lib/pieanimation.o ../build/release/lib/piesliceanimation.o ../build/release/lib/splineanimation.o ../build/release/lib/baranimation.o ../build/release/lib/stackedbaranimation.o ../build/release/lib/percentbaranimation.o ../build/release/lib/abstractbaranimation.o ../build/release/lib/horizontalbaranimation.o ../build/release/lib/horizontalstackedbaranimation.o ../build/release/lib/horizontalpercentbaranimation.o ../build/release/lib/areachartitem.o ../build/release/lib/qareaseries.o ../build/release/lib/chartaxis.o ../build/release/lib/qabstractaxis.o ../build/release/lib/chartvalueaxisx.o ../build/release/lib/chartvalueaxisy.o ../build/release/lib/qvalueaxis.o ../build/release/lib/chartbarcategoryaxisx.o ../build/release/lib/chartbarcategoryaxisy.o ../build/release/lib/qbarcategoryaxis.o ../build/release/lib/chartcategoryaxisx.o ../build/release/lib/chartcategoryaxisy.o ../build/release/lib/qcategoryaxis.o ../build/release/lib/chartdatetimeaxisx.o ../build/release/lib/chartdatetimeaxisy.o ../build/release/lib/qdatetimeaxis.o ../build/release/lib/bar.o ../build/release/lib/abstractbarchartitem.o ../build/release/lib/qabstractbarseries.o ../build/release/lib/qbarset.o ../build/release/lib/qbarmodelmapper.o ../build/release/lib/qvbarmodelmapper.o ../build/release/lib/qhbarmodelmapper.o ../build/release/lib/qbarseries.o ../build/release/lib/barchartitem.o ../build/release/lib/qstackedbarseries.o ../build/release/lib/stackedbarchartitem.o ../build/release/lib/qpercentbarseries.o ../build/release/lib/percentbarchartitem.o ../build/release/lib/qhorizontalbarseries.o ../build/release/lib/horizontalbarchartitem.o ../build/release/lib/qhorizontalstackedbarseries.o ../build/release/lib/horizontalstackedbarchartitem.o ../build/release/lib/qhorizontalpercentbarseries.o ../build/release/lib/horizontalpercentbarchartitem.o ../build/release/lib/qlegend.o ../build/release/lib/legendmarker.o ../build/release/lib/legendlayout.o ../build/release/lib/linechartitem.o ../build/release/lib/qlineseries.o ../build/release/lib/qpieseries.o ../build/release/lib/piesliceitem.o ../build/release/lib/piechartitem.o ../build/release/lib/qpieslice.o ../build/release/lib/qpiemodelmapper.o ../build/release/lib/qvpiemodelmapper.o ../build/release/lib/qhpiemodelmapper.o ../build/release/lib/qscatterseries.o ../build/release/lib/scatterchartitem.o ../build/release/lib/qsplineseries.o ../build/release/lib/splinechartitem.o ../build/release/lib/xychart.o ../build/release/lib/qxyseries.o ../build/release/lib/qxymodelmapper.o ../build/release/lib/qvxymodelmapper.o ../build/release/lib/qhxymodelmapper.o -L/usr/local/Trolltech/Qt-4.8.2/lib -L/tmp/qcharts/lib/release -Wl,-rpath,/tmp/qcharts/lib/release -lQtGui -L/usr/local/Trolltech/Qt-4.8.2/lib -L/usr/X11R6/lib64 -lQtCore -lpthread
And the command used to build the the object with the missing functions is this:
g++ -c -m64 -pipe -fvisibility=hidden -fvisibility-inlines-hidden -O0 -Wall -W -D_REENTRANT -fPIC -DQTCOMMERCIALCHART_LIBRARY -DQT_NO_DEBUG -DQT_GUI_LIB -DQT_CORE_LIB -DQT_SHARED -I/usr/local/Trolltech/Qt-4.8.2/mkspecs/linux-g++-64 -I. -I/usr/local/Trolltech/Qt-4.8.2/include/QtCore -I/usr/local/Trolltech/Qt-4.8.2/include/QtGui -I/usr/local/Trolltech/Qt-4.8.2/include -I../include -I../include -I. -Ianimations -Iareachart -Iaxis -Iaxis/valueaxis -Iaxis/barcategoryaxis -Iaxis/categoryaxis -Iaxis/datetimeaxis -Ibarchart -Ibarchart/vertical/bar -Ibarchart/vertical/stacked -Ibarchart/vertical/percent -Ibarchart/horizontal/bar -Ibarchart/horizontal/stacked -Ibarchart/horizontal/percent -Ilegend -Ilinechart -Ipiechart -Iscatterchart -Isplinechart -Ithemes -Ixychart -I../build/release/lib -o ../build/release/lib/versiontracker.o versiontracker.cpp
Upvotes: 1
Views: 1377
Reputation: 74098
From man gcc
-fvisibility=default|internal|hidden|protected
...
extern declarations are not affected by -fvisibility, so a lot of code can be recompiled with -fvisibility=hidden with no modifications. However, this means that calls to extern functions with no explicit visibility will use the PLT , so it is more effective to use __attribute ((visibility)) and/or #pragma GCC visibility to tell the compiler which extern declarations should be treated as hidden.
I haven't used this myself, but from GCC Wiki - Visibility and a small example, I would say that adding
__attribute__ ((visibility ("default")))
to your extern "C"
functions, should make them visible in the dynamic functions list, e.g. nm -D libQtCommercialChart.so.1.0.0
.
If you have many functions defined, bracing them with
extern "C" {
#pragma GCC visibility push(default)
...
#pragma GCC visibility pop
};
might be more convenient.
If you don't care about symbol visibility, dropping -fvisibility=hidden
from your command line will work as well, of course.
Upvotes: 4