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

The Archive Base Latest Questions

Editorial Team
  • 0
Editorial Team
Asked: May 20, 20262026-05-20T15:23:13+00:00 2026-05-20T15:23:13+00:00

I have two projects written in C: a client side and a server side,

  • 0

I have two projects written in C: a client side and a server side, both of which contain lots of common global variables. I want to write a class (clientbot and serverbot using a interface Transaction) which will call the main function of each project.

I have moved all the common global variables in a header file and included it in both project. But on building it is throwing me linking error.

Error 3 error LNK2005: “int g_nBytestoSend” (?g_nBytestoSend@@3HA) already defined in transimpl.obj agentBot.obj

Can anyone suggest what I should do?

  • 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-20T15:23:13+00:00Added an answer on May 20, 2026 at 3:23 pm

    You shouldn’t put the actual variables in the header, only extern declarations of those. Put the actual variables in a separate .c or .cpp file and link with that.

    In the header (lets call it globals.h), you put this declaration:

    extern int g_nBytesToSend;
    

    Then you create a new code file to hold the actual variables (say global.c):

    int g_nBytesToSend;
    

    Let’s imagine you had three code files server.c, client.c and bot.c and that you’re using gcc. You would build this like:

    gcc -o server.o -c server.c
    gcc -o client.o -c client.c
    gcc -o bot.o -c bot.c
    gcc -o globals.o -c globals.c
    gcc -o mybot server.o client.o bot.o globals.o
    

    (Try to keep your number of globals small.)

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

Sidebar

Related Questions

I have two projects, project A and Project B. Both are written in groovy
I have two projects: 1) a project written in Visual C++ 2005 which targets
I have two visual studio projects, one written in C#, another written in fortran
I have two projects and I want to combine them together.When I install each
I have two projects A and B both are built differently, but the jars
I have two projects in the same server, their settings conflict in the session.auto_start,
We have two projects that are both class libraries. Project 1 is a VS
In my WiX projects I have two custom actions, in the same DLL. Both
This issue has been driving me insane. On two separate projects (both of which
I have two projects: a profiler and a basic application (with JUnit tests) The

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.