Jump to content
  • Advertisement

Archived

This topic is now archived and is closed to further replies.

DarkEmpire

my own memory static library problems

This topic is 5931 days old which is more than the 365 day threshold we allow for new replies. Please post a new topic.

If you intended to correct an error in the post then please contact us.

Recommended Posts

Hi, I want to implement my own version of FillMemory and memset functions in a static library memory.lib... Using VC6, i create a new project, choose static library and add a memory.cpp file containing my own versions... But how can i use this library ? I created a testLib project, and add memory.lib in the project->setting->link->library module. and modify the lib path to use memory.lib To use my library, i choosed "no default lib", to avoid using libc.lib Here is the link error when i try to build my test: "unresolved external symbol _memset Release/TestLib.exe : fatal error LNK1120: 1 unresolved externals" Here is the code i use in my testlib: { char testChar[50]; FillMemory(&testChar, 0, sizeof(testChar)); //memset(&testChar, 0, sizeof(testChar)); return 0; } The error link message is the same if i uncomment the line with memset and comment FillMemory line. What is the problem ?

Share this post


Link to post
Share on other sites
Advertisement
The CRT version of memset is defined as

extern "C" {
void * __cdecl memset(void *, int, size_t);
}

extern "C" turns off C++ name mangling. However, when you define your memset function, you aren''t using extern "C" and therefore your memset''s name is mangled. Define your memset like so:

extern "C" void * __cdecl memset(void *dest, int c, size_t count)
{
...
}

and that should fix the problem.

Share this post


Link to post
Share on other sites
Are you including a custom header, or the standard ones? If you are including the standard ones (which you might not want to do here), then you have to declare your functions extern "C", because that's how they're declared in the standard headers.

You can still link with the standard libraries, just make sure that the linker finds your memory.lib before the crt library.

[EDIT: Ahh, well, IndirectX beat me to it...]

[edited by - Dactylos on June 30, 2002 12:25:49 PM]

Share this post


Link to post
Share on other sites
Thanks a lot...

i rename memset function with your advices, and all is ok.

Thanks a lot...

But FillMemory is a win32 function, isn''t it ? So why, memset must be defined to use FillMemory ? Is there a link (dependancies) with libc.lib ?

If FillMemory is not a win32 function? If not, is there a win32 equivalent function ?

Thanks

NB: If i want these informations, it is because i don''t wnt to use libc.lib functions (C runtime)...

Share this post


Link to post
Share on other sites
quote:
Original post by DarkEmpire
But FillMemory is a win32 function, isn''t it ? So why, memset must be defined to use FillMemory ? Is there a link (dependancies) with libc.lib ?

If FillMemory is not a win32 function? If not, is there a win32 equivalent function ?


FillMemory isn''t really a function. It is a macro that expands to either RtlFillMemory, which is a function exported from ntdll.dll, or memset which is a function exported from msvcrt.dll. Which expansion is chosen depends on your project settings.

Share this post


Link to post
Share on other sites
There's RtlFillMemory, but you usually don't get to play with it. You probably can find your way around winnt.h, though.

Or, you may need to install DDK to get ntdll.lib.


[edited by - IndirectX on July 1, 2002 3:10:41 AM]

Share this post


Link to post
Share on other sites

  • Advertisement
×

Important Information

By using GameDev.net, you agree to our community Guidelines, Terms of Use, and Privacy Policy.

We are the game development community.

Whether you are an indie, hobbyist, AAA developer, or just trying to learn, GameDev.net is the place for you to learn, share, and connect with the games industry. Learn more About Us or sign up!

Sign me up!