October 22, 2024
Chicago 12, Melborne City, USA
C++

Undefined reference to `_function_name` when linking in WSL


I am trying to link multiple object files using ld in Ubuntu WSL, but I am encountering an undefined reference to `write_port' error. The function is defined in asm file as function_name in my code, but the linker seems to be looking for _function_name.
This setup works fine in my Ubuntu VM. This error is only appearing for functions defined in an asm file assembled with nasm.

I was expecting the compilation process in WSL to work normally, similar to how it did in my Ubuntu VM. Initially, I attempted to build the project directly in Windows, but since Windows cannot build ELF files, I switched to using WSL.

I verified that function_name is declared properly in the header file and defined in the source file.
I then tried to install the same version of ld that was installed in my VM within WSL, but I was unable to install that specific version. I also tried renaming the functions in the asm file to _function_name without the leading underscore but the error became undefined reference to `function_name'



You need to sign in to view this answers

Leave feedback about this

  • Quality
  • Price
  • Service

PROS

+
Add Field

CONS

+
Add Field
Choose Image
Choose Video