链接到框架CMake的未定义符号

时间:2016-08-07 17:36:49

标签: c macos linker frameworks cmake

在编译/静态链接a project of mine时,我收到以下错误(在这种情况下使用OpenAL,我尝试过其他音频库,如PulseAudio并获得类似错误):

Undefined symbols for architecture x86_64:
  "_alcCaptureCloseDevice", referenced from:
      _ad_close in libsphinxbase.a(ad_openal.c.o)
  "_alcCaptureOpenDevice", referenced from:
      _ad_open_dev in libsphinxbase.a(ad_openal.c.o)
  "_alcCaptureSamples", referenced from:
      _ad_read in libsphinxbase.a(ad_openal.c.o)
  "_alcCaptureStart", referenced from:
      _ad_start_rec in libsphinxbase.a(ad_openal.c.o)
  "_alcCaptureStop", referenced from:
      _ad_stop_rec in libsphinxbase.a(ad_openal.c.o)
  "_alcGetIntegerv", referenced from:
      _ad_read in libsphinxbase.a(ad_openal.c.o)
ld: symbol(s) not found for architecture x86_64

您可以在项目链接中找到CMakeLists.txt,但我认为错误位于its dependency内(尽管编译得很好并生成了x86_64架构库)。这是依赖项的主要CMakeLists.txt

#
# Initial CMake and project setup
#

CMAKE_MINIMUM_REQUIRED(VERSION 2.8 FATAL_ERROR)
SET(PROJECT_NAME sphinxbase)
PROJECT(${PROJECT_NAME})

SET(CMAKE_MODULE_PATH "${CMAKE_SOURCE_DIR}/cmake")
SET_DIRECTORY_PROPERTIES(PROPERTIES EP_PREFIX ${CMAKE_BINARY_DIR}/build-data)

#
# Setup compiler flags
#

if (NOT CMAKE_BUILD_TYPE)
    message(STATUS "No build type selected, default to Release")
    set(CMAKE_BUILD_TYPE CACHE Release FORCE)
endif()

set(CMAKE_C_FLAGS_DEBUG "${CMAKE_C_FLAGS_DEBUG} -std=gnu11 -O0 -fprofile-arcs -ftest-coverage")
set(CMAKE_C_FLAGS_RELEASE "${CMAKE_C_FLAGS_RELEASE} -std=gnu11 -O3")

#
# Final project settings
#
configure_file("${CMAKE_SOURCE_DIR}/include/sphinx_config.h.in" "${CMAKE_SOURCE_DIR}/include/sphinx_config.h")
INCLUDE_DIRECTORIES(include)
ADD_SUBDIRECTORY(src)
ADD_SUBDIRECTORY(test EXCLUDE_FROM_ALL)

ADD_LIBRARY(${PROJECT_NAME} STATIC
        $<TARGET_OBJECTS:libsphinxad>
        $<TARGET_OBJECTS:fe>
        $<TARGET_OBJECTS:feat>
        $<TARGET_OBJECTS:lm>
        $<TARGET_OBJECTS:util>
        $<TARGET_OBJECTS:sphinx_adtools>
        $<TARGET_OBJECTS:sphinx_cepview>
        $<TARGET_OBJECTS:sphinx_fe>
        $<TARGET_OBJECTS:sphinx_jsgf2fsg>
        $<TARGET_OBJECTS:sphinx_lmtools>
    )

TARGET_LINK_LIBRARIES(${PROJECT_NAME} ${LIBS})

我在${LIBS}对象文件夹中设置libsphinxad

include_directories(${CMAKE_SOURCE_DIR}/include/sphinxbase)

if (WIN32)
    set(SOURCES ${SOURCES} ad_win32.c)
endif ()

find_package(PulseAudio)
if (PULSEAUDIO_FOUND)
    set(SOURCES ${SOURCES} ad_pulse.c)
    set(LIBS ${PULSEAUDIO_LIBRARIES} CACHE INTERNAL "libs")
endif()

find_package(OSS)
if (OSS_FOUND)
    set(SOURCES ${SOURCES} ad_oss.c )
endif()

find_package(OpenAL)
if (OPENAL_FOUND)
    set(SOURCES ${SOURCES} ad_openal.c)
    set(LIBS ${OPENAL_LIBRARY} CACHE INTERNAL "libs")
    include_directories(${OPENAL_INCLUDE_DIR})
endif()

find_package(ALSA)
if (ALSA_FOUND)
    set(SOURCES ${SOURCES} ad_alsa.c)
    set(LIBS ${ALSA_LIBRARIES} CACHE INTERNAL "libs")
endif()

add_library(libsphinxad OBJECT ${SOURCES})

如您所见,我正在链接到OpenAL框架。以下是CMake发送到TARGET_LINK_LIBRARIES的路径,该路径给出了上述错误:

/System/Library/Frameworks/OpenAL.framework

看起来我正在做的事情,所以我有点困惑。我尝试添加-framework标志并添加链接到其他库,如CoreAudio和Foundation无济于事。有什么建议吗?

我已经让项目构建而没有错误链接到动态库,但出于我的目的,我需要静态链接库。

0 个答案:

没有答案