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

The Archive Base Latest Questions

Editorial Team
  • 0
Editorial Team
Asked: June 11, 20262026-06-11T18:23:14+00:00 2026-06-11T18:23:14+00:00

I am trying to use a extern C function inside my header file for

  • 0

I am trying to use a extern “C” function inside my header file for a c++ class.

When I compile I keep getting the error

duplicate symbol _currentInstance in:
main.o
GLHandler.o

I thought I had the right guards but can’t seem to figure out why this is happening. Any help would be much appreciated.

Here is the header file.

#ifndef GLHANDLER_H
#define GLHANDLER_H

#include "LoadedObject.h"


#ifdef __cplusplus
extern "C" {
void displayCallback();
}
#endif



class GLHandler {

private:
    LoadedObject *object;

public:
    GLHandler(LoadedObject *);
    void initializeVBO(LoadedObject *);
    void renderObject(struct model *);
    void displayFunction(void);
    model *createModel(void);
    void setupDisplayCallback();


};

GLHandler *currentInstance;

#ifdef __cplusplus
}

#endif

#endif

EDIT: Quickly pointed out by David, the extern GLHandler *currentInstance fixed the error.

  • 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-11T18:23:15+00:00Added an answer on June 11, 2026 at 6:23 pm

    This problem has nothing to do with the extern "C" declaration – you’re defining a global variable in the header, so it gets defined in each compilation unit:

    GLHandler *currentInstance;
    

    In the header, you should instead use:

    extern GLHandler *currentInstance;
    

    then in exactly one .cpp file have:

    GLHandler *currentInstance;
    

    As a side note, as it stands right now, the header is valid only for C++, since it has a class definition. The #ifdef __cplusplus directives are pointless clutter (though harmless).

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

Sidebar

Related Questions

I'm trying use mod_rewrite to rewrite URLs from the following: http://www.site.com/one-two-file.php to http://www.site.com/one/two/file.php The
trying to use hibernate with my web app and getting following exception: Initial SessionFactory
I'm trying to use this function in a C program that needs to be
I'm trying to use a class named CFindWnd . Unfortunately it's written in C
I'm trying to use jquery load function, but I can't get the whole content
I am writing a program where a C++ file calls an extern C function
I am trying to use the function PathCanonicalize using DllImport (PInvoke) on a 64
I am trying to compile a 64bit dll for use with a 64bit C#
Possible Duplicate: A call to PInvoke function '[…]' has unbalanced the stack I'm trying
I'm trying to initialize a global array of function pointers at compile-time, in either

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.