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

The Archive Base Latest Questions

Editorial Team
  • 0
Editorial Team
Asked: June 1, 20262026-06-01T12:59:16+00:00 2026-06-01T12:59:16+00:00

I have to use an ugly C-library inside my c++ application. In the following

  • 0

I have to use an ugly C-library inside my c++ application. In the following explanation I will call it UglyLib. I successfully compiled UglyLib as a statically linked library.
In the file ugly.h UglyLib uses an extern variable:

file ugly.h:

extern SomeStruct_type somestruct;

the variable is defined (and also used) in another file. I will call it anotherugly.c.

file anotherugly.c:

SomeStruct_type somestruct;

My c++ application is based on a generic template library (TemplateLib) and the application itself is composed by the main window GUI code and on an application library statically linked with the main window code. I will call this statically linked library ApplicationLib.

TemplateLib contains a templatelibfile.h, that exports a function foo using somestruct, the extern variable exposed by UglyLib.

file templatelibfile.h:

#include<ugly.h>
...
void foo()
{
...
do something with somestruct
...
}

foo function is used by appllibfile.h contained in the statically linked ApplicationLib.

file appllibfile.h:

#include<templatelibfile.h>
...
void applfoo()
{
...
foo();
...
}

Main Window application includes appllibfile.h

file main.cpp:

#include<appllibfile.h>
...
int main()
{
...
applfoo();
...
return 0;
}

In VS2008 when I try to compile the main window application, the microsoft linker give me this error

error LNK2001: unresolved external symbol “struct SomeStruct_type somestruct” (?somestruct@@3USomeStruct_type@@A)

If I add in templatefile.h a new definition of the extern variable the compiler stops to complain.

file templatelibfile.h:

#include<ugly.h>
SomeStruct_type somestruct
...
void foo()
{
...
do something with somestruct;
...
}

BUT I would wish to avoid it because I don’t know if it is the correct thing to do (I don’t want to risk to alter the semantic of UglyLib redefining a different instance of somestruct variable).
Have you some suggestions in order to avoid the linking problem without redefining the somestruct extern variable?
Thanks a lot!

  • 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-01T12:59:17+00:00Added an answer on June 1, 2026 at 12:59 pm

    It’s probably because of the name-mangling that the C++ compiler does. Since anotherugly.c is a C source (presumably compiled with a C compiler), the symbol somestruct will be exposed without being mangled. When you compile the rest of the files with a C++ compiler, the linker then looks for a mangled name which does not exist.

    I think surrounding the declaration in ugly.h in extern "C" might solve the problem.

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

Sidebar

Related Questions

I have a use case where I need to call a (non-static) method in
I have an asynchronous library which is compiled under .NET 3.5, since it's used
I have use include ('base.php') script in my other scripts ( more.php ). Now
I have use the TryUpdateModel method on the controllers but now I need to
Hello I have use DOMDocs in the past but I am stuck how to
I am working on a website on which we have use parallax effect. In
I'm just starting to learn AspectJ, and I have use-case for say, User login.
I have a use case where I am setting the page focus to a
I have a use case where if a number lies between 0-10 it should
I have the following class: class BritneySpears { public: int getValue() { return m_value;

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.