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 8391115
In Process

The Archive Base Latest Questions

Editorial Team
  • 0
Editorial Team
Asked: June 9, 20262026-06-09T19:10:32+00:00 2026-06-09T19:10:32+00:00

My project has this folder structure: Project/ –Classes/ —-Class1.h —-Class1.cpp –main.cpp Class1.h contains method

  • 0

My project has this folder structure:

Project/
--Classes/
----Class1.h
----Class1.cpp
--main.cpp

“Class1.h” contains method definitions, “Class1.cpp” is the source code for “Class1.h”.

The source code of “Class1.h” is like this:

class Class1 {
  public:
    void do_something();
};

The source code of “Class1.cpp” is like this:

#include "Class1.h"

void Class1::do_something() {
  //
} 

The source code of “main.cpp” is like this:

#include "Classes/Class1.h"

int main(int argc,char** args) {
  Class1* var = new Class1();
  var->do_something();
  return 0;
}     

However, when compiling “main.cpp”, the compiler doesn’t know where the implementation of methods in Class1 is, so it shows linking error about undefined reference.

Do I have to add any path into the command line so the compiler knows what source files it has to compile? How to tell the compiler that it must compile “Class1.cpp” also?

  • 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-06-09T19:10:34+00:00Added an answer on June 9, 2026 at 7:10 pm

    You need to know about building (compiling and linking) C++ applications. This topic usually don’t describe in programming books about C++ and only way to do it – google and programming community sites with articles.

    Fast answer is:

    g++ -c Classes/Class1.cpp -o Class1.o
    g++ -c main.cpp -o main.o
    g++ Class1.0 main.0 -o ProjectName
    

    It’s a simple set of commands to compiling and linking program. Usually it would be done by build system (make, qmake, cmake, waf, scons, ant etc). Also, IDE can build program without additional configuration, Visual Studio for example.

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

Sidebar

Related Questions

The project, I have involved, has an architecture-oriented project's file/folder structure: Root |____ Node1
I have a Java project which has this file structure (shown in Eclipse): ProjectName
We are using TortoiseSVN for a project. One file in this project has a
I am working on a small project for learning PHP better. This project has
This is how my project looks: TestMvc (my web project) has a reference to
In the Makefile.in of an existing c++ project on linux (ubuntu), it has this:
I have been handed this project that has a large number of issues with
I am adding MVC to a project that has MANY legacy webform pages. This
My use case is this... I have a project that has two production branches.
I have an AS3 project making use of compile time constants. This has worked

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.