[Interest] link error (and probably a dumb question)

René J.V. Bertin rjvbertin at gmail.com
Wed Sep 16 11:19:23 CEST 2015


I hate to ask, but I can't seem to understand while building Qt 5.5.0 on linux why the 1st command fails and the 2nd succeeds:

1%> (cd /opt/local/build/qtbase/src/plugins/sqldrivers/sqlite ; g++ -v -L/opt/local/lib -O3 -march=native -fpermissive -g -Wl,--no-undefined -Wl,--enable-new-dtags -Wl,-rpath,/opt/local/lib -Wl,-rpath,/opt/local/libexec/qt5/lib -Wl,-rpath,/opt/local/lib -Wl,-rpath,/opt/local/libexec/qt5/lib -shared -o libqsqlite.so .obj/smain.o .obj/qsql_sqlite.o .obj/moc_qsql_sqlite_p.o -L/usr/lib/x86_64-linux-gnu -lsqlite3 -L/opt/local/build/qtbase/lib -lQt5Sql -lQt5Core.so -lpthread)
.obj/qsql_sqlite.o: In function `qMakeError':
/opt/local/src/qt-everywhere-opensource-src-5.5.0/qtbase/src/sql/drivers/sqlite/qsql_sqlite.cpp:101: undefined reference to `QSqlError::QSqlError(QString const&, QString const&, QSqlError::ErrorType, QString const&)'
.obj/qsql_sqlite.o: In function `QString::toLower() const &':
/opt/local/src/qt-everywhere-opensource-src-5.5.0/qtbase/include/QtCore/../../src/corelib/tools/qstring.h:389: undefined reference to `QString::toLower_helper(QString const&)'

2%> (cd /opt/local/build/qtbase/src/plugins/sqldrivers/sqlite ; g++ -v -L/opt/local/lib -O3 -march=native -fpermissive -g -Wl,--no-undefined -Wl,--enable-new-dtags -Wl,-rpath,/opt/local/lib -Wl,-rpath,/opt/local/libexec/qt5/lib -Wl,-rpath,/opt/local/lib -Wl,-rpath,/opt/local/libexec/qt5/lib -shared -o libqsqlite.so .obj/smain.o .obj/qsql_sqlite.o .obj/moc_qsql_sqlite_p.o -L/usr/lib/x86_64-linux-gnu -lsqlite3 /opt/local/build/qtbase/lib/libQt5Sql.so /opt/local/build/qtbase/lib/libQt5Core.so -lpthread)

That 2nd command was of course created manually by converting the -L /opt/local/build path into absolute references to the QtSql and QtCore shared libraries. At least the QtCore library seems suitable for the intended kind of linking because the bearer plugins built just fine. The linker also does pull in symbols from both libraries; the 1st command spews a total of 30 lines when both libraries are passed in via -l; over 200 when -lQt5Sql is missing and almost 500 when -lQt5Core is missing instead. Both libraries must be given with their full path. 

When I give only QtCore via a full path I'm left with errors about an undefined reference to
QSqlError::QSqlError(QString const&, QString const&, QSqlError::ErrorType, QString const&)

Does that help understand what's going on here?


More information about the Interest mailing list