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

如何在Java中使用PJSIP/PJNATH?STUN编译报错求助

Fixing Undefined Symbols When Compiling PJNATH STUN Shared Library for JNA

Hey there, fellow PJSIP newbie! Let's break down why you're seeing those undefined symbol errors and how to fix them.

The Root Cause

Your compile command only builds stun_msg.c, but STUN message functions in PJNATH depend on PJLIB (the core PJSIP utility library where pj_pool_calloc and other pool management functions live) and other internal PJNATH modules. You're not linking against these required libraries, so the linker can't locate the definitions for those missing symbols.

Step-by-Step Fix

  1. Ensure PJLIB and PJNATH are fully compiled first
    Before building your custom STUN library, make sure you've completed compiling the full PJSIP/PJNATH source tree. This will generate the shared libraries (like libpj.so, libpjnath.so, libpjlib-util.so) that your code needs to link against.

  2. Update your compile command to include required libraries
    Modify your gcc command to add:

    • -L/path/to/pj/libraries: Replace this with the actual path where your compiled PJ shared libraries are stored (e.g., /usr/local/lib or the lib directory in your PJSIP build folder).
    • Link flags for mandatory PJ libraries: -lpj (PJLIB core), -lpjnath (PJNATH core), -lpjlib-util (utility functions often used with STUN).

    Here's a corrected example command:

    gcc -Wall -g -shared -o lib_stun_msg.so -fPIC stun_msg.c -Wl,-z,defs -L/usr/local/lib -lpj -lpjnath -lpjlib-util
    
  3. Add header path if needed
    If the compiler can't find PJ header files (like pj/pool.h), add the -I/path/to/pj/include flag to point to the directory containing PJ's header files:

    gcc -Wall -g -shared -o lib_stun_msg.so -fPIC stun_msg.c -Wl,-z,defs -I/usr/local/include -L/usr/local/lib -lpj -lpjnath -lpjlib-util
    

Extra Tips

  • If you built PJ libraries as static libraries instead of shared ones, replace -lpj etc. with the full path to the .a files (e.g., /usr/local/lib/libpj.a).
  • Double-check that your build configuration (debug/release, 32/64-bit) matches between the PJ libraries and your custom STUN library—mismatches can cause unexpected linking errors.

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

相关产品推荐
方舟 Agent Plan

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

最近更新时间:2026.05.21 04:13:27