为什么无法将Mac Framework文件与CMake链接? [英] Why I cannot link the Mac framework file with CMake?

查看:532
本文介绍了为什么无法将Mac Framework文件与CMake链接?的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我有一个与MAC中的CMake有关的问题。我确保可执行程序将使用以下代码正确链接框架和库:

I have a question related to CMake in MAC. I make sure that the executable program will link the framework and libraries correctly with the following codes:

link_directories(directory_to_framework_and_libs)
add_executable(program ${FILE_LIST})
target_link_libraries(program framework_name lib1 lib2)

在在第一行代码中,我表示可执行程序可以在其中搜索框架和库的位置。在第三行代码中,框架和库将链接到可执行程序。但是,当我使用Xcode 4编译从cmake文件创建的xcode.project时,该项目不断抱怨它找不到 -lframework_name ld:找不到库-lframework_name 任何想法将不胜感激。

In the first line code, I denote the location where the executable program can search for the framework and libraries. In the third line code, the framework and the libraries will link to the executable program. However, when I compile the xcode.project created from the cmake file with Xcode 4, the project keeps complaining that it cannot find -lframework_name: ld: library not found -lframework_name Any ideas will be appreciated.

推荐答案

您无法以这种方式链接到框架,必须使用 find_library ,因为它包括对OSX框架的一些特殊处理。

You can't link to a framework this way, you have to use find_library as it includes some special handling for frameworks on OSX.

此外,请勿使用 link_directories ,CMake使用库的完整路径,因此不需要。

Also, don't use link_directories, CMake use full paths to libraries and it's not needed.

这里有些简单AudioUnit示例:

Here's some simple example with AudioUnit:

find_library(AUDIO_UNIT AudioUnit)
if (NOT AUDIO_UNIT)
    message(FATAL_ERROR "AudioUnit not found")
endif()

add_executable(program ${program_SOURCES})
target_link_libraries(program ${AUDIO_UNIT})

这篇关于为什么无法将Mac Framework文件与CMake链接?的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆