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

The Archive Base Latest Questions

Editorial Team
  • 0
Editorial Team
Asked: May 28, 20262026-05-28T14:06:53+00:00 2026-05-28T14:06:53+00:00

I have a C++ program called myArchive that calls routines from a static C

  • 0

I have a C++ program called myArchive that calls routines from a static C library.

My code for myArchive has a class called Archive that contains a private variable called md, which of type Metadata *, defined in my C library.

Here’s the myArchive.hpp header:

#ifndef MYARCHIVE_H
#define MYARCHIVE_H

#include "myLibraryHeaders.h"
...
namespace Archive {
    class Archive {
        public:
            Archive();
            virtual ~Archive();

            Metadata * getMd() { return md; }
            Metadata ** getMdRef() { return &md; }
            void setMd(Metadata *_md) { md = _md; }
        private:
            Metadata *md;
    };

    Archive::Archive() {
        md = NULL;
    }

    Archive::~Archive() {
        if (md != NULL) 
           freeMetadata(&md);
    }
}

#endif

The freeMetadata() function is just releasing items in a linked list:

void freeMetadata(Metadata **md) {                                                                                                                                                                                                         
    Metadata *iter;
    Metadata *prev = NULL;

    if (! *md)
        return;

    for (iter = *md; iter != NULL; iter = iter->next) {
        /* ... */
        if (prev != NULL)
            free(prev);
        prev = iter;
    } 

    if (prev != NULL) {
        free(prev);
        prev = NULL;
    }
}

Here is the declaration in one of the headers referenced in myLibraryHeaders.h:

#ifdef __cplusplus
extern "C" {
#endif

#ifndef METADATAHELPERS_H
#define METADATAHELPERS_H

typedef struct metadata {
    /* ... */
    struct metadata *next;
} Metadata;

/* ... */
void freeMetadata(Metadata **md);
/* ... */

#endif

#ifdef __cplusplus
}
#endif

I have some other variables, but this is the stuff relevant to my question, which is:

When I try to compile this, I get an out-of-scope error:

...
g++ -D_FILE_OFFSET_BITS=64 -D_LARGEFILE64_SOURCE=1 -DUSE_ZLIB -DUSE_BZLIB -O3 -Wformat -Wall -Wswitch-enum -static -c myArchive.cpp -o myArchive.o
myArchive.hpp: In destructor "virtual myArchive::Archive::~Archive()":
myArchive.hpp:87: error: "freeMetadata" was not declared in this scope                                                                                                                                                  
make: *** [myArchive] Error 1

But I am including a header file (in myLibraryHeaders.h) that declares freeMetadata(). Further, the compiler isn’t complaining about the Metadata type, which itself is also defined in one of the headers in myLibraryHeaders.h.

What am I missing or doing wrong?

  • 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-28T14:06:53+00:00Added an answer on May 28, 2026 at 2:06 pm

    The only explanation that makes sense is that you’re somehow getting METADATAHELPERS_H defined prior to the include of myLibraryHelpers.h, probably due to some prior include somewhere — some kind of circular include dependency. You can try using g++ -E to extract the post-preproceesed text and try to see if you can untangle the problem from that (search for where freeMetaData appears in that to get some idea of the order that you’re ending up with), but in general solving these problems can be tricky

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

Sidebar

Related Questions

I have a class called ModelView which inherits from NSOpenGLView. When my program runs
I have a fairly old unmanaged C++ program that called managed c# code (vs2003)
I have program that has a variable that should never change. However, somehow, it
I have a program that uses the mt19937 random number generator from boost::random. I
I have a test program called ftest. It loads .so files that contain tests
I have a magnet link from a torrent site that should open this program
Basically I have a Base class called Program. I then have more specific program
I have a winform data entry and retrieval program called CaseNotes. This has a
Under Windows, I have used a program called Dependency Walker to examine the libraries
I have a program failing with: terminate called after throwing an instance of 'std::bad_alloc'

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.