5

Lately I'm getting warnings when compiling the .emacs

Warning (bytecomp): reference to free variable ‘url-http-extra-headers’
Warning (bytecomp): reference to free variable ‘oauth--token-data’
Warning (bytecomp): reference to free variable ‘url-callback-function’
Warning (bytecomp): reference to free variable ‘url-callback-arguments’

I don't know were this variables are defined, and thus cannot constraint the errors.

Q1: Does anyone know were the problem is?

Q2: How to solve the problem?

Drew
  • 75,699
  • 9
  • 109
  • 225
Dox
  • 955
  • 10
  • 28
  • 3
    You're probably setting variables that aren't defined when their assignments are evaluated. You can look for where variables are defined with `M-.`, but that will probably fail if you haven't loaded the file that defines the offending variable yet. –  Nov 22 '17 at 16:23
  • 1
    @DoMiNeLa10 Agreed, just one minor correction: Replace "You're" with "You or one of the packages getting loaded during byte-compilation are". – Basil Nov 22 '17 at 17:18
  • If you set `after-init-time` to `t` at the top of your .emacs does the warning get a filename? (refer [Re: "reference to free variable" only during initialization](https://lists.gnu.org/archive/html/emacs-devel/2017-01/msg00556.html), continued [here](http://lists.gnu.org/archive/html/emacs-devel/2017-02/msg00625.html)) – npostavs Nov 23 '17 at 01:40

2 Answers2

5

See the answer by Drew for a general description of compiler warnings pertaining to free variables.

In your particular case, however, the culprit is the package oauth2.el, which for some reason is getting loaded during the byte-compilation of your user-init-file (perhaps you are a use-package user?).

In this case adding (defvar foo) to your user-init-file will not make the warnings go away. Instead, you could try assigning a value to the corresponding variables before the oauth2 package is loaded in your user-init-file, e.g.

    (eval-when-compile
      (defvar oauth--token-data ())

Update

I removed my suggestion to raise the issue with the oauth2 package from my answer, as byte-compiling the package on its own does not raise the warnings mentioned. In my case, at least, the warnings only appear because of the way use-package loads files before byte-compiling user settings, and I'm not entirely sure why, though it's related to the fact that all variables mentioned are void, i.e. they have been defined with defvar but not assigned a value.

Basil
  • 12,019
  • 43
  • 69
  • 1
    It's probably due to oauth2.el's use of `defadvice`, it has strange interactions with compilation. The nadvice interface is much better about this. – npostavs Nov 23 '17 at 01:41
  • 1
    An easy way to avoid the warnings is to defer loading the problematic package: `(use-package oauth2 :defer t)` – Ted Zlatanov Jun 08 '20 at 15:04
2

Those are only warnings, which means that the rest of your code that loads libraries or whatever should still do that.

In that case, you can use C-h v to find out where each such variable is defined. If such a variable is defined in a library that you load, then you need tell the byte compiler not to worry about that variable, i.e., that it will be properly defined before it is actually used.

To do that you put a vacuous defvar for that variable in your init file. For example, if the variable is foo then you put this in your init file, before it otherwise refers to foo:

(defvar foo)

Note that there is no initial value provided for foo by this defvar.

See the Elisp manual, nodes Defining Variables and Compiler Errors.

Drew
  • 75,699
  • 9
  • 109
  • 225