You could read The Dragon Book
] and then set out to write your own compiler from scratch if you have a year or five to spare or you could join a project like LLVM/Clang and learn by contributing to a compiler in development.
Assuming you're compiling C++ the minimal basic components you'll need are:-
A File System interface to read and write source, intermediate and executable files. The Binutils Linux package contains the Binary File Descriptor library for this purpose, It's very good.
A C preprocessor like Boost::Wave
A Lexer and Parser for C++ ( This is considered a hard part and what you'd need to read and understand the Dragon book and several more in order to write )
A Code generator to take an Abstract Sytax Tree and generate IL or some form of assembly
language for the target processor.
An assembler to turn that IL or ASM into executable code.
A Linker to link together the ouputs of compilation units to form executable modules.
Writing any one of these would be a major achievement. Good Luck.