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

  • Home
  • SEARCH
  • 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 7493509
In Process

The Archive Base Latest Questions

Editorial Team
  • 0
Editorial Team
Asked: May 29, 20262026-05-29T17:00:03+00:00 2026-05-29T17:00:03+00:00

I have a namespace that I am currently using in two classes. When I

  • 0

I have a namespace that I am currently using in two classes. When I try to compile my project, I get that error but my namespace is not anonymous!

One of my classes looks like this:

//margin.cpp
#include <math.h>
#include "margin.h"
#include "anotherClass.h"
#include "specificMath.nsp.h" //My namespace

double margin::doSomeMath(double a, double b){
    return specificMath::math_function1(0, 1, 0);
    // Just a simpler, random example
} 

My namespace looks like this:

//specificMath.nsp.h
#ifndef specificMath
#define specificMath
namespace specificMath {
     double math_function1(double, double, double);
     double math_function1(double);
     //more functions
}

 //specificMath.nsp.cpp
 #include <stdlib.h>
 #include "constants.h"
 #include "specificMath.nsp.h"

 namespace specificMath{
     double math_function1(double a, double b, double c){
          //some code
     }
     ... more functions
 }

When I try to compile, it seems to compile fine, but when linking (and I’ve been doing “make clean” to make sure it’s using the new files) I get an error saying:

margin.o: In function `margin::doSomeMath(double, double)':
margin.cpp:(.text+0x3d): undefined reference to `(anonymous namespace)::math_function1(double, double, double)'

Why does it think it’s an anonymous namespace? How can I fix this?

I compile doing this:

g++ -I. -c -w *.h *.cpp

And then…

g++ -o myProgram *.o 
  • 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-29T17:00:14+00:00Added an answer on May 29, 2026 at 5:00 pm

    You #defined the namespace name away. After the preprocessor sees #define specificMath, then it finds all instances of specificMath after that and replaces them with what you #defined it to, which in this case, is nothing. So it simply eliminates it.

    #ifndef specificMath
    #define specificMath
    namespace specificMath {
    

    After the preprocessor runs

    namespace {
    

    Always use all capitals for macros, and never prepend underscores to them.

    #ifndef SPECIFIC_MATH_FUNCTIONS
    

    for example.

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

Sidebar

Related Questions

In my project I have two libraries that would currently result in a circular
If I have a .Net class that is not part of any namespace then
I have an interface that contains a single method called ListAll() using System.Collections.Generic; namespace
We currently have quite a few classes in a project, and each of those
I have two classes (class A and B) both marked with [Binding]. Currently I'm
I have a cyclical redundancy circular dependency between two classes in my project, StatusEffect
Currently I'm busy on a project using XML messaging. I have one general schema,
I have found that there is generally a singe type or namespace that takes
Have a source xml document that uses namespace containing prefixes and a default namespace.
I have a data structure that represents C# code like this: class Namespace: string

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.