Sign in to follow this  

Header files

This topic is 3155 days old which is more than the 365 day threshold we allow for new replies. Please post a new topic.

If you intended to correct an error in the post then please contact us.

Recommended Posts

Hello, I am trying to learn how to use header files but am having trouble. Here is what I have:
main.cpp
#include <iostream>
#include "func1.h"
using namespace std;


int main()
{
	cout << "This is main.cpp" << endl;
	
	func1();
	
	return 0;
}

func1.cpp
#include "func1.h"
#include <iostream>
using namespace std;

void func1()
{
	cout << "This is func1." << endl;
}

func1.h
#ifndef __FUNC1_H_
#define __FUNC1_H_

void func1();

#endif

I get the following error: g++ -o headers main.o -lpthread main.o: In function `main': main.cpp:(.text+0x83): undefined reference to `func1()' collect2: ld returned 1 exit status make: *** [headers] Error 1 I am not sure what I am doing wrong. Thanks.

Share this post


Link to post
Share on other sites

This topic is 3155 days old which is more than the 365 day threshold we allow for new replies. Please post a new topic.

If you intended to correct an error in the post then please contact us.

Create an account or sign in to comment

You need to be a member in order to leave a comment

Create an account

Sign up for a new account in our community. It's easy!

Register a new account

Sign in

Already have an account? Sign in here.

Sign In Now

Sign in to follow this