gpt4 book ai didi

macos - "ld: unknown option: -soname"在 OS X 上

转载 作者:行者123 更新时间:2023-12-03 10:45:04 35 4
gpt4 key购买 nike

我尝试在 Mac OS X 上使用 CMake 构建我的应用程序,但出现以下错误:

Linking CXX shared library libsml.so
ld: unknown option: -soname
collect2: ld returned 1 exit status
make[2]: *** [libsml.so] Error 1
make[1]: *** [CMakeFiles/sml.dir/all] Error 2
make: *** [all] Error 2

这很奇怪,因为 Mac 有 .dylib 扩展名而不是 .so。

有我的 CMakeLists.txt:
cmake_minimum_required(VERSION 2.6)

PROJECT (SilentMedia)

SET(SourcePath src/libsml)

IF (DEFINED OSS)
SET(OSS_src
${SourcePath}/Media/Audio/SoundSystem/OSS/DSP/DSP.cpp
${SourcePath}/Media/Audio/SoundSystem/OSS/Mixer/Mixer.cpp
)
ENDIF(DEFINED OSS)

IF (DEFINED ALSA)
SET(ALSA_src
${SourcePath}/Media/Audio/SoundSystem/ALSA/DSP/DSP.cpp
${SourcePath}/Media/Audio/SoundSystem/ALSA/Mixer/Mixer.cpp
)
ENDIF(DEFINED ALSA)

SET(SilentMedia_src

${SourcePath}/Utils/Base64/Base64.cpp
${SourcePath}/Utils/String/String.cpp
${SourcePath}/Utils/Random/Random.cpp

${SourcePath}/Media/Container/FileLoader.cpp

${SourcePath}/Media/Container/OGG/OGG.cpp

${SourcePath}/Media/PlayList/XSPF/XSPF.cpp
${SourcePath}/Media/PlayList/XSPF/libXSPF.cpp
${SourcePath}/Media/PlayList/PlayList.cpp

${OSS_src}
${ALSA_src}

${SourcePath}/Media/Audio/Audio.cpp
${SourcePath}/Media/Audio/AudioInfo.cpp
${SourcePath}/Media/Audio/AudioProxy.cpp

${SourcePath}/Media/Audio/SoundSystem/SoundSystem.cpp
${SourcePath}/Media/Audio/SoundSystem/libao/AO.cpp

${SourcePath}/Media/Audio/Codec/WAV/WAV.cpp
${SourcePath}/Media/Audio/Codec/Vorbis/Vorbis.cpp
${SourcePath}/Media/Audio/Codec/WavPack/WavPack.cpp
${SourcePath}/Media/Audio/Codec/FLAC/FLAC.cpp
)

SET(SilentMedia_LINKED_LIBRARY
sml
vorbisfile
FLAC++
wavpack
ao
#asound
boost_thread-mt
boost_filesystem-mt
xspf
gtest
)

INCLUDE_DIRECTORIES(
/usr/include
/usr/local/include
/usr/include/c++/4.4
/Users/alex/Downloads/boost_1_45_0
${SilentMedia_SOURCE_DIR}/src
${SilentMedia_SOURCE_DIR}/${SourcePath}
)

#link_directories(
# /usr/lib
# /usr/local/lib
# /Users/alex/Downloads/boost_1_45_0/stage/lib
#)

IF(LibraryType STREQUAL "static")
ADD_LIBRARY(sml-static STATIC ${SilentMedia_src})
# rename library from libsml-static.a => libsml.a
SET_TARGET_PROPERTIES(sml-static PROPERTIES OUTPUT_NAME "sml")
SET_TARGET_PROPERTIES(sml-static PROPERTIES CLEAN_DIRECT_OUTPUT 1)
ELSEIF(LibraryType STREQUAL "shared")
ADD_LIBRARY(sml SHARED ${SilentMedia_src})

# change compile optimization/debug flags # -Werror -pedantic
IF(BuildType STREQUAL "Debug")
SET_TARGET_PROPERTIES(sml PROPERTIES COMPILE_FLAGS "-pipe -Wall -W -ggdb")
ELSEIF(BuildType STREQUAL "Release")
SET_TARGET_PROPERTIES(sml PROPERTIES COMPILE_FLAGS "-pipe -Wall -W -O3 -fomit-frame-pointer")
ENDIF()

SET_TARGET_PROPERTIES(sml PROPERTIES CLEAN_DIRECT_OUTPUT 1)
ENDIF()

### TEST ###

IF(Test STREQUAL "true")
ADD_EXECUTABLE (bin/TestXSPF ${SourcePath}/Test/Media/PlayLists/XSPF/TestXSPF.cpp)
TARGET_LINK_LIBRARIES (bin/TestXSPF ${SilentMedia_LINKED_LIBRARY})

ADD_EXECUTABLE (bin/test1 ${SourcePath}/Test/test.cpp)
TARGET_LINK_LIBRARIES (bin/test1 ${SilentMedia_LINKED_LIBRARY})

ADD_EXECUTABLE (bin/TestFileLoader ${SourcePath}/Test/Media/Container/FileLoader/TestFileLoader.cpp)
TARGET_LINK_LIBRARIES (bin/TestFileLoader ${SilentMedia_LINKED_LIBRARY})

ADD_EXECUTABLE (bin/testMixer ${SourcePath}/Test/testMixer.cpp)
TARGET_LINK_LIBRARIES (bin/testMixer ${SilentMedia_LINKED_LIBRARY})
ENDIF (Test STREQUAL "true")

### TEST ###

ADD_CUSTOM_TARGET(doc COMMAND doxygen ${SilentMedia_SOURCE_DIR}/doc/Doxyfile)

在 Linux 上没有错误。

构建过程:
cmake -D BuildType=Debug -D LibraryType=shared .
make

我发现,在 CMakeFiles/sml.dir/link.txt 中生成了错误的命令.但是为什么,因为 CMake 的目标是跨平台..

如何解决?

最佳答案

我在 OS X 上遇到了类似的问题,我使用 install_name 解决了这个问题。切换而不是 soname .

gcc -shared <files> -lc -Wl,-install_name,<libname>.so, -o <libname>.so.1

关于macos - "ld: unknown option: -soname"在 OS X 上,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/4580789/

35 4 0
Copyright 2021 - 2024 cfsdn All Rights Reserved 蜀ICP备2022000587号
广告合作:1813099741@qq.com 6ren.com