Undefined Reference to hal_export_funct Linker Error in LinuxCNC HAL Component

More
05 Oct 2025 06:02 #335840 by takgu
Hello,I am encountering a persistent linker error while building a HAL component for LinuxCNC, despite correctly identifying the location of the required function. I would appreciate any assistance from members who have experience using
hal_export_funct
. 1. The Problem I am trying to link my component, but the build fails with an "undefined reference" error for a HAL API function. 2. The Setup and Findings ItemDetailsInitial Linker Option
-L/lib -llinuxcnchal
Error Message
undefined reference to hal_export_funct
Source of ErrorI confirmed that the function
hal_export_funct
is not defined in
liblinuxcnchal.so
.Function LocationI found that
hal_export_funct
is defined in the real-time library:
/rtlib/hal_lib.so
.Attempted FixI updated the linker options in my build system (a
.pro
file using qmake) to include both libraries:
-L/lib -llinuxcnchal
and
-L/rtlib -lhal_lib
.Resulting ErrorThe linker now reports that it cannot find the
-lhal_lib
library.
Sheets로 내보내기 3. The Core Issue The linker path to the directory (
/rtlib
) is accurate, and the library file (
hal_lib.so
) containing the function is confirmed to exist there. However, the build system or linker seems unable to successfully link
-lhal_lib
.Could this issue be related to:
  1. A specific linker flag order required for real-time libraries?
  2. A misunderstanding of how the HAL and RTAPI libraries should be linked together (especially since
    hal_init
    is present in both
    liblinuxcnchal.so
    and
    hal_lib.so
    )?
  3. An incorrect way to specify the library name (
    -l
    ) when using an absolute path or a custom library path (
    -L
    ) in the build system?
Any guidance on how to correctly force the linker to recognize and use
hal_lib.so
for
hal_export_funct
would be greatly appreciated.Thank you.

Please Log in or Create an account to join the conversation.

More
05 Oct 2025 06:16 #335842 by unknown
Is there any reason you can not use halcompile to build your component. As that is the "traditional" way to build components outside of the build process.

Please Log in or Create an account to join the conversation.

More
05 Oct 2025 06:41 #335843 by takgu
I am currently building a CNC control application using Qt C++ to control servo motors via EtherCAT.

I am encountering errors while attempting to execute the following HAL functions within my Qt code: hal_init, hal_ready, hal_export_funct, and hal_link.

Additionally, when I use the halcmd utility to add components or functions, I am unable to use (access) those resulting HAL pins/fields within my Qt C++ application.

Thank you.

Please Log in or Create an account to join the conversation.

More
05 Oct 2025 08:21 - 05 Oct 2025 08:22 #335848 by Hakan
The libs are not actually in /lib and /rtlib are they?
Last edit: 05 Oct 2025 08:22 by Hakan.

Please Log in or Create an account to join the conversation.

More
05 Oct 2025 08:34 #335850 by takgu
/lib/linuxcnchal.so
- hal_export_funct - not exist

/rtlib/hal_lib.so
- hal_export_funct - exist

LIBS += -L$$LINUXCNC_HOME/lib -llinuxcnchal
LIBS += -L$$LINUXCNC_HOME/rtlib -lhal_lib

** Link Error when building qt app ('Not found -lhal_lib')

Thanks

Please Log in or Create an account to join the conversation.

More
05 Oct 2025 08:38 #335851 by unknown
Is there any reason you're not using something such as linuxcnc.org/docs/2.9/html/gui/qtvcp.html

Please Log in or Create an account to join the conversation.

More
05 Oct 2025 08:52 #335852 by takgu
The reason I am using Qt C++ is that the existing external module, which was developed in C++, is incompatible with Qt Python (QtPy).

Thanks.

Please Log in or Create an account to join the conversation.

More
05 Oct 2025 09:09 #335854 by Hakan
LINUXCNC_HOME then, what is its value?

Please Log in or Create an account to join the conversation.

  • rodw
  • rodw's Avatar
  • Away
  • Platinum Member
  • Platinum Member
More
05 Oct 2025 09:21 #335855 by rodw
A bit left field but how did you install linuxcnc? If installed on Trixie and not the LinuxCNC ISO, did you
sudo apt install linuxcnc-uspace-dev
I think this is needed to get the required libs (certainly for halcompile)
The ISO installs linuxcnc-uspace-dev

Please Log in or Create an account to join the conversation.

More
05 Oct 2025 09:23 #335856 by takgu
LINUXCNC_HOME : /home/user1/linuxcnc

The Qt application now works correctly when I comment out the following two lines in the build configuration:

- LIBS += -L/home/user1/linuxcnc/rtlib -lhal_lib

- hal_export_funct.

Thanks

Please Log in or Create an account to join the conversation.

Time to create page: 0.084 seconds
Powered by Kunena Forum