qmake to cmake转换和链接错误

时间:2012-11-24 18:19:22

标签: c++ qt linker cmake qmake

我从qmake转换了一个项目(最初我使用qt-creator在mac / linux / win上构建它)到cmake,我收到了很多链接错误。

例如:

架构x86_64的未定义符号:   “runion(QtRegion const&,QtRegion const&)”,引自:       3DView.cpp.o中的Q3DView :: ReloadLineData()   “pafrand(int)”,引自:

我的.pro文件:

CONFIG += debug_and_release
QT            += core gui opengl
DEFINES       += _TEST1
TEMPLATE      = app
TARGET        = test
HEADERS       = xxx.h \
                xxxxxx.h \
                etc.h
    Libs/include/generic/xxxxxx.h

SOURCES       = xxxx.cpp \
                xxx.cpp \
                xxxx.cpp 

INCLUDEPATH   += Libs/include
INCLUDEPATH   += ../plugin/srv

RESOURCES     = resource.qrc

##### LINUX
unix:!macx:INCLUDEPATH += . /usr/local/include/boost  
unix:!macx:LIBS += -L/usr/local/lib
unix:!macx:LIBS += -lboost_system -lboost_thread
!win32:!macx: LIBS = -lGL -lGLU
########

#### MAC
macx:INCLUDEPATH += . /usr/local/include/boost
macx:LIBS += -L/usr/local/lib
macx:LIBS += -lboost_system-mt -lboost_thread-mt
macx:QMAKE_LFLAGS_RPATH += /usr/local/lib
####

QMAKE_CXXFLAGS_WARN_ON =

FORMS += \
    UI/xxx.ui \
    UI/xx.ui

我的cmake文件版本:

project( test )

cmake_minimum_required( VERSION 2.6 )

if(APPLE)
set(CMAKE_OSX_ARCHITECTURES x86_64)
ENDIF()

set ( CMAKE_BUILD_TYPE Debug )

add_definitions ( -Wall )

find_package ( Qt4 REQUIRED )

FIND_PACKAGE(Boost)
IF (Boost_FOUND)
    INCLUDE_DIRECTORIES(${Boost_INCLUDE_DIR})
    ADD_DEFINITIONS( "-DHAS_BOOST" )
ENDIF()

find_package(GLUT)
find_package(OpenGL)
IF(APPLE)
SET(CMAKE_CXX_LINK_FLAGS "-framework OpenGL -framework GLUT")
ENDIF(APPLE)

set ( test_HDRS
    xxxx.h
    xxxxxx.h
    xxxx.h
    )

set ( test_SRCS
    xxxxx.cpp
    xxx.cpp
    xxxxx.cpp
    )

set ( test_UIS
    UI/xx.ui
    UI/xxxx.ui
    )
QT4_WRAP_UI(UIS ${test_UIS})

set ( test_RSCS
    resource.qrc
    )

QT4_ADD_RESOURCES(RSCS ${test_RSCS})

QT4_WRAP_CPP(MOCS ${test_HDRS})

INCLUDE(${QT_USE_FILE})
ADD_DEFINITIONS(${QT_DEFINITIONS})

include_directories (
    ${CMAKE_SOURCE_DIR} ${CMAKE_CURRENT_BINARY_DIR}
    ${QT_QTCORE_INCLUDE_DIR} ${QT_QTGUI_INCLUDE_DIR} ${QT_QTCORE_INCLUDE_DIR} ${QT_QTGUI_INCLUDE_DIR} ${QT_QTOPENGL_INCLUDE_DIR}
    Libs/include
    /usr/local/include/boost
    ../plugin/srv)

link_directories (
        /usr/local/lib
    )

add_executable ( test ${test_SRCS} ${UIS} ${RSCS} ${TRS} ${MOCS} )

target_link_libraries ( test  ${QT_LIBRARIES} ${QT_QTCORE_LIBRARY} ${QT_QTGUI_LIBRARY} ${QT_QTCORE_LIBRARY} ${QT_QTGUI_LIBRARY} ${QT_QTOPENGL_LIBRARY} )

我尝试了很多不同的东西,我在网上找到但总是同样的问题。 有任何想法吗?感谢

1 个答案:

答案 0 :(得分:0)

您未在-lqgis_core -lqgis_gui中关联CMakeLists.txt。将qgis_coreqgis_gui添加到target_link_libraries()来电。