How can I use runtime library without hardcoding it
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.
Even compiling with /MT does not work.
Re: How can I use runtime library without hardcoding it
Are you including the appropriate .lib file in the list of files to link?
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 ?
Re: How can I use runtime library without hardcoding it
atoi is implemented in libucrt.lib for static linking.
Re: How can I use runtime library without hardcoding it
Thank you, now itoa works but I'm a little bit worried about this :
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: Select all
libucrt.lib
kernel32.lib(KERNEL32.dll) : warning LNK4237: /SUBSYSTEM:NATIVE specified when importing from 'KERNEL32.DLL'; Use /SUBSYSTEM:CONSOLE or /SUBSYSTEM:WINDOWS.
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: Select all
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
-
- Member
- Posts: 5562
- Joined: Mon Mar 25, 2013 7:01 pm
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.
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!
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!
Last edited by devc1 on Fri Mar 24, 2023 2:29 pm, edited 1 time in total.
-
- Member
- Posts: 5562
- Joined: Mon Mar 25, 2013 7:01 pm
Re: How can I use runtime library without hardcoding it
Pay attention to the license. If you copy GPL code, your kernel must be released under the GPL.devc1 wrote:I'll be copying some functions from Linux
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.