Undefined references in Libc?

Topics for the Eclipse Environment
acreque
Posts: 16
Joined: Sun Aug 22, 2010 8:13 am
Location: Cleveland, OH

Undefined references in Libc?

Post by acreque »

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.
rnixon
Posts: 833
Joined: Thu Apr 24, 2008 3:59 pm

Re: Undefined references in Libc?

Post by rnixon »

What platform and tools rev are you using?
How are you able to change things at such a low level, g++ instead of gcc?
acreque
Posts: 16
Joined: Sun Aug 22, 2010 8:13 am
Location: Cleveland, OH

Re: Undefined references in Libc?

Post by acreque »

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.
User avatar
tod
Posts: 587
Joined: Sat Apr 26, 2008 8:27 am
Location: Southern California
Contact:

Re: Undefined references in Libc?

Post by tod »

I'm just guessing but it sounds like it might be a name mangling problem.
  1. Are you familiar with extern "C"{ c forward refs, methods or includes can go inside the block}?
  2. Have you used it to wrap C functions and non-system include headers?
rnixon
Posts: 833
Joined: Thu Apr 24, 2008 3:59 pm

Re: Undefined references in Libc?

Post by rnixon »

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++.
acreque
Posts: 16
Joined: Sun Aug 22, 2010 8:13 am
Location: Cleveland, OH

Re: Undefined references in Libc?

Post by acreque »

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?).
acreque
Posts: 16
Joined: Sun Aug 22, 2010 8:13 am
Location: Cleveland, OH

Re: Undefined references in Libc?

Post by acreque »

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.
rnixon
Posts: 833
Joined: Thu Apr 24, 2008 3:59 pm

Re: Undefined references in Libc?

Post by rnixon »

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.
User avatar
tod
Posts: 587
Joined: Sat Apr 26, 2008 8:27 am
Location: Southern California
Contact:

Re: Undefined references in Libc?

Post by tod »

If you're not using WiFi you should be able to remove the reference to the rtl8711 library.
acreque
Posts: 16
Joined: Sun Aug 22, 2010 8:13 am
Location: Cleveland, OH

Re: Undefined references in Libc?

Post by acreque »

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.
Post Reply