compilation

How to create a runnable jar file from source code programmatically?

﹥>﹥吖頭↗ 提交于 2019-12-09 03:05:59
问题 I need to create runnable .jar file programmatically from a string. My decision is to create a .class file from string and add it to the .jar using JarOutputStream. What API must I use to create the .class file? Are there any other solutions to create a .jar from the source code? 回答1: In order to do that, you can use the Java Compiler API. There is this excellent tutorial that can walk you through. 回答2: To compile code, you need a compiler. You can either use the Sun Oracle compiler or the

Using snprintf in a cross-platform application

元气小坏坏 提交于 2019-12-09 02:51:24
问题 I am writing a C program that is expected to be compiled with all major compilers. Currently I am developing on GCC on a linux machine and will compile on MSVC before committing the code. To make the cross-compiling easy, I am compiling with -ansi and -pedantic flags. This worked well until I started using snprintf which is not available in C89 standard. GCC can compile this without the -ansi switch but MSVC will fail always as it doesn't have C99 support. So I did something like, #ifdef

Java code compilation using JavaCompiler API and compilation errors handling

守給你的承諾、 提交于 2019-12-09 01:38:15
问题 I have the following Java code that compiles the given Java code using the javax.tools.JavaCompiler API: JavaCompiler compiler = ToolProvider.getSystemJavaCompiler(); ByteArrayOutputStream err = new ByteArrayOutputStream(); compiler.run(new FileInputStream("Test.java"), new FileOutputStream("Test.class"), err, "Test.java"); // Test.java contains the code of a simple Java class String compilationErrors = err.toString(); In the above code, all compilation errors are returned as one String

Evaluate expression as string, return object?

核能气质少年 提交于 2019-12-09 01:24:44
问题 Basically I have some code where when it happens, I need to set some object equal to some expression. All of this "what to do" jazz is stored as a string. So I parse it, and use reflection to find the object I am doing it to. Now I need to find out how to store the value to this object. The problem is the value could be "1", "1*(5/2)", or "some string value". It would be really cool if I could have expressions like "this.SomeProperty" or "(x > 3 ? 4 : 5)". Also, the object it is storing to,

F# performance question: what is the compiler doing?

谁都会走 提交于 2019-12-09 00:57:13
问题 Referencing this code: F# Static Member Type Constraints Why is, for example, let gL = G_of 1L [1L..100000L] |> List.map (fun n -> factorize gL n) significantly slower than [1L..100000L] |> List.map (fun n -> factorize (G_of 1L) n) By looking at Reflector, I can see that the compiler is treating each of these in very different ways, but there is too much going on for me to decipher the essential difference. Naively I assumed the former would perform better than the later because gL is

Generate C++ code where templates have been expanded

给你一囗甜甜゛ 提交于 2019-12-09 00:55:08
问题 I was wondering if there is a way to use a C++ compiler to just produce C++ code where all templates have been expanded to the instantiations that are required by the program. This code must exist at some point in the compilation process, although probably not in ASCII form by default, but it should not be too difficult to convert it back to readable C++ code in my opinion. EDIT: I am mostly interested in a solution that will produce actual C++ code (which at least compiles and ideally is

How to compile and link multiple python modules (or packages) using cython?

痴心易碎 提交于 2019-12-08 23:03:16
问题 I have several python modules (organized into packages), which depend on each other . e.g. Module1 Module2: imports Module1 Module3 Module4: imports Module3, Module 2, Module 1 Let's assume the relevant interface to develop applications is in Module4 and I want to generate a Module4.so using cython . If I proceed in the naive way, I get an extension Module4.so which I can import BUT the extension relies on the python source code of Module1, Module2, Module3. Is there a way to compile so that

When using two frames in emacs, how do I prevent the compilation buffer from showing up in both?

荒凉一梦 提交于 2019-12-08 22:42:19
问题 I work with two monitors, and often use emacs with two frames open; one for each monitor. each frame is split into two side-by-side windows, like so: a | b <-- frame 1 in monitor 1 ------- c | d <-- frame 2 in monitor 2 When I hit my 'compile' button while in window a, the compilation buffer opens in the buffer next to it. So far so good: a | compilation ----------------- c | d However, if I then move to window c to edit some stuff, then hit compile again, window d visits the compilation

Using memory barriers to force in-order execution

泪湿孤枕 提交于 2019-12-08 20:45:44
问题 Trying to go on with my idea that using both software and hardware memory barriers I could disable the out-of-order optimization for a specific function inside a code that is compiled with compiler optimization, and therefore I could implement software semaphore using algorithms like Peterson or Deker that requires no out-of-order execution, I have tested the following code that contains both SW barrier asm volatile("": : :"memory") and gcc builtin HW barrier __sync_synchronize : #include

Are there any advantages to compiling an assembly as x64?

人盡茶涼 提交于 2019-12-08 20:15:46
问题 Suppose I have a .Net Framework 3.5 SP1/CLR 2.0 application which needs to run on both x86 and x64 platforms. Suppose as well that for whatever reason, I need to create separate x86 and x64 installation programs. As I have an x64-specific installer anyway, would there be any benefit to recompiling the application itself as x64 rather than targeting "AnyCPU"? Does setting the target to x64 change anything at all besides the header information of the generated assembly? 回答1: If you specify x64