Page 1 of 1

Some trouble adapting Meaty Skeleton to an existing project

Posted: Wed Apr 11, 2018 5:21 am
by LazyKitty
Hi,

As the title states, I'm having some trouble adapting the Meaty Skeleton tutorial to my existing project.

Specifically, my problem comes with the libk, when it tries to call a function from the main kernel project (in this case, my equivalent of terminal_write()).
When linking, it says there's an undefined reference to that function, even though I have included the header.

I'm only getting this issue when I try to call the libk function (putchar) from the kernel itself (or libk functions that rely on it), though just including the header (stdio.h) without calling the function gives no issues.
Other functions in libk, which don't call anything from the kernel project (such as strlen) work fine.

Can anyone help me understand why I'm having this problem and maybe how I can solve it?

Re: Some trouble adapting Meaty Skeleton to an existing proj

Posted: Wed Apr 11, 2018 11:24 am
by simeonz
I would suggest that you check whether you have that symbol defined in your kernel .o file with nm (or, objdump --syms, readelf -s, etc.). I suspect that you don't actually have it, or if you use C++, it may be a mangling issue (and then you need to use extern "C".)

The fact that you experience the issue only when you use an i/o routine from the library is normal. Libraries are object file packages/archives, such that any object file inside the library is only included by the linker when something inside it is actually used. The library probably has separate object file for the i/o routines inside it which carries the symbol dependency that your kernel fails to satisfy. You can view the contents of the library archive and the symbols in it with the nm command, or use the ar command to view the object file contents, extract individual object files (for testing purposes), etc.

Btw, header files have no play in this. They are entirely a compiler concern, and if your compilation is successful, they are irrelevant. (Well, generally speaking.)

Re: Some trouble adapting Meaty Skeleton to an existing proj

Posted: Wed Apr 11, 2018 12:42 pm
by LazyKitty
Adding extern "C" to my equivalent of terminal_write() solved my problem.

Thanks. I definitely hadn't thought of that.