[CMake] Link error when building static exe against static Qt 4.5 plugin

Andreas Pakulat apaku at gmx.de
Mon Mar 23 12:57:12 EDT 2009


On 23.03.09 16:53:15, Stephen Collyer wrote:
> 2009/3/23 Stephen Collyer <scollyer at netspinner.co.uk>
> 
> > I'm trying to build a fully static exe on Opensuse 11.1 against a static
> > build of Qt 4.5, and
> > I'm trying to link against a static QMySQL plugin.
> >
> > I'm getting a link error when I do so, and I suspect it's because I'm not
> > telling LINK_LIBRARIES how to link against the static plugin
> >
> 
> OK, I've more-or-less sorted this out. I have added the following:
> 
> IF (NOT "${BUILD_SHARED_LIBS}")
>     SET(SQL_LIB_DIRS "${QT_LIBRARY_DIR}/../plugins/sqldrivers"
> "/usr/lib/mysql")
>     SET(MYSQL_LIBS qsqlmysql mysqlclient)
> ENDIF (NOT "${BUILD_SHARED_LIBS}")
> 
> LINK_DIRECTORIES(${QT_LIBRARY_DIR} "../plugins" ${SQL_LIB_DIRS})
> 
> and have changed the exe linking as follows:
> 
> SET(PM_SRCS protocol_manager.cpp)
> ADD_EXECUTABLE(protocol_manager_exe ${PM_SRCS})
> TARGET_LINK_LIBRARIES(protocol_manager_exe ProtocolManager ClientCertificate
> Server HTTP IPCListener Comms Exceptions Support ${MYSQL_LIBS}
> ${QT_LIBRARIES})
> 
> However, I'm not entirely happy as:
> 
> a) I've hardcoded the relative path ../plugins/sqldrivers in the
> SQL_LIB_DIRS

Thats ok, anybody who doesn't have this simply has a broken Qt install,
Linux distro's usually provide some directory under which they symlink a
proper directory hierarchy (and if the distro doesn't it simply broken).

You could of course also use the (not properly documented) QT_PLUGINS_DIR
variable.

> b) I've got an explicity reference to /usr/lib as well
> 
> Can anyone suggest how I can make this a bit more platform independent ?

Use find_library for your mysql library, not sure how to force it to search
for the static version though (except removing the shared lib).

Andreas
 
-- 
You learn to write as if to someone else because NEXT YEAR YOU WILL BE
"SOMEONE ELSE."


More information about the CMake mailing list