[Solved] “undefined reference to `memset’” bug
“undefined reference to `memset'” bug
I have the following code:
It’s fairly self-explanatory: lib.c is built as a static library, main.c is built as part of the executable, and build.bat simply builds everything. When I run build.bat, I get an “undefined reference to `memset'” error. Should be reproducible on your end. I built it with 8.30.0 and 4.8.4 and got the error. Note that if you change ‘#if 0’ to ‘#if 1’, you don’t get the warning. Also, if you build the exe using gcc instead of ld, you don’t get the error.
Best answer
Hello,
This is not a bug in the toolchain: it is the intended behavior. Even the native gcc is having the same behavior.
The reason is that the linker, on it’s own, does not know where to look for the default libraries: (libc, libgcc). The user himself must specify their location by using the -L option and by also linking the libraries.
This is made obvious if you are looking at any output produced by the compilation with the gcc driver and the -v option enabled. That is the reason that we suggested using the driver itself and not just simply the linker.
If you are still wanting to use the linker, we recommend modifying the linking command as follows:
rx-elf-ld main.o lib.a
-L"<install_path>\GCCforRenesasRX4.8.4.201803-GNURX-ELF\
rx-elf\rx-elf\rx-elf\lib" -lc -o main.out
where <install_path> is the folder in which the toolchain itself is installed.
__
Best regards,
The GNU Tools Team
Hello,
Thank you for reaching out to us.
We managed to reproduce the issue and we recommend using gcc to link as opposed to the linker (ld). By linking only with ld, there are some additional flags missing from your linking command (e.g. -I and -L for include path and library paths, respectively). The gcc driver knows not only to link objects, but also to link together certain objects and libraries that are used to set up the startup code for the executable.
Please let us know if we can be of further assistance.
Best regards,
The GNU Tools Team