编译错误:“找不到-lQtCore4”

时间:2011-07-08 08:45:18

标签: c++ qt4 ubuntu-11.04

昨天我下载了Qt4 Opensource library for linux。运行后

./configure
./make
./make install

将其插入我的.bashrc文件:

PATH=/usr/local/TrollTech/Qt-4.7.3/bin:$PATH
export PATH

在此之后,我运行了cmake以便为我生成一个Makefile。的CMakeLists.txt:

project(VTKToVTFx)

cmake_minimum_required(VERSION 2.6)

find_package(VTK REQUIRED)
find_package(Qt4 REQUIRED)

include(${VTK_USE_FILE})
include(${QT_USE_FILE})

SET(VTK_TO_VTFX_FORMS main.ui)
QT4_WRAP_UI(VTK_TO_VTFX_FORMS_UIC ${VTK_TO_VTFX_FORMS})

SET(MOC_HEADERS VTKToVTFx.h)
qt4_wrap_cpp(MOC_OUTFILES ${MOC_HEADERS})

SET(CPP_SOURCES VTKToVTFx.cpp
                VTKPatch.cpp
                VTKFile.cpp
                VTKData.cpp
                VTKDataHolder.cpp
                )

add_executable(VTKToVTFx ${CPP_SOURCES} ${VTK_TO_VTFX_FORMS_UIC} ${MOC_OUTFILES})

# Adds folders for Visual Studio solution explorer (and for Xcode explorer)
source_group( "Generated"         FILES ${MOC_FILES_CPP} ${VTK_TO_VTFX_FORMS_UIC} ${QRC_FILES_CPP} ${MOC_OUTFILES})

INCLUDE_DIRECTORIES(${CMAKE_CURRENT_BINARY_DIR})

target_link_libraries(VTKToVTFx vtkHybrid)
target_link_libraries(VTKToVTFx QtCore4)
target_link_libraries(VTKToVTFx QtGUI4)

这个CMakeLists.txt在Windows上工作得很好,但是当我尝试在安装Ubuntu时编译输出时,会发生以下错误:

/usr/bin/ld: cannot find -lQtCore4
/usr/bin/ld: cannot find -lQtGUI4

有人能指出我的问题吗?

1 个答案:

答案 0 :(得分:3)

在unix [like]世界中,斜杠是路径分隔符,而不是反斜杠。

\usr\local\TrollTech\Qt-4.7.3\bin评估为usrlocalTrollTechQt-4.7.3bin

编辑:此外,您的CMakeLists.txt似乎有点犯规。看看http://qtnode.net/wiki/Qt4_with_cmake。而不是

target_link_libraries(VTKToVTFx QtCore4)

使用类似的东西(来源是链接的网站):


  
      
  • 要添加对网络或qttest等Qt4库的支持,您需要添加包含文件和相应的库。例如,要添加对网络和qttest库的支持,您可以使用:
  •   
INCLUDE_DIRECTORIES(
   ${QT_INCLUDE_DIR}
   ${QT_QTNETWORK_INCLUDE_DIR}
   ${QT_QTTEST_INCLUDE_DIR}
)

TARGET_LINK_LIBRARIES(
   ${QT_LIBRARIES}
   ${QT_QTNETWORK_LIBRARIES}
   ${QT_QTTEST_LIBRARIES}
)

即使在4.x版本的版本中,库也已重命名并将重命名。幸运的是,不需要硬编码:)