Qt5 Compile with an error "undefined reference" when linking static libraries or dynamic libraries
-
Qt5 linked the static libraries which have defined by this function,but the error still appear:
qt_odin.o:‘QOdinMsg::MsgQCreate()’ : qt_odin.cpp.text+0x14):function ‘od_msg_create_fix_trans(char const*, unsigned int, unsigned int, unsigned int) ’ undefined reference
linked lib:
LIBS += $$PWD/interface/lib/tx1/libparam_msg.a \ $$PWD/interface/lib/tx1/libengine.a \ $$PWD/interface/open_lib/json-c-0.12.1/tx1/lib/libjson-c.a
nm:
nm libengine.a | grep od_msg_create_fix_trans: 0000000000000000 T od_msg_create_fix_trans
Regards
-
-
the compiler cmd :
/home/suma/tx1/gcc/gcc-linaro-6.2.1-2016.11-x86_64_aarch64-linux-gnu/bin/aarch64-linux-gnu-g++ -Wl,-rpath-link,/home/suma/tx1/Linux_for_Tegra/rootfs/usr/lib/aarch64-linux-gnu -Wl,-rpath-link,/home/suma/tx1/Linux_for_Tegra/rootfs/usr/lib/aarch64-linux-gnu/tegra -Wl,-rpath-link,/home/suma/tx1/Linux_for_Tegra/rootfs/usr/lib -Wl,-rpath-link,/home/suma/tx1/Linux_for_Tegra/rootfs/lib/aarch64-linux-gnu --sysroot=/home/suma/tx1/Linux_for_Tegra/rootfs -Wl,-O1 -Wl,-rpath,/usr/local/qt5/lib -o GUIControlSystem main.o ... ... qt_odin.o qrc_qml.o ... ... moc_qt_odin.o -L/home/suma/tx1/Linux_for_Tegra/rootfs/usr/lib/aarch64-linux-gnu -L/home/suma/tx1/Linux_for_Tegra/rootfs/usr/lib -L/home/suma/tx1/Linux_for_Tegra/rootfs/lib/aarch64-linux-gnu /home/suma/interface/lib/tx1/libparam_msg.a /home/suma/interface/lib/tx1/libengine.a /home/suma/interface/open_lib/json-c-0.12.1/tx1/lib/libjson-c.a -L/home/suma/tx1/qt/qt5/lib -lQt5QuickWidgets -lQt5Quick -lQt5Widgets -lQt5Multimedia -lQt5Gui -lQt5Qml -lQt5Network -lQt5Sql -lQt5SerialPort -lQt5Core -lGLESv2 -lpthread
-
For linux systems I am suggesting that you follow the rules for declaring libraries. or this here
When I read your first post, I thought you are on windows because you are using windows notation for library declaration.
AFAIK that would help in your case. For linux there has been always the split between library path (-L) and library (-l) in declaration. Not sure, if there are really any linux systems around being able to handle differently. Anyway it will not hurt following these rules. You can even do it on windows with MinGW tool chain.
@Alex_wang said in Qt5 Compile with an error "undefined reference" when linking static libraries or dynamic libraries:
main.o ... ... qt_odin.o qrc_qml.o ... ... moc_qt_odin.o
-L/home/suma/tx1/Linux_for_Tegra/rootfs/usr/lib/aarch64-linux-gnu
-L/home/suma/tx1/Linux_for_Tegra/rootfs/usr/lib
-L/home/suma/tx1/Linux_for_Tegra/rootfs/lib/aarch64-linux-gnu
/home/suma/interface/lib/tx1/libparam_msg.a <<<<<< those need a split
/home/suma/interface/lib/tx1/libengine.a <<<<<< those need a split
/home/suma/interface/open_lib/json-c-0.12.1/tx1/lib/libjson-c.a <<<<<< those need a split
-L/home/suma/tx1/qt/qt5/lib
-lQt5QuickWidgets -lQt5Quick -lQt5Widgets -lQt5Multimedia -lQt5Gui -lQt5Qml
-lQt5Network -lQt5Sql -lQt5SerialPort -lQt5Core -lGLESv2
-lpthreadI have marked in the quoted section the three lines the linker cannot understand.
@Alex_wang said in Qt5 Compile with an error "undefined reference" when linking static libraries or dynamic libraries:
LIBS += -L$$PWD/interface/lib/tx1 -llibparam_msg.a \ -L$$PWD/interface/lib/tx1 -llibengine.a \ -L$$PWD/interface/open_lib/json-c-0.12.1/tx1 -llib/libjson-c.a
This may work.
I am not sure about the notation of libraries in linux. The naming seem to be too close to windows MinGW libs. -
If that function is originally in a .c file, the traditional error is that in the header file (or in your manually pasted prototype) it has not been defined as extern "C".
-
Read this very carefully.
As @koahnig said you're not linking properly, also for static linking it's advisable (very, very advisable) you add the libraries to the
PRE_TARGETDEPS
variable in your project file, explanation here.Finally, if
libengine.a
has dependencies of its own on dynamic libraries, those have to be linked with the application/user code, which is my "educated" guess for whyod_msg_create_fix_trans
can't be found (the library list is on the short side). Where is this function defined? -
Hi,
.pro has been changed :unix:!macx: LIBS += -L$$PWD/../../../../../opt/odin/lib/tx1/ -lparam_msg INCLUDEPATH += $$PWD/../../../../../opt/odin/lib/tx1 DEPENDPATH += $$PWD/../../../../../opt/odin/lib/tx1 unix:!macx: PRE_TARGETDEPS += $$PWD/../../../../../opt/odin/lib/tx1/libparam_msg.a unix:!macx: LIBS += -L$$PWD/../../../../../opt/odin/lib/tx1/ -lengine INCLUDEPATH += $$PWD/../../../../../opt/odin/lib/tx1 DEPENDPATH += $$PWD/../../../../../opt/odin/lib/tx1 unix:!macx: PRE_TARGETDEPS += $$PWD/../../../../../opt/odin/lib/tx1/libengine.a unix:!macx: LIBS += -L$$PWD/../../../../../opt/odin/open_lib/json-c-0.12.1/tx1/lib/ -ljson-c INCLUDEPATH += $$PWD/../../../../../opt/odin/open_lib/json-c-0.12.1/tx1/include DEPENDPATH += $$PWD/../../../../../opt/odin/open_lib/json-c-0.12.1/tx1/include unix:!macx: PRE_TARGETDEPS += $$PWD/../../../../../opt/odin/open_lib/json-c-0.12.1/tx1/lib/libjson-c.a
But the error still ......
-
Hi,
@mvuori
@kshegunov @koahnigThank you for your reply
the error has been solved:
as mvuori said, the header file of the libs is not been defined extern "C"
9/10