开发者

"Undefined Symbol _memset"

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 开发者_如何学Go-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!


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.


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


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.

0

上一篇:

下一篇:

精彩评论

暂无评论...
验证码 换一张
取 消

最新问答

问答排行榜