我尝试在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
Run Code Online (Sandbox Code Playgroud)
这很奇怪,因为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
) …Run Code Online (Sandbox Code Playgroud) 我看了这里给定的ctypes示例-Beginner,并使用不同的C代码执行了相同的步骤。我已经使用此处提供的C代码构建了一个.dll和.lib:http : //wolfprojects.altervista.org/articles/dll-in-c-for-python/
//test.c
__declspec(dllexport) int sum(int a, int b) {
return a + b;
}
Run Code Online (Sandbox Code Playgroud)
在我的wrapper.py中,我有:
import ctypes
testlib = ctypes.CDLL("C:\\Users\\xyz\\Documents\\Python\\test.dll")
Run Code Online (Sandbox Code Playgroud)
当我运行脚本时,出现以下错误:
self._handle = _dlopen(self._name,mode)
OSError:[WinError 193]%1不是有效的Win32应用程序
如果我用
testlib = ctypes.LibraryLoader("C:\\Users\\xyz\\Documents\\Python\\test.dll")
Run Code Online (Sandbox Code Playgroud)
那么我在运行脚本时没有任何错误。但是,如果我尝试这样做:
testlib.sum(3,4)
Run Code Online (Sandbox Code Playgroud)
我得到错误:
dll = self._dlltype(名称)
TypeError:“ str”对象不可调用
dll和.py位于同一文件夹中。谁能帮助我了解这里的情况。我花了数小时试图弄清楚这一点,但是碰壁了。谢谢。