I'm trying to wrap elements of this ascii-art repo. I'm using g++ 9.3.0 cpp-17
on ubuntu 20.04. Here's a Tree overview of the dirs -
├── build
├── in
│ ├── js.bmp
│ ├── socrates.bmp
│ └── woman.bmp
├── LICENSE
├── makefile
├── out
│ ├── js.txt
│ ├── socrates.txt
│ └── woman.txt
├── README.md
├── results
│ ├── js.png
│ ├── socrates.png
│ └── woman.png
└── src
├── headers
│ ├── bmp_body.h
│ ├── bmp_header.h
│ ├── bmp_image.h
│ ├── bmp_process.h
│ └── bmp_reader.h
├── lib
│ ├── bmp_body.cpp
│ ├── bmp_header.cpp
│ ├── bmp_image.cpp
│ ├── bmp_process.cpp
│ └── bmp_reader.cpp
└── main.cpp
Following my intuition, compiling solely src/main.cpp
, namely g++ -Wall src/main.cpp
results in undefined reference errors.
/usr/bin/ld: /tmp/ccTouLyj.o: in function `main':
main.cpp:(.text+0x12f): undefined reference to `new_bmp_image()'
/usr/bin/ld: main.cpp:(.text+0x162): undefined reference to `bmp_read_header(std::__cxx11::basic_string<char, std::char_traits<char>, std::allocator<char> >, unsigned char*)'
/usr/bin/ld: main.cpp:(.text+0x1aa): undefined reference to `delete_bmp_image(bmp_image*)'
/usr/bin/ld: main.cpp:(.text+0x262): undefined reference to `bmp_read_body(std::__cxx11::basic_string<char, std::char_traits<char>, std::allocator<char> >, int, int, int, int, int)'
/usr/bin/ld: main.cpp:(.text+0x288): undefined reference to `bmp_to_ascii(bmp_image*)'
/usr/bin/ld: main.cpp:(.text+0x297): undefined reference to `delete_bmp_image(bmp_image*)'
collect2: error: ld returned 1 exit status
compiling every file under src
, namely main.cpp
and lib/*.cpp
, results in success.
Namely the command, g++ -Wall src/main.cpp src/lib/*.cpp
results a successful complilation.
This might be obvious for experienced c++ programmers, but I'm confused as to what's Really going on. I want to understand why and why not, it did what it did. Although I can barely intuitively understand what's going on, a little more elaboration on this would be awesome :)