Presumably by ".cpp file" you mean "translation unit".
The holy C++ standard couldn't care less how the code is distributed in files, and has no notion of header files versus .cpp.
A variable to be defined in one translation unit and accessed in another, must have extern
linkage. This is the default for namespace level non-const
variables. However, an ordinary declaration will also define the variable, and then you run into the One Definition Rule that in general requires a single definition of each thing.
A solution is to write e.g.
extern int n_oranges;
in the translation unit where you just want to access the variable. The explicit mention of extern
linkage, without an initializer, makes this a pure declaration.
You can have as many pure declarations of something, as you want.
It's best to put such a declaration in a header file, so as to avoid redundant multiple possibly not quite matching declarations. Note that in a header file it will be included as part of each relevant translation unit's text. The C++ compiler doesn't care where it comes from, just that it's there.
Relevant standardese:
C++11 §3.1/2:
” A declaration is a definition unless it declares a function without specifying the function’s body (8.4), it
contains the extern
specifier (7.1.1) or a linkage-specification (7.5) and neither an initializer nor a function-body, it declares a static data member in a class definition (9.2, 9.4), it is a class name declaration (9.1), it is an opaque-enum-declaration (7.2), it is a template-parameter (14.1), it is a parameter-declaration (8.3.5) in a
function declarator that is not the declarator of a function-definition, or it is a typedef
declaration (7.1.3),
an alias-declaration (7.1.3), a using-declaration (7.3.3), a static_assert-declaration (Clause 7), an attribute-declaration (Clause 7), an empty-declaration (Clause 7), or a using-directive (7.3.4).