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

The Archive Base Latest Questions

Editorial Team
  • 0
Editorial Team
Asked: May 20, 20262026-05-20T04:32:23+00:00 2026-05-20T04:32:23+00:00

I have two files once is named as test.cpp and another as ani.cpp. test.cpp

  • 0

I have two files once is named as test.cpp and another as ani.cpp.

test.cpp is as follows:

#include<iostream>

namespace Anirudh{

    void start(){
        std::cout<<"This is the start function of the namespace Anirudh\n";
    }
}

and the file ani.cpp is as follows

#include<iostream>

using namespace Anirudh;
int main(){

    start();
    return 0;
}

and this is what I am doing on the terminal

anirudh@anirudh-Aspire-5920:~/Desktop/testing$ g++ -c test.cpp
anirudh@anirudh-Aspire-5920:~/Desktop/testing$ g++ test.o ani.cpp 
ani.cpp:3: error: ‘Anirudh’ is not a namespace-name
ani.cpp:3: error: expected namespace-name before ‘;’ token
ani.cpp: In function ‘int main()’:
ani.cpp:6: error: ‘start’ was not declared in this scope
anirudh@anirudh-Aspire-5920:~/Desktop/testing$ 

This is the first time I am trying to define my own namespace in C++ and using it in another code. I got my code running after #include "test.cpp" in my ani.cpp file but I want to link the object code of test.cpp with ani.cpp rather than including it inside ani.cpp
I have even tried extern namespace Anirudh; but that didn’t work. Of-course there is a proper way to link them which I do not know right now. So please enlighten me. Thanks in advance.

  • 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-20T04:32:23+00:00Added an answer on May 20, 2026 at 4:32 am

    Within ani.cpp you never told the compiler that there’s a namespace Anirudh somewhere else in the program prior to doing the using. If you’re used to other module systems this probably seems quirky.

    What you can do is declare the namespace+function prior to calling it, with these lines before the using namespace in ani.cpp

    namespace Anirudh{    
        void start();
    }
    

    Often these declarations would be wrapped up in a header but that’s probably not needed for this simple example.

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

Sidebar

Related Questions

I have two php files so far, test.php: <?php include(../config_conn_fordon_db.php); include(../config_open_db.php); // Fix Special
I have two files (f1 and f2) containing some text (or binary data). How
I have two files with slight differences. A normal diff will show me the
I need to setup LookAndFeel Files in JDK 1.6. I have two files: napkinlaf-swingset2.jar
I have two XML files with two different XSD schemas and different namespaces. They
I have two PHP files that I need to link. How can I link
I have two properties files that are not the same and I need to
I have two XML files. They are similar, but there are two nodes of
Suppose that you have two huge files (several GB) that you want to concatenate
I have a project consisting of two files, main.c and logoff.c. When I try

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.