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

在Ubuntu 14.04编译Erlang代码时遭遇type ref() undefined错误求助

Fixing the type ref() undefined Error When Compiling Erlang on Ubuntu 14.04

Hey there, let's work through this type ref() undefined error you're facing while compiling Erlang code on Ubuntu 14.04. I’ve dealt with similar headaches before, so here are the most likely causes and fixes to try out:

  • Outdated Erlang/OTP Version
    Ubuntu 14.04 ships with a pretty old Erlang version (usually OTP 17.x or earlier). The ref() built-in type wasn’t globally available in these older releases—you needed to explicitly import its definition.

    • Fix: First check your Erlang version with erl -version. If it’s older than OTP 18, you can either:
      1. Upgrade to a newer stable OTP release using tools like kerl or asdf (since Ubuntu 14.04’s default repos don’t have newer versions), or
      2. Add -include_lib("kernel/include/erlang.hrl"). at the top of any module that uses ref()—this pulls in the correct type definition from the kernel library.
  • Missing or Misplaced Header Files
    If your code uses ref() but doesn’t include the header that defines it, the compiler won’t recognize the type. Sometimes custom header files might depend on ref() but fail to import the required include.

    • Fix: Audit all .hrl files in your project to ensure any file using ref() includes -include_lib("kernel/include/erlang.hrl"). or the appropriate custom header. When compiling, use erl -I ./include (adjust the path to your include directory) to make sure the compiler can find all necessary headers.
  • Type Definition Conflicts or Typos
    It’s easy to accidentally define a custom ref() type in your code that clashes with the built-in one, or misspell the type (like refs() instead of ref()). Either case will make the compiler unable to locate the correct built-in type.

    • Fix: Search your codebase for any -type ref() :: ... declarations—if you find one, rename your custom type or explicitly use erlang:ref() to reference the built-in type everywhere. Double-check all instances of the type for spelling errors too.
  • Corrupted Compilation Environment
    In rare cases, your Erlang installation on Ubuntu 14.04 might be corrupted, leading to missing or unreadable header files.

    • Fix: If you installed Erlang via apt, try reinstalling it with:
      sudo apt-get purge erlang*
      sudo apt-get update && sudo apt-get install erlang
      

    If that doesn’t work, use kerl to compile a fresh, standalone Erlang version—this avoids any system-level corruption issues.

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

相关产品推荐
方舟 Agent Plan

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

最近更新时间:2026.05.28 09:25:25