When I go and make a C++ application I generally use libraries like SDL or wxWidgets and so on. But if I were to make a library would I need to use a library to make a library? Or can I make the entire library out of core C++ code, is this even possible?
Yes.
My point is there must be a point were a library has nothing to base itself on and so the only things it can use are core C++.
No.
C & C++ are examples of third-generation languages. As such they attempt to hide many system-wise implementation details. Underlying the third-generation programming language (3GL) layer is a second-generation programming language (2GL) such as x86 assembly; below this we have machine code instructions.
As has already been pointed out by josefx, you can indeed implement a C++ library in pure C++. However, system libraries (especially those for controlling devices) can be and often are written in assembler. And in general, a library could also be written in COBOL or Fortran or even Brainfuck.
It's the assembler/compiler/linker processes that actually convert 2GL/3GL
codes into a library
that can be linked to in C++.
Here is a small example of a C program, blah.c
, that links to no standard runtime libraries, but it still manages to print stuff out using a function in a *proprietary library, libfoo.a,
written in x86 assembler
:
blah.c:
/*-----------------------------------------------
blah.c
Invokes some assembly
------------------------------------------------*/
void _start()
{
char sz[]={"oOoook\n"};
foo(sz,sizeof(sz));
byebye();
}
foo.asm:
;----------------------------------------------------------------------------
;Some foo assembly: exposes system write & exit
;----------------------------------------------------------------------------
SECTION .text
global foo
global byebye
foo:
push ebp
mov ebp,esp
mov edx, [ebp+12]
mov ecx, [ebp+8]
mov ebx,1
mov eax,4 ;syscall for __NR_write
int 0x80 ;service interrupt
mov esp,ebp
pop ebp
mov eax,0
ret
byebye:
mov ebx,0
mov eax,1 ;syscall for __NR_exit
int 0x80 ;service interrupt
ret
And here's how it's built:
$ nasm -felf -ofoo.o foo.asm
$ ar rs libfoo.a foo.o
$ gcc -L. -oblah blah.c -lfoo -nostartfiles -nostdlib -nodefaultlibs
$ ./blah
oOoook
$
As can be seen, the library makes use of system calls (in this case to the linux
kernel); which incidentally, may also be implemented by third-parties.