ScalaMacros and Eclipse
Asked Answered
L

3

7

I am trying to compile a (Scala) macro in Eclipse 3.7.2 with the Scala IDE Plugin available for Scala 2.10.0-M3, but I am experiencing the following error:

"macro implementation not found: XXXXX (the most common reason for that is that you cannot use macro implementations in the same compilation run that defines them) if you do need to define macro implementations along with the rest of your program, consider two-phase compilation with -Xmacro-fallback-classpath in the second phase pointing to the output of the first phase"

I already know how to avoid it with a simple editor and a terminal (just following the error message), but is it possible to achieve the dual phase task in Eclipse?

Legault answered 16/5, 2012 at 15:56 Comment(2)
By now, I am going to create a new project to keep the macro implementations in it. This ugly workaround allows the code to compile nice.Legault
Yes, this is a canonical solution to dealing with macros.Zeppelin
O
8

How to create a macro project to link to an existing project:

  • Create a scala project named for example ProjectMacros, put a file named for example Macros.scala containing macros in it. This project should compile without problems, because there are only macros.
  • Right-click on the existing scala project, then "Properties". The Properties window opens.
  • In the Java Build Path section:
    • Under the tab Projects, add ProjectMacros.
    • Under the tab Libraries, click Add Class Folder, and select the ProjectMacros/bin directory.
  • In the Project References section, check ProjectMacros

Now, after adding in the existing project an import like import Macros._ you can use the macros functions and annotations.

Ophicleide answered 24/10, 2012 at 8:33 Comment(0)
L
3

Well, separating macro implementation and macro invocation in two differents projects (and playing with project references) seems to solve the issue. Anyway, the Scala-IDE plugin has been notably improved with its version for Scala 2.10-M4 (in terms of macro support), so I recommend to update to it.

Legault answered 26/6, 2012 at 18:9 Comment(1)
Are you saying the Scala IDE now supports tiered compilation in the same project? If so, how?Reflectance
O
1

You could probably use Ant for building, but since you are saying that you already achieved this with terminal I think it would be easier to create script, and run it using custom builder (go to project properties, click Builders -> New... -> Program and then set it up to run your script.

Offal answered 16/5, 2012 at 21:35 Comment(0)

© 2022 - 2024 — McMap. All rights reserved.