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

The Archive Base Latest Questions

Editorial Team
  • 0
Editorial Team
Asked: June 1, 20262026-06-01T18:50:49+00:00 2026-06-01T18:50:49+00:00

The short question is: How can I use Visual Studio to create/compile/run projects that

  • 0

The short question is: How can I use Visual Studio to create/compile/run projects that have source code in different directories.

Here are the specific details:

I have an class definition file (.hpp) and implementation file (.cpp) in one directory and I have a main.cpp file in another directory. In Visual Studio 2008, I created a new project and put main.cpp in that project. I added the class file directory to Additional Include Directories (right click on the project -> project properties -> Configuration Properties – C/C++ – General -> Additional Include Directories = C:\Test\cpp).

When I do this, intellisense works fine when editing main.cpp. When I Build the project, it compiles fine, but I get link errors such as:

error LNK2019: unresolved external symbol “public: int __thiscall Test::add(int)” (?add@Test@@QAEHH@Z) referenced in function _main.

As far as I can tell, Visual Studio isn’t actually compiling Test.cpp (I don’t see any .obj files being made for it). I have tried compiling it separating, before Compiling/Building main.cpp, but that didn’t make any difference. Is there a way around this? When I search the web for answers, I see a lot of people forgetting to include libraries for the linker, but I’m not dealing with any libraries.

I have also verified this code compiles and runs correctly by moving Test.hpp and Test.cpp to the same directory as main.cpp – that worked without any problems. I would just stick with that setup, but I need to be able to use source from different directories for a project I’m working on.

Here are the 3 files:

  1. C:\Test\cpp\Test.hpp

    #ifndef TEST_H
    #define TEST_H
    
    class Test
    {
    private:
      int mynum;
    
    public:
      Test();
      int add(int num);
    
    };
    #endif //TEST_H
    
  2. C:\Test\cpp\Test.cpp

    #include "Test.hpp"
    
    Test::Test()
    {
      mynum = 0;
    }
    
    int Test::add(int num)
    {
      return mynum += num;
    }
    
  3. C:\Visual Studio Projects\MyProject\main.cpp

    #include <iostream>
    #include <Test\Test\Test.hpp>
    
    int main(int argc, char *argv[])
    {
      Test test;
      std::cout << "Add 5 = " << test.add(5) << std::endl;
      return 0;
    }
    
  • 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-01T18:50:50+00:00Added an answer on June 1, 2026 at 6:50 pm

    The bottom line is that you have to compile Test.cpp and link with it somehow. Two options:

    1. Add Test.cpp to your project
    2. Create a library project, say TestLib. Add Test.cpp to that project and compile it. Then link your main project with the TestLib.

    In second case you can have dependent projects in VisualStudio. This way it will properly pull proper Debug/Release/etc. version of the lib when you build your main project. It will also get it from the right folder. E.g. no need to mess with linker settings manually.

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

Sidebar

Related Questions

Short question: If I have class that impelemnts FactoryBean interface, how can I get
I have a short and simple question: Can I use NSSpeechSynthesizer or Mac OS's
I have written a custom dialog (form) that I can use in a C#
My Question: Is there a way to set up Visual Studio to use the
Short question: How can I use createLink in a Filter? I'm getting error: No
The short question: how can I (or is it possible to) make use of
I would like to create a Visual Studio addin which can identify if the
Short question: Can anyone tell me what the requirements (especially when it comes to
A short question: I've got a TabNavigator with multiple canvas children. How can i
SHORT VERSION OF QUESTION: So basically my question is: How can I set the

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.