OSDev.org https://forum.osdev.org/ |
|
How can I use runtime library without hardcoding it https://forum.osdev.org/viewtopic.php?f=1&t=56797 |
Page 1 of 1 |
Author: | devc1 [ Fri Mar 24, 2023 6:26 am ] |
Post subject: | How can I use runtime library without hardcoding it |
I want to use the C Runtime Library functions in my kernel for some purposes like converting integers to text and vice versa. I'm using MSVC CL, I run vcvars64.bat and when I call for example _itoa() it gives unresolved external error. Even compiling with /MT does not work. |
Author: | iansjack [ Fri Mar 24, 2023 6:51 am ] |
Post subject: | Re: How can I use runtime library without hardcoding it |
Are you including the appropriate .lib file in the list of files to link? |
Author: | devc1 [ Fri Mar 24, 2023 7:07 am ] |
Post subject: | Re: How can I use runtime library without hardcoding it |
I'm not including anything, and talking about .lib files is there any static cruntime lib which I can include ? |
Author: | iansjack [ Fri Mar 24, 2023 7:18 am ] |
Post subject: | Re: How can I use runtime library without hardcoding it |
atoi is implemented in libucrt.lib for static linking. |
Author: | devc1 [ Fri Mar 24, 2023 12:32 pm ] |
Post subject: | Re: How can I use runtime library without hardcoding it |
Thank you, now itoa works but I'm a little bit worried about this : Code: libucrt.lib kernel32.lib(KERNEL32.dll) : warning LNK4237: /SUBSYSTEM:NATIVE specified when importing from 'KERNEL32.DLL'; Use /SUBSYSTEM:CONSOLE or /SUBSYSTEM:WINDOWS. libucrt includes kernel32.dll, It's fine because I'm not using any windows related function but at the same time I'll be linking my kernel to some dlls in the future (for e.g. the driver development kit or Graphics API), so the time I'll add DLL importing to my bootloader the bootloader will likely fail because it cannot find kernel32.dll. This is the related document : https://learn.microsoft.com/en-us/cpp/e ... w=msvc-170 On top of that I may be naming some functions a similar name to windows one's here are the exported functions : Code: Section contains the following imports:
KERNEL32.dll FFFF80000000B000 Import Address Table FFFF8000000138C0 Import Name Table 0 time date stamp 0 Index of first forwarder reference 4F5 RtlCaptureContext 4FD RtlLookupFunctionEntry 504 RtlVirtualUnwind 3A0 IsDebuggerPresent 5E6 UnhandledExceptionFilter 5A4 SetUnhandledExceptionFilter 27D GetLastError 564 SetLastError 232 GetCurrentProcess 5C4 TerminateProcess 3A8 IsProcessorFeaturePresent 178 ExitProcess 1C5 FreeLibrary 295 GetModuleHandleW 294 GetModuleHandleExW 2CD GetProcAddress 36C HeapAlloc 370 HeapFree 149 EnterCriticalSection 3E0 LeaveCriticalSection 123 DeleteCriticalSection 1B6 FlsGetValue 1B7 FlsSetValue 386 InitializeCriticalSectionAndSpinCount 3E6 LoadLibraryExW 3D4 LCMapStringW 3AE IsValidCodePage 1CC GetACP 2B6 GetOEMCP 1DB GetCPInfo 2F8 GetStringTypeW 412 MultiByteToWideChar 637 WideCharToMultiByte DA CreateFileW 503 RtlUnwindEx 145 EncodePointer 487 RaiseException 5D8 TlsGetValue 5D9 TlsSetValue 4FF RtlPcToFileHeader 555 SetFilePointerEx 57F SetStdHandle 1B9 FlushFileBuffers 64B WriteFile 21A GetConsoleOutputCP 216 GetConsoleMode 94 CloseHandle 64A WriteConsoleW |
Author: | Octocontrabass [ Fri Mar 24, 2023 1:07 pm ] |
Post subject: | Re: How can I use runtime library without hardcoding it |
C runtime libraries are designed to be used in hosted environments. In a freestanding environment like an OS kernel, you will need to either find a library designed to be used in a freestanding environment or write the necessary functions yourself. |
Author: | devc1 [ Fri Mar 24, 2023 2:23 pm ] |
Post subject: | Re: How can I use runtime library without hardcoding it |
Ok So I think that I'm going to write the library by myself and I'll be copying some functions from Linux to speed up the coding process. I will make a separate c runtime library (cruntime.dll) and a whole nos runtime library (nosrt.dll) for user mode programs. If you have better name suggestion let me know and thanks! |
Author: | Octocontrabass [ Fri Mar 24, 2023 2:28 pm ] |
Post subject: | Re: How can I use runtime library without hardcoding it |
devc1 wrote: I'll be copying some functions from Linux Pay attention to the license. If you copy GPL code, your kernel must be released under the GPL. |
Author: | devc1 [ Fri Mar 24, 2023 2:31 pm ] |
Post subject: | Re: How can I use runtime library without hardcoding it |
Then I will just proceed and use existing functions from my previous OS, It has most of the functions that I need. |
Page 1 of 1 | All times are UTC - 6 hours |
Powered by phpBB © 2000, 2002, 2005, 2007 phpBB Group http://www.phpbb.com/ |