0

I use qmake and .pro files to generate my VisualStudio .vcxproj files.

I have created a static library which contains helper functions for all my error handling. This includes wrappers for fetching error codes out of QSqlTableModel and QSqlQuery.

My library project has QT += sql in order to support these methods.

I am trying to avoid having to add the QT += sql dependency to an application which links the library but otherwise makes no use of sql.

I have passed the QSqlTableModel and QSqlQuery into the library as pointers and forward declared them so I can compile without a problem.

But I get linker errors unresolved external symbol "__declspec(dllimport) public: class QSqlError __cdecl QSqlQueryModel::lastError(void)const "

I can easily work around the linker errors by adding QT += sql to my application.

But, given that my application will never actually call this, can I just make the linker happily move on (and perhaps have the application throw a big structured exception if I ever did call it)?

Mike Kinghan
  • 55,740
  • 12
  • 153
  • 182
Techniquab
  • 843
  • 7
  • 22

2 Answers2

1

But, given that my application will never actually call this

The functions in your static library however will call this, which is why you need QT+=sql.

Nikos C.
  • 50,738
  • 9
  • 71
  • 96
0

It sounds like you want to pass linker flags such as --allow-shlib-undefined (assuming GNU linker). You'll probably need to add that to QMAKE_LFLAGS manually yourself.

I'm not sure what you mean by a "structured exception" here - if an undefined function is called, you can expect your program to receive SIGSEGV, which normally results in a core dump. Certainly not something you could easily deal with and continue.

A better strategy would be to split your library into two libraries: one that depends only on Qt Core and another for use with Qt Sql.

Toby Speight
  • 27,591
  • 48
  • 66
  • 103