Undefined references in Libc?
Undefined references in Libc?
Is it possible I've got the wrong version of libc.a? The default linker in NBEclipse generates the following errors on my code:
C:\nburn\gcc-m68k\m68k-elf\lib\m5206e\libc.a(lib_a-system.o): In function `_system_r':
system.c:(.text+0xe): undefined reference to `_system'
C:\nburn\gcc-m68k\m68k-elf\lib\m5206e\libc.a(lib_a-times.o): In function `_times_r':
times.c:(.text+0xe): undefined reference to `times'
C:\nburn\gcc-m68k\m68k-elf\lib\m5206e\libc.a(lib_a-unlinkr.o): In function `_unlink_r':
unlinkr.c:(.text+0x10): undefined reference to `unlink'
collect2: ld returned 1 exit status
I've tried using g++ rather than gcc for compile & link, but the error remains.
C:\nburn\gcc-m68k\m68k-elf\lib\m5206e\libc.a(lib_a-system.o): In function `_system_r':
system.c:(.text+0xe): undefined reference to `_system'
C:\nburn\gcc-m68k\m68k-elf\lib\m5206e\libc.a(lib_a-times.o): In function `_times_r':
times.c:(.text+0xe): undefined reference to `times'
C:\nburn\gcc-m68k\m68k-elf\lib\m5206e\libc.a(lib_a-unlinkr.o): In function `_unlink_r':
unlinkr.c:(.text+0x10): undefined reference to `unlink'
collect2: ld returned 1 exit status
I've tried using g++ rather than gcc for compile & link, but the error remains.
Re: Undefined references in Libc?
What platform and tools rev are you using?
How are you able to change things at such a low level, g++ instead of gcc?
How are you able to change things at such a low level, g++ instead of gcc?
Re: Undefined references in Libc?
Running NBEclipse 2.5.0 to build a MOD5272 app.
The specific compiler (or linker) can be specified via the IDE menu: Right-click on project Properties. Then {C/C++ Build}->{Settings}->{GNU C/C++ Linker}. Enter the compiler of choice in the Command text box.
I've tried both m68k-elf-g++ and m68k-elf-gcc, but get the same linker error either way.
The code for our NetBurner app is an amalgam of both C and C++. I'm trying to compile and link in the Lua source files ... that's where the trouble started.
The specific compiler (or linker) can be specified via the IDE menu: Right-click on project Properties. Then {C/C++ Build}->{Settings}->{GNU C/C++ Linker}. Enter the compiler of choice in the Command text box.
I've tried both m68k-elf-g++ and m68k-elf-gcc, but get the same linker error either way.
The code for our NetBurner app is an amalgam of both C and C++. I'm trying to compile and link in the Lua source files ... that's where the trouble started.
Re: Undefined references in Libc?
I'm just guessing but it sounds like it might be a name mangling problem.
- Are you familiar with extern "C"{ c forward refs, methods or includes can go inside the block}?
- Have you used it to wrap C functions and non-system include headers?
Re: Undefined references in Libc?
If you have .c files, you could try making them .cpp files, even if your writing straight C code. There is not advantage I can think of to use a .c file, and the name mangling problem goes away, as well as the fact some of the NetBurner functions require C++.
Re: Undefined references in Libc?
Right. I tried the extern "C" { ... } for all of the relevant files.
I also renamed all of the Lua *.c and *.h files to *.cpp and *.hpp, respectively. This was suggested by the Lua web site. I also revised the corresponding #include statements accordingly (#include lua.h -> #include lua.hpp)
Still getting the undefined reference error. How can I verify that I am using the correct version of libc (is it subsumed into ../lib/MOD5272.a?).
I also renamed all of the Lua *.c and *.h files to *.cpp and *.hpp, respectively. This was suggested by the Lua web site. I also revised the corresponding #include statements accordingly (#include lua.h -> #include lua.hpp)
Still getting the undefined reference error. How can I verify that I am using the correct version of libc (is it subsumed into ../lib/MOD5272.a?).
Re: Undefined references in Libc?
Okay, after going through the usual steps to resolve name mangling there is one linker error that refuses to go away:
c:/nburn/gcc-m68k/bin/../lib/gcc/m68k-elf/4.2.1/../../../../m68k-elf/lib/m5206e\libc.a(lib_a-unlinkr.o): In function `_unlink_r':
unlinkr.c:(.text+0x10): undefined reference to `unlink'
The libraries I'm trying to link to are (in order):
"C:\nburn\lib\NetBurner.a"
"C:\nburn\lib\MOD5272.a"
"C:\nburn\lib\rtl8711Library.a"
The offending file, unlinkr.c, appears to be some low-level libc function related to file I/O (I'm guessing). The fact that a Google search only generates about 130 hits on this spelling of the filename makes me a little suspicious.
I think there's an error in the MOD5272 library.
c:/nburn/gcc-m68k/bin/../lib/gcc/m68k-elf/4.2.1/../../../../m68k-elf/lib/m5206e\libc.a(lib_a-unlinkr.o): In function `_unlink_r':
unlinkr.c:(.text+0x10): undefined reference to `unlink'
The libraries I'm trying to link to are (in order):
"C:\nburn\lib\NetBurner.a"
"C:\nburn\lib\MOD5272.a"
"C:\nburn\lib\rtl8711Library.a"
The offending file, unlinkr.c, appears to be some low-level libc function related to file I/O (I'm guessing). The fact that a Google search only generates about 130 hits on this spelling of the filename makes me a little suspicious.
I think there's an error in the MOD5272 library.
Re: Undefined references in Libc?
Where does rtl8711Library.a come from?
My installation only has MOD5272.a and NetBurner.a.
All the lib files will be listed in \nburn\lib.
My installation only has MOD5272.a and NetBurner.a.
All the lib files will be listed in \nburn\lib.
Re: Undefined references in Libc?
If you're not using WiFi you should be able to remove the reference to the rtl8711 library.
Re: Undefined references in Libc?
Our app does not need wireless capability at this time, so the rtl8711 is out (Thanks).
For now, I can achieve error-free linkage using the following work-around in my app:
// -----------------------------------------------------------------------------
// WARNING! Bogus Code Ahead!
// -----------------------------------------------------------------------------
// The following global is defined only as a work-around for the linker error:
// c:/nburn/ ... /lib/m5206e/libc.a(lib_a-unlinkr.o): In function `_unlink_r':
// unlinkr.c:(.text+0x10): undefined reference to `unlink'
// -----------------------------------------------------------------------------
extern const int unlink = 0;
This is very bad Kung Fu of course, and I will be grateful if someone can tell me what's really going on with the unlinkr.c code.
For now, I can achieve error-free linkage using the following work-around in my app:
// -----------------------------------------------------------------------------
// WARNING! Bogus Code Ahead!
// -----------------------------------------------------------------------------
// The following global is defined only as a work-around for the linker error:
// c:/nburn/ ... /lib/m5206e/libc.a(lib_a-unlinkr.o): In function `_unlink_r':
// unlinkr.c:(.text+0x10): undefined reference to `unlink'
// -----------------------------------------------------------------------------
extern const int unlink = 0;
This is very bad Kung Fu of course, and I will be grateful if someone can tell me what's really going on with the unlinkr.c code.