我需要将库(portaudio)链接为静态库。当我执行以下操作时
arm-none-linux-gnueabi-gcc -static -L/media/Data/lib/.libs -lportaudio prova.cpp
链接失败告诉我
/tmp/ccuoQi1J.o: In function `main':
prova.cpp:(.text+0x190): undefined reference to `Pa_Initialize'
prova.cpp:(.text+0x1bc): undefined reference to `Pa_GetDeviceCount'
prova.cpp:(.text+0x1d8): undefined reference to `Pa_GetDeviceInfo'
prova.cpp:(.text+0x248): undefined reference to `Pa_OpenDefaultStream'
prova.cpp:(.text+0x27c): undefined reference to `Pa_CloseStream'
prova.cpp:(.text+0x280): undefined reference to `Pa_Terminate'
collect2: ld returned 1 exit status
虽然没有 -static 选项,链接不会出现错误
arm-none-linux-gnueabi-g++ -L/media/Data/lib/.libs -lportaudio prova.cpp
我需要静态链接所有库,可能吗?
最佳答案
-static
On systems that support dynamic linking, this prevents linking with the shared libraries. On other systems, this option has no effect.
在这里,所有 undefined symbol 都在 libportaudio
库中,这是一个共享库,您通过指定 -static
来阻止链接到它,因此会出现错误。 gcc 无法在指定的库路径 (/media/Data/lib/.libs
) 中找到 libportaudio
的静态版本
为什么要静态链接该共享库?有什么具体原因吗?
您可能想阅读本文以了解有关 gcc 如何处理 shared and static libraries. 的更多信息
关于gcc - 无法将 portaudio 库链接为静态库,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/9992204/