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

The Archive Base Latest Questions

Editorial Team
  • 0
Editorial Team
Asked: June 5, 20262026-06-05T18:47:24+00:00 2026-06-05T18:47:24+00:00

I have been having these really odd problems with Visual Studio 2010. At this

  • 0

I have been having these really odd problems with Visual Studio 2010. At this point, the behavior is so erratic that I really wish I did not have to use it for CUDA (I know I don’t have to, but it is hard not to use it).

One of the many problems I have been having with really basic stuff is header files being included more than once. For example:

//vars.cuh
#if !defined(VARS_cuh)
#define VARS_cuh

#include <cuda.h>
#include <cuda_runtime_api.h>

int* kern_xstart, *kern_xend, *kern_ystart, *kern_yend, *kern_zstart, *kern_zend;
/* more variable definitions */

#endif

I then include this file in most of my source files:

//source_file.cu
extern "C"{
#include "vars.cuh"
/* more includes of my own headers */
#include <cuda.h>
#include <cuda_runtime_api.h>
}

/* source file body */

The VS 2010 compiler puts out errors like this: “error LNK2005: foo already defined in other_source_file_I_wrote.cu.obj”

Why is it doing this? Also, to kill two birds with one stone, with this setup, I also have problems with writing a function in source_file.cu, and then prototyping it in vars.cuh. The problem arrises that vars.cuh can’t see the definition, even though I am clearly including vars.cuh in source_file.cu!

Thank you!

  • 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-05T18:47:25+00:00Added an answer on June 5, 2026 at 6:47 pm

    The header file is being compiled multiple times because, as you say, you include this header file in most of your source files. Those global variables are included in multiple source files and thus are defined in every source file that includes the header. When the linker links all of the object files together, it finds multiple definitions of those variables, hence the error.

    If you want to share global variables across multiple source files, declare them as extern in the header, then define each of them once in one source file.

    This isn’t a problem with Visual Studio or the Visual C++ compiler, it’s how C works.

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

Sidebar

Related Questions

I have been having an issue with the $this->delete() method that deletes a record
I have been having problems installing VB6 on Windows 7. I realize it is
I have been having problems with my site and I just realized I have
We have been having some debate this week at my company as to how
I have been having problems with creating a download list of files for a
I have been having this issue in iterating through an array of keys and
I have been having this problem for the last few days and I can't
I've been having really bad memory problems with an ASP.NET Application. It seems as
I have been having issues calling a background image in my CSS file. The
I have been having trouble with the Google Maps API for one week now

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.