Search code examples
header-filesld

gnu ld says undefined reference to `xxx(arg1, arg2)' in program with external hpp header


just to make my kernel source code smaller, i spilt it into multiple headers.

(important, they are hpp headers, not h headers. so extern "C" {#include <that_stuff.hpp>} didn't do anything.)

while linking, gnu ld says "undefined reference to `xxx(arg1, arg2)'"

(the function "xxx(arg1, arg2)" is in the header)

how to fix?


Solution

  • your description seems, that you don't compile your .cc file with extern "C" { }; - did you try a re-compile? you can try to add the prefix extern "C" void xxx(int arg1, int arg2); in your header file. If this don't work, make the same in your source file: extern "C" void xxx(int arg1, int arg2) { / code / }

    C .o file linkage does not show arguments for functions, only the name - commonly. It can be changed, but in my knowing it is so like I write it.