注册 登录  
 加关注
   显示下一条  |  关闭
温馨提示!由于新浪微博认证机制调整,您的新浪微博帐号绑定已过期,请重新绑定!立即重新绑定新浪微博》  |  关闭

Q超越兔子的蜗牛O--逸云沙鸥Linux

飘飘何所似,天地一沙鸥;落霞与孤鹜齐飞,秋水共长天一色~~

 
 
 

日志

 
 

cmake 解决错误:Cannot specify link libraries for target  

2012-08-18 15:23:38|  分类: Qt学习和开发 |  标签: |举报 |字号 订阅

  下载LOFTER 我的照片书  |
最近研究cmake来配置Qt的编译方法,写好了CMakeLists.txt通过编译后却无法链接成功;由于用的是mac osx,还以为是不同系统链接库出了问题;检查他给出的路径(变量${QT_LIBRARIES}的内容)为:

/Volumes/Design/LocalSoft/Qt/Desktop/Qt/4.8.1/gcc/lib/QtGui.framework/Volumes/Design/LocalSoft/Qt/Desktop/Qt/4.8.1/gcc/lib/QtCore.framework


手动设置为静态库的路径:

TARGET_LINK_LIBRARIES(FilterSamesetBasic
/Volumes/Design/LocalSoft/Qt/Desktop/Qt/4.8.1/gcc/lib/QtGui.la
/Volumes/Design/LocalSoft/Qt/Desktop/Qt/4.8.1/gcc/lib/QtCore.la )

还是链接失败,错误如下:

Linking CXX executable FilterSamesetBasic
ld: warning: ld: warning: ignoring file /Volumes/Design/LocalSoft/Qt/Desktop/Qt/4.8.1/gcc/lib/QtGui.la, file was built for unsupported file format ( 0x23 0x20 0x51 0x74 0x47 0x75 0x69 0x2e 0x6c 0x61 0x20 0x2d 0x20 0x61 0x20 0x6c ) which is not the architecture being linked (x86_64): /Volumes/Design/LocalSoft/Qt/Desktop/Qt/4.8.1/gcc/lib/QtGui.laignoring file /Volumes/Design/LocalSoft/Qt/Desktop/Qt/4.8.1/gcc/lib/QtCore.la, file was built for unsupported file format ( 0x23 0x20 0x51 0x74 0x43 0x6f 0x72 0x65 0x2e 0x6c 0x61 0x20 0x2d 0x20 0x61 0x20 ) which is not the architecture being linked (x86_64): /Volumes/Design/LocalSoft/Qt/Desktop/Qt/4.8.1/gcc/lib/QtCore.la

看来这个静态库是不合适的,还是仔细琢磨出错的那句话:

CMake Error at src/CMakeLists.txt:19 (TARGET_LINK_LIBRARIES):
  Cannot specify link libraries for target "FilterSamesetBasic" which is not
  built by this project.


还是疯狂查资料,最后在http://answers.ros.org/question/10890/cannot-specify-link-libraries-for-target/ 上,看到高手的回复,弄懂了问题所在:

In principle your file should work. The only thing is that you need the target (rosbuild_add_executable) before the target_link_libraries.

也就是说 要将 ADD_EXECUTABLE的声明放到设置库文件的TARGET_LINK_LIBRARIES之前,修改后终于链接成功了,可以使用啦~~,(新手不懂得很多啊!!!)附上核心内容和注视,以作纪念:

FIND_PACKAGE(Qt4 REQUIRED)
ADD_DEFINITIONS(${QT_DEFINITIONS})
INCLUDE(${QT_USE_FILE})

# 下面的是路径测试
#MESSAGE(STATUS "The BINARY dir is: " ${PROJECT_BINARY_DIR})
#MESSAGE(STATUS "The SOURCE dir is: " ${PROJECT_SOURCE_DIR})

# 设置输出程序的路径,为编译目录下的bin目录
SET(EXECUTABLE_OUTPUT_PATH ${PROJECT_BINARY_DIR}/bin)

SET(FilterSamesetBasic_SOURCES main.cpp mainwidget.cpp)
SET(FilterSamesetBasic_HEADERS mainwidget.h)
SET(FilterSamesetBasic_FORMS ../ui/mainwidget.ui)

QT4_WRAP_CPP(FilterSamesetBasic_HEADERS_MOC ${FilterSamesetBasic_HEADERS})
QT4_WRAP_UI(FilterSamesetBasic_FORMS_HEADERS ${FilterSamesetBasic_FORMS})

# 添加编译路径到包含的路径中,否则部分编译出的头文件找不到
INCLUDE_DIRECTORIES(${CMAKE_CURRENT_BINARY_DIR})

ADD_EXECUTABLE(FilterSamesetBasic ${FilterSamesetBasic_SOURCES}
${FilterSamesetBasic_FORMS_HEADERS}
${FilterSamesetBasic_HEADERS_MOC}
)

# 添加共享库路,注意该配置必须添加在设置应用程序后,即ADD_EXECUTABLE后面
IF(LINUX)
MESSAGE(STATUS "Found LINUX OS")
TARGET_LINK_LIBRARIES(FilterSamesetBasic ${QT_LIBRARIES})
ELSEIF(APPLE)
MESSAGE(STATUS "Found APPLE OS")
TARGET_LINK_LIBRARIES(FilterSamesetBasic ${QT_LIBRARIES})
ENDIF()
#LINK_DIRECTORIES(${QT_LIBRARIES})


  评论这张
 
阅读(6296)| 评论(0)
推荐 转载

历史上的今天

评论

<#--最新日志,群博日志--> <#--推荐日志--> <#--引用记录--> <#--博主推荐--> <#--随机阅读--> <#--首页推荐--> <#--历史上的今天--> <#--被推荐日志--> <#--上一篇,下一篇--> <#-- 热度 --> <#-- 网易新闻广告 --> <#--右边模块结构--> <#--评论模块结构--> <#--引用模块结构--> <#--博主发起的投票-->
 
 
 
 
 
 
 
 
 
 
 
 
 
 

页脚

网易公司版权所有 ©1997-2017