Nogurenn
Nogurenn

Reputation: 878

How to compile and link separated .h and .cpp files in C++ using the command line?

I wanted to separate function definitions and function headers using folders but I get a fatal error saying "x.h" was not found. The filenames provided below are just samples. Is this even possible?

This is the line I'm using:

g++ -I ./headers/ -o main2.o main2.cpp ./definitions/x.cpp 

Upvotes: 0

Views: 116

Answers (1)

P0W
P0W

Reputation: 47794

If you're sure you've correct files in correct path, one issue is :-

There shouldn't be any space after -I and use just ./headers

g++ -I./headers -o main2.o main2.cpp ./definitions/x.cpp 
      ^^No Space

Upvotes: 4

Related Questions