Sign Up

Sign Up to our social questions and Answers Engine to ask questions, answer people’s questions, and connect with other people.

Have an account? Sign In

Have an account? Sign In Now

Sign In

Login to our social questions & Answers Engine to ask questions answer people’s questions & connect with other people.

Sign Up Here

Forgot Password?

Don't have account, Sign Up Here

Forgot Password

Lost your password? Please enter your email address. You will receive a link and will create a new password via email.

Have an account? Sign In Now

You must login to ask a question.

Forgot Password?

Need An Account, Sign Up Here

Please briefly explain why you feel this question should be reported.

Please briefly explain why you feel this answer should be reported.

Please briefly explain why you feel this user should be reported.

Sign InSign Up

The Archive Base

The Archive Base Logo The Archive Base Logo

The Archive Base Navigation

  • SEARCH
  • Home
  • About Us
  • Blog
  • Contact Us
Search
Ask A Question

Mobile menu

Close
Ask a Question
  • Home
  • Add group
  • Groups page
  • Feed
  • User Profile
  • Communities
  • Questions
    • New Questions
    • Trending Questions
    • Must read Questions
    • Hot Questions
  • Polls
  • Tags
  • Badges
  • Buy Points
  • Users
  • Help
  • Buy Theme
  • SEARCH
Home/ Questions/Q 4106180
In Process

The Archive Base Latest Questions

Editorial Team
  • 0
Editorial Team
Asked: May 20, 20262026-05-20T21:20:36+00:00 2026-05-20T21:20:36+00:00

I am trying to understand how including multiple files in C++ works. I did

  • 0

I am trying to understand how including multiple files in C++ works. I did a lot of searching and finally I wrote a test code which is summarizes my problem. I have two header files and two cpp files that look like this:

test1.h:

#ifndef _TEST_1_H
#define _TEST_1_H

int val = 10;
void func1();

#endif

test2.h:

#ifndef _TEST_2_H
#define _TEST_2_H

#include "test1.h"
void func2();

#endif

test1.cpp:

#include <iostream>
#include "test1.h"

void func1()
{
    std::cout<<val<<std::endl;
}

test2.cpp:

#include <iostream>
#include "test2.h"

void func2()
{
    func1();
}

And my main file looks as follows:

test.cpp:

#include <iostream>
#include "test2.h"
#include "test1.h"


int main()
{
    func1();
    func2();
    getchar();
    return 0;
}

I am using VS10 and I have only added “test.cpp” as source file. When I compile this code I get following error:

**1>test.obj : error LNK2019: unresolved external symbol "void __cdecl func2(void)" (?func2@@YAXXZ) referenced in function _main **
**1>test.obj : error LNK2019: unresolved external symbol "void __cdecl func1(void)" (?func1@@YAXXZ) referenced in function _main **

I don’t quite understand even after including both the header files why am I getting this? What am I missing?

Any help would be appreciated!

Thanks
Newbie

  • 1 1 Answer
  • 0 Views
  • 0 Followers
  • 0
Share
  • Facebook
  • Report

Leave an answer
Cancel reply

You must login to add an answer.

Forgot Password?

Need An Account, Sign Up Here

1 Answer

  • Voted
  • Oldest
  • Recent
  • Random
  1. Editorial Team
    Editorial Team
    2026-05-20T21:20:36+00:00Added an answer on May 20, 2026 at 9:20 pm

    Including the files only satisfy the compiler. You need to link all of the obj files together.
    If you are using visual studio, make sure all of those files are included in the project you’re building.

    One a side note, using int val = 10 on the header file is wrong – you’ll have linkage problem.
    Put it in a cpp file and use extern int val on its header.

    HTH

    • 0
    • Reply
    • Share
      Share
      • Share on Facebook
      • Share on Twitter
      • Share on LinkedIn
      • Share on WhatsApp
      • Report

Sidebar

Related Questions

Trying to understand Ruby a bit better, I ran into this code surfing the
After trying to understand why client code is not rendered in a page (injected
I'm trying to understand someone else's Perl code without knowing much Perl myself. I
I'm really confused here. I am trying to understand this code (it's javascript) but
I am trying to understand how to include JavaScript externally so the code prints
I am trying to understand the ways in which an unmanaged user-mode Windows process
I'm trying to write my code as maintainable and easy to understand as possible,
Trying to understand an fft (Fast Fourier Transform) routine I'm using (stealing)(recycling) Input is
Trying to understand the options for will_paginate's paginate method: :page — REQUIRED, but defaults
Trying to understand something. I created a d:\svn\repository on my server. I committed folders

Explore

  • Home
  • Add group
  • Groups page
  • Communities
  • Questions
    • New Questions
    • Trending Questions
    • Must read Questions
    • Hot Questions
  • Polls
  • Tags
  • Badges
  • Users
  • Help
  • SEARCH

Footer

© 2021 The Archive Base. All Rights Reserved
With Love by The Archive Base

Insert/edit link

Enter the destination URL

Or link to existing content

    No search term specified. Showing recent items. Search or use up and down arrow keys to select an item.