-2

For a C++ project I have a folder structure like this:

  • Makefile
  • src/main.cpp
  • include/parse.h

My issue comes from compiling. In my main.cpp I do:

#include parse.h

This then gives me an error to say it can't find "parse.h". Then I put in there:

#include include/parse.h

That doesn't work either, i guess because it's looking for src/include which doesn't exist. Is there a way I can simply put #include parse.h and have it look for that folder, or alternatively what should I put on that line so it can be found?

EDIT: Sorry if my question wasn't clear. I changed the formatting a bit for clarify, but basically, yes it's an issue that I don't know how to specify the directory. It would be easy if all te code was in one dir, but since the include folder is on the same level on include I don't know how to specify.

Jimmy
  • 12,087
  • 28
  • 102
  • 192
  • 1
    You're getting downvotes probably because your question isn't very clear. Post some code, post what commands you're using to compile, specify more what exactly your issue is. I'm betting it's a problem with specifying include paths as compile arguments, not missing quotes. But that's the thing, with your current info we can only guess. :) –  Apr 16 '15 at 07:00
  • 2
    If you are using `gcc` you can use pass the `-I./include` flag when you compile the program and use `#include ` to include the header. – wefwefa3 Apr 16 '15 at 07:10
  • 3
    Also see http://stackoverflow.com/questions/2908057/makefiles-compile-all-cpp-files-in-src-to-os-in-obj-then-link-to-binary?rq=1 for more along the lines of specifying dirs and whatnot in makefile. But if you don't have any quotes or <> around your includes, AugmentedJacob's answer is correct. –  Apr 16 '15 at 07:12
  • Last thing I'd suggest is if you're really new to C++, try learning/starting out using an IDE like Eclipse with CDT plugin or Visual Studio Community Edition. These IDE's default to automating the build process so that you don't need to add writing compiler specific makefiles to your learning curve right off bat. –  Apr 16 '15 at 07:15

2 Answers2

0

The syntax is #include<HeaderName.h> or #include"HeaderName.h"

Where HeaderName is the name of the file in your directory that you wish to add to the program.

In your case you should be using one of the following.

#include<parse.h> or #include"parse.h"

If there's a subfolder that you need to get to then you could use this

#include "../include/parse.h"

Augmented Jacob
  • 1,567
  • 19
  • 45
  • I really think the issue here isn't him forgetting to put quotes on his include, he probably just didn't write it properly on here. Sounds more like he's after specifying an include directory in compiler args. –  Apr 16 '15 at 06:58
  • @TechnikEmpire you're probably right but let's see how Jimmy will refer to the answer... – W.F. Apr 16 '15 at 07:00
  • Yeah I asked him to give more deets –  Apr 16 '15 at 07:01
  • 1
    Yeah @TechnikEmpire waiting for OP to reply cause judging by his page, he's not much of a C++ guy. I may be wrong. – Augmented Jacob Apr 16 '15 at 07:01
  • @AugmentedJacob Edited with a bit more detail – Jimmy Apr 16 '15 at 07:08
  • @Jimmy it's the syntax. There's not much to explain. – Augmented Jacob Apr 16 '15 at 07:09
  • @AugmentedJacob if you read his update, he appears to be after how to specify include/src/misc directories to compiler args. –  Apr 16 '15 at 07:17
  • Yes, I've made the changes too. Added an extra part to the answer and I hope he finds it useful. – Augmented Jacob Apr 16 '15 at 07:18
0

In your main.cpp you need to put : #include "../include/parse.h"

reneca
  • 9
  • 1