8

CodeBlocks Failed to Find the Header File

Code::Blocks (http://www.codeblocks.org/) is an alternative C++ IDE for Ubuntu platform. It is a free C++ IDE and you do not need to configure Wine to get Visual C++ runs on your Linux OS. Although the user interface probably will be slightly different from Visual C++ but the features and main functionalities are almost the same.

However, CodeBlocks seems having problem in getting the header file if the .cpp file includes the header file for compilation as well. For example, in the PatientAccount.cpp file:

#include "PatientAccount.h"


You will get the following error when compiling the PatientAccount.cpp file:

/home/yee/CodeBlocks/Assignment1/src/PatientAccount.cpp|1|fatal error: PatientAccount.h: No such file or directory

Workaround

You need to provide the absolute path to tell the compiler where to find the header file:

#include "/home/yee/CodeBlocks/Assignment1/include/PatientAccount.h"

Solution

You have to configure the project build and add the directory where the header file is located. The steps are as below:-

  1. Project > Build options > Search Directories tab
  2. Choose the Policy dropdown list with the option: Prepend target options to project options”
  3. Click the button ‘Add’ to search and add the directory (e.g. ‘include’ directory)
  4. Another popup with the question “Keep this as a relative path?” and click ‘Yes’ to add the directory.

Note: The location of the settings probably varies depending on the Code::Blocks version. The workaround and solution is applicable for version 10.05.

facebooktwittergoogle_plusredditpinterestlinkedinmailby feather
1 Star2 Stars3 Stars4 Stars5 Stars (4 votes, average: 2.25 out of 5)
Loading ... Loading ...

chin yee

8 Comments

  1. OMG ty! Spent all day on IRC:s and forums trying to find a solution. Then I just googled: code::blocks “fatal error” and this came up.

  2. I can’t believe the config for codeblocks doesn’t point to this folder by default.
    Thank you for documenting this setting, and saving me from a headache.

  3. Good tip. Before reading your post, I used to type in the relative location of the folder in my include, just like you would on a website:

    #include “../include/header_file.h”

    Thanks, again!

Leave a Reply

Your email address will not be published. Required fields are marked *

Current ye@r *

What is 9 + 9 ?
Please leave these two fields as-is:
IMPORTANT! To be able to proceed, you need to solve the following simple math (so we know that you are a human) :-)