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

Denis Scherbakov denis_scherbakov at yahoo.com
Mon Mar 23 13:30:14 EDT 2009


Steve,

To be platform independent use FIND_LIBRARY and its HINTS option.
You may want to check CMake/Modules/Find*.cmake files. There are great
examples how to be fully platform independent.

If BUILD_SHARED_LIBS, then ALL libraries in your project will be built
shared. I use for this one separate variable or separate target like:
MyLibraryShared and MyLibraryStatic.

/usr/lib is scanned automatically, you don't need to include it.

If Qt is using MySQL library, you need to include it after Qt, not before.

Denis

 
> 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
> b) I've got an explicity reference to /usr/lib as well
> 



      


More information about the CMake mailing list