You need to enable JavaScript to run this app.
优惠活动
大模型
产品
解决方案
定价
更多

Qt开发C++音频应用时链接libsox库出现undefined reference to `sox_open_read'错误的求助

Fixing "undefined reference to `sox_open_read'" in Qt + libsox Project

Hey there, I’ve dealt with this exact linking headache when using libsox in Qt C++ projects—let’s get this sorted out for you.

First, let’s clarify the root cause: your IDE can auto-complete sox_open_read because it’s finding the header files correctly, but the linker can’t locate the actual libsox binary library (static or dynamic) that contains the compiled implementation of this function. That’s why you’re hitting the "undefined reference" error.

Here’s how to fix it step by step:

1. Make sure libsox is properly compiled/installed

  • If you built libsox from the source you downloaded, double-check that you generated a linkable library file. You should see something like libsox.a (static library) or libsox.so (Linux dynamic library)/libsox.dll (Windows) in your build output. If you only compiled the Sox command-line tool, you’ll need to recompile the source with the correct flags to build the library.
  • On Linux systems, you can skip building from source and install the pre-built development package instead: sudo apt-get install libsox-dev (this includes both headers and the library files).

2. Configure your Qt .pro file correctly

This is the most critical step—you need to tell Qt’s build system where to find the libsox library and link against it. Add these lines to your project’s .pro file:

# Add path to sox header files (adjust if your src folder is in a different location)
INCLUDEPATH += $$PWD/src

# Add path to the folder containing the libsox library file
LIBS += -L/path/to/your/sox/library/folder

# Link against the sox library
LIBS += -lsox

For example, if your libsox library is in a lib folder at the root of your Qt project, it would look like this:

INCLUDEPATH += $$PWD/src
LIBS += -L$$PWD/lib -lsox
  • Note for Windows: If you’re using a dynamic library, you might need to specify the exact library name (e.g., -lsox-1) or directly reference the .lib file path.

3. Check architecture compatibility

Ensure that your Qt project’s build architecture (32-bit vs 64-bit) matches the architecture of the libsox library you’re using. If you’re building a 64-bit Qt app, libsox must also be compiled for 64-bit—mismatches will cause linking failures.

4. Verify the library contains the required symbol

To confirm that sox_open_read exists in your libsox library, use the nm command (Linux/macOS) or a similar tool on Windows:

nm -D libsox.so | grep sox_open_read

If you see output with the symbol name, that means the library has the function; if not, you’ll need to recompile libsox correctly.

Once you’ve made these changes, clean your Qt project (Build > Clean All), then rebuild it. The linker should now find the libsox library and resolve the sox_open_read reference.

内容的提问来源于stack exchange,提问作者S At

相关产品推荐
方舟 Agent Plan

超全模态模型 × Harness 升级,最新支持 Deepseek-V4.1-Flash、GLM-5.3 系列、Doubao-Seedream-5.0-pro、Kimi-K3 (部分), 限时 9.9 元起

最近更新时间:2026.04.29 13:29:10