Skip to main content
1 of 2
user29356
  • 89
  • 1
  • 3
  • 9

global variables with c++ in multiuple files

I'm not a c++ programmer(but have used regular c code for implementing low level machine language equivalent SW for some time), and after tying to modify an existing c++ program to do what I need (and failing), I've decided to rewrite parts of the code in plain c code.

But to be able to use the data, I need to create some variables that have to be accessable to parts of the existing c++ code.

When I declare a global variable (extern int variable name;) outside the main program, the compile fails because the references to the global variable aren't within the scope of the cpp parts of the program.

I don't program with multiple files myself, so I was wondering if I need to globally declare the same variables as part of each cpp program that needs to have access to the variables? Is there a another/better way?

user29356
  • 89
  • 1
  • 3
  • 9