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?

  • 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. – user12563 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, continued here) – npostavs Nov 23 '17 at 1:40

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.

      (defvar oauth--token-data ())


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.

| improve this answer | |
  • 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 1:41
  • 1
    An easy way to avoid the warnings is to defer loading the problematic package: (use-package oauth2 :defer t) – Ted Zlatanov Jun 8 at 15:04

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.

| improve this answer | |
  • It didn't solve to me. – Felipe Oct 16 at 22:58

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service, privacy policy and cookie policy

Not the answer you're looking for? Browse other questions tagged or ask your own question.