Question

When I try to compile my file using a library (.a), I get 'fatal error: URLInputStream.h: No such file or directory compilation terminated. '. I'm still pretty new to C++, and this seems so simple but I can't get it to work.

Compilation commands I've tried:

g++ inc/Downloader.h lib/libcs240utils.a
g++ inc/Downloader.h -L lib -l cs240utils
g++ inc/Downloader.h -Llib -lcs240utils
g++ src/Downloader.cpp -I inc -L lib -l cs240utils 
g++ -c src/Downloader.cpp -I inc -L lib -l cs240utils 

How I compile my archive:

make lib
g++ -c -o utils/obj/CommandRunner.o utils/src/CommandRunner.cpp -I utils/inc
g++ -c -o utils/obj/FileInputStream.o utils/src/FileInputStream.cpp -I utils/inc
g++ -c -o utils/obj/FileSystem.o utils/src/FileSystem.cpp -I utils/inc
g++ -c -o utils/obj/HTMLToken.o utils/src/HTMLToken.cpp -I utils/inc
g++ -c -o utils/obj/HTMLTokenizer.o utils/src/HTMLTokenizer.cpp -I utils/inc
g++ -c -o utils/obj/HTTPInputStream.o utils/src/HTTPInputStream.cpp -I utils/inc
g++ -c -o utils/obj/StringUtil.o utils/src/StringUtil.cpp -I utils/inc
g++ -c -o utils/obj/URLInputStream.o utils/src/URLInputStream.cpp -I utils/inc
ar cr lib/libcs240utils.a utils/obj/*.o

The archive seems to be built correctly:

ar t lib/libcs240utils.a 

CommandRunner.o
FileInputStream.o
FileSystem.o
HTMLToken.o
HTMLTokenizer.o
HTTPInputStream.o
StringUtil.o
URLInputStream.o

I've also tried various options in ar. If I specify an include path -I utils/inc then it will compile and work properly, so the file I want does work properly. I've read numerous articles and questions here on StackOverflow, and I can't seem to see what I'm doing incorrectly. Any ideas or suggestions?

Note: I'm compiling a header which seems weird. It was originally split into .cpp and .h, but to simplify problem solving I merged them. This same error happened when they were split as well: g++ src/Downloader.cpp -I inc -L lib -l cs240utils

Was it helpful?

Solution

If Downloader.h still likely needs header files to talk to types/classes/etc. in your static library.

The fact that you mention that "-I utils/inc" makes it work would lead me to think that Downloader.h references stuff in that header. You still need the header for compilation even when you have a static lib as part of the link step.

Licensed under: CC-BY-SA with attribution
Not affiliated with StackOverflow
scroll top