I have a main.cpp file in a directory called test that has an
#include "INIReader.h"
The structure of the files is like below
---/test/main.cpp
---/inih/ini.h
ini.c
---/inih/cpp/INIReader.h
INIReader.cpp
INIReader.cpp has these includes
#include "../ini.h"
#include "INIReader.h"
I am trying to compile main.cpp in one line with
g++ -o test -Wall -I../inih/cpp main.cpp
but it is not working. Errors like
> Undefined symbols for architecture x86_64:
>... REFERENCES TO stuff in INIReader ...
>ld: symbol(s) not found
> for architecture x86_64 clang: error: linker command failed with exit
> code 1 (use -v to see invocation)
show up.
Right now I am compiling by running the commands and it will work.
> g++ -c -Wall ../inih/cpp/INIReader.cpp
> g++ -c -Wall ../inih/ini.c
> g++ -c -Wall -I../inih/cpp main.cpp
> g++ -o configtest main.o INIReader.o ini.o
I thought that the g++ compiler will look for each #include in each of the default include directories and the passed -I directory and do not know why the above one liner does not work. Will g++ "follow" includes in all files like the ./ini.h? I have not been able to find a good resource for learning this. How can I combine these command into one line like the previous command? Thanks.
Edit:
I have looked at the "duplicate" question but not understand how it relates to my problem. I am trying to find a good resource for learning how to "include" correctly with g++ and know why my current one liner does not work. It is not a problem in the code, as compiling and then linking one by one is successful!
Duplicate question was similar, but did not cover including files in other directories.