User forums > General (but related to Code::Blocks)

How to work with header files in codeblocks

(1/2) > >>

ankitbehera2670:
I have three file:

main.cpp:

--- Code: ---#include <iostream>
#include "head.h"
using namespace std;

int main()
{
    int a,b;
    a=2;b=3;
    int c=sum(a,b);
    cout <<"c:"<<c<<endl;
    return 0;
}
--- End code ---

head.h:

--- Code: ---#ifndef _HEAD_H_
#define _HEAD_H_
int sum(int a , int b);
#endif

--- End code ---
head.c:

--- Code: ---#include "head.h"

int sum(int a, int b)
{
    return(a+b);
}
--- End code ---

When I compile it, codeblocks give me the error: undefined error to function sum. And I have also included the path in Setting->Build Options->Search Directories->Compiler->Add. But still I get the error.

BlueHazzard:
http://wiki.codeblocks.org/index.php?title=FAQ-Compiling_(general)#Q:_How_do_I_report_a_compilation_problem_on_the_forums.3F

but probably you are not using projects?

ankitbehera2670:
No. I am using projects. But I did choose "Empty  Project".

oBFusCATed:
Then add all your files to the project. This will resolve the problem.

ankitbehera2670:
I have already done that but still doesn't seem to work. Here is screenshot:https://ibb.co/cKX5xc

Navigation

[0] Message Index

[#] Next page

Go to full version