2

I asked a similar question, but I have some update which is really confusing me. Essentially, I want to link a number of object files with the linker as follows:

/usr/ccs/bin/ld -o q -e start_master -dn -z defs -M ../../../mapfile.q {list of object files}

I get the following error:

Undefined                       first referenced 
 symbol                             in file
_memset                             reconf.o

The interesting things is, that memset is not referenced in reconf.c and I also grep'ed the whole directory but there is also no reference in any of the other files to _memset. Therefore I am wondering why I get this error message from the linker, although nowhere in my source code _memset is actually used. Anyone an idea what could be going on here?

Thanks so much, this error is driving us mental!

EDIT:

I tried to add the path to the library of memset and linked it with -lc and run it in verbose mode:

/usr/ccs/bin/ld -o q -e start_master -dn -z defs -z verbose -L/usr/lib -M ../../../mapfile.q {list of object files} -lc

Then I get the following error: ld: fatal: library -lc: not found ld: fatal: File processing errors. No output written to q

And this although libc.so is clearly in /usr/lib ...

Confusing

EDIT II:

Doing some more research it seems that on Solaris 10 static linking disappeard as you can read here:

http://blogs.oracle.com/rie/entry/static_linking_where_did_it

Probably this is my problem. Has anyone an idea how I could rewrite my linker command for a workaround to this problem?

Many thanks!

Mike
  • 71
  • 1
  • 3
  • 3
    Use `gcc` (or perhaps `cc` in your case) rather than trying to drive `ld` directly. – Paul R Aug 10 '11 at 10:36
  • Unfortunately, this gives me the following error: segment address or length `v0xfff0000000' exceeds internal limit – Mike Aug 10 '11 at 10:58
  • If you're linking multiple `.o` files to make a new `.o` file, undefined symbols are not supposed to be an error. It sounds to me like `ld` is trying to make an executable... – R.. GitHub STOP HELPING ICE Aug 10 '11 at 14:09

3 Answers3

3

Probably you did:

struct S v = { 0 };

or

struct S v;
v = (some const-variable).

or

uint8_t b[100] = { 0 };

.

Some compilers are putting implicitly the built-in memset (or memcpy) for such things. The built-in memset then is called _memset (in your case). Once you link and your libc (or what provides standard-function in your case) does not providie it, you are getting this link error.

Patrick B.
  • 11,773
  • 8
  • 58
  • 101
  • 5
    This doesn't really answer the question - the OP wants to know how to fix the error, i.e. what specific additional library needs to be linked. – Paul R Aug 10 '11 at 10:40
  • 1
    I answered to: "Anyone an idea what could be going on here?" – Patrick B. Aug 11 '11 at 11:19
1

Assuming you're on Solaris, you'll find memset in the libc.so library :

/usr/lib-> nm libc.so | grep memset
[7122]  |    201876|     104|FUNC |GLOB |0    |9      |_memset

Simply add -lc to the command line

gastush
  • 1,026
  • 7
  • 18
  • Thanks for your answer, the libc.so seems to be on the system, so when running your command I obtain 000310d4 T _memset. I tried to feed the -lc flag to the linker, but the result is a bit "surprising": ld: fatal: library -lc: not found – Mike Aug 10 '11 at 11:01
  • You also have to tell it where to find it. Add `-L/usr/lib` to the linker options – gastush Aug 10 '11 at 11:47
  • Added this to the command line, the error remains the same. It is really confusing what is happening here... – Mike Aug 10 '11 at 12:32
  • @Mike Could you update your question with the exact command line you're using now? – Matt Gibson Aug 11 '11 at 09:47
  • Hi Matt, just updated my question with the exact command line that I am currently using. Hope that helps a bit ... – Mike Aug 11 '11 at 10:19
0

Memset is a library function from standard C library. If you don't use gcc for linking (which links your files with standard libraries by default) you should explicitly link your progrom with libc.

On the other option, probably you don't use libc. In this case memset call could be generated by gcc.

From man gcc:

-nodefaultlibs

Do not use the standard system libraries when linking. Only the libraries you specify will be passed to the linker, options specifying linkage of the system libraries, such as -static-libgcc or -shared-libgcc, will be ignored. The standard startup files are used normally, unless -nostartfiles is used. The compiler may generate calls to memcmp, memset, memcpy and memmove. These entries are usually resolved by entries in libc. These entry points should be supplied through some other mechanism when this option is specified.

In this case simply write memset (it's trivial proc.) and supply it to linker.

Shawn Chin
  • 84,080
  • 19
  • 162
  • 191
Yury
  • 3,000
  • 2
  • 24
  • 24