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

The Archive Base Latest Questions

Editorial Team
  • 0
Editorial Team
Asked: May 25, 20262026-05-25T18:25:29+00:00 2026-05-25T18:25:29+00:00

I wrote something to simulate the getopt.h library for a Windows application, and part

  • 0

I wrote something to simulate the getopt.h library for a Windows application, and part of this is a global variable. This worked fine when I compiled the program as a single application; however, when I split off the getopt library and linked against it, my program started getting segfaults. Investigating this, it seems that accessing the variable from outside the DLL doesn’t work and returns an invalid pointer; is there anything I can do to fix this?

Edit:If I enter a function in the DLL in the debugger, the variable has the correct value – acessing it directly from the application gives a different value.

  • 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-25T18:25:29+00:00Added an answer on May 25, 2026 at 6:25 pm

    What’s probably happening is that you haven’t setup the dllexport/dllimport correctly. The result is that you’re ending up with different copies of the same variable. (one in the DLL and one outside)

    Within the DLL, you need to compile with dllexport to expose the variable to the client application.

    Then in the client application, you need to declare the same variable as dllimport. Then it will link against the one that’s in the DLL.

    This is slightly unfortunate because the same headers are usually used for the DLL and the client. So the usual work-around is this:

    #ifdef COMPILE_DLL
    #define DLL_EXPORT  __declspec(dllexport)
    #else
    #define DLL_EXPORT  __declspec(dllimport)
    #endif
    

    EDIT:

    Can you confirm whether or not you have two copies of the same variable? Try printing out the addresses from both inside the DLL and from outside.

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

Sidebar

Related Questions

I wrote something like this: instance Functor (Either e) where fmap _ (Left a)
While playing around with regexps in Scala I wrote something like this: scala> val
I am trying to use jQuery with MYSQL and I wrote something like this
I was recently working with a DateTime object, and wrote something like this: DateTime
I was trying to understand something with pointers, so I wrote this code: #include
I wrote something like this in the controller. public ActionResult Giris() { ViewData[Tarif] =
How to make a filter for .txt files? I wrote something like this but
I wrote something to load PNG files from a custom C++ IStream via GDI+.
Something I wrote throws a lot of AttributeError exceptions when using time.strptime() inside a
I'm using WebKitDotNet to simulate and automate a web browser. This is really nifty

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.