“Undefined Symbol _memset”

感情迁移 提交于 2019-12-02 00:47:55

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

Yury

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.

易学教程内所有资源均来自网络或用户发布的内容,如有违反法律规定的内容欢迎反馈
该文章没有解决你所遇到的问题?点击提问,说说你的问题,让更多的人一起探讨吧!