I am trying to write code that will compile on either mlton or mosml.
In my mosml I can exit on failure as follows.
Process.exit(Process.failure)
However when I try to reuse the same code and compile on mlton. It cannot find Process in its library set. Please let me know my options in terms of writing code that will work on either platform within one source code file.
The Process structure is a substructure of OS, so the following should work:
OS.Process.exit OS.Process.failure
See the Basis Library specification.
Related
I am newly learning c++. I am using the Linux ubuntu operating system and a sciTE text editor.
Do you know how to create a file on scite that I will be able to compile and then create an archive on terminal? also how do I create a 'make file. cpp'. Any help will be greatly appreciated.
Thanks! :)
Do you know how to create a file on scite that I will be able to compile and then create an archive on terminal?
You can use any text editor to write C++ source code. There is nothing very editor-specific about it. The file itself should be assigned a name that your compiler will recognize as designating a C++ source file. Compilers generally look at the filename extension for that purpose, and ".cpp" is a very common pattern recognized as indicating C++ source. It looks like that's what you're intended to use, so when you save the file just be sure to give it a name that ends in .cpp.
In order to successfully compile, you of course need to write valid C++ source code in the file, and in order to compile it to a program (I assume that's what you meant by "archive") it must contain a valid main() function.
how do I create a 'make file. cpp'.
I think you've gotten your instructions confused. Perhaps the instruction is just meant to convey what I already said about giving your source file a name ending in ".cpp". Alternatively, you may have been asked to create a makefile, which is input to the build tool "make", that could be used to build the program instead of running the compiler directly. You may ask specific questions about make here, but we are not in the business of writing full tutorials. The first thing you should do if you need instructions about make would be to consult your course materials and lecture notes, and / or ask your instructor.
On the third hand, make doesn't even need a makefile in some simple cases. It may be that you are instructed to build the program without a makefile. If you have named the source "prog.cpp" and it contains valid C++ source for a complete program, then you should be able to build that program via the command "make prog". In that case, the resulting program will be named "prog".
I have seen one other answer link but what I don't understand is what is basis.cm and what's it's use?
You are asking two questions.
What is basis.cm and what's it's use?
This is the Basis library. It allows the use of built-in functions.
How to compile and execute a stand-alone SML-NJ executable
Assuming you followed Jesper Reenberg's tutorial on how to execute a heap image, the next thing you need in order to have SML/NJ produce a stand-alone executable is to convert this heap image. One should hypothetically be able to do this using heap2exec, a tool that takes the heap image, e.g. the .x86-linux file generated on my system, and generates an .asm file that can be assembled and linked.
Unfortunately, this tool is not very well-maintained, so you have to
Go to the smlnj.org page and fix the download-link by removing 'www.' (this page and the SourceForge page don't contain the same explanations or assumptions about argument count, and neither page's download link work).
Download and extract this tool, and fix the 'build' script so it points to your ml-build tool
Fix the tool's argument use by changing [inf, outf] to [_, inf, outf]
Run ./build which generates 'heap2asm.x86-linux' on my system
For example, in order to generate an .asm file for the heap2asm program itself, run
sml #SMLload heap2asm.x86-linux heap2asm.x86-linux heap2asm.s
At this point, I have unfortunately been unable to produce an executable that works. E.g. if you run gcc -c heap2asm.s and ld heap2asm.o, you get a warning of a missing _start label. The resulting executable segfaults even if you rename the existing _sml_heap_image label to _start. That is, it seems that a piece of entry code that the runtime environment normally delivers is missing here.
At this point, discard SML/NJ and use MLton for producing stand-alone binaries.
I need to convert a simple OCaml file into JAR file so that I can run atop JVM platform.
This OCaml file needs to use the Big_int module. There is this line of code
open Big_int
But it always returns me this line of error Error: Reference to undefined globalBig_int'` when I try to run ocamljava to convert it into jar file.
ocamljava -o myprog.jar source.ml
I am able to see big_int.cmi, big_int.cmj, big_int.cmx, big_int.mli, nums.cma, nums.cmja, etc on this directory /Users/myname/.opam/ocamljava-2.0-alpha2/lib/ocaml. I know that the Big_int is residing inside these libraries; but I don't know how to link them into compilation.
By the way, I'm using OCamlJava 2.0.
Erencie,
Entering open Big_int only accesses the compiled interface (.cmi file) for big_int, but does not load the implementation of big_int.
Implementations for user modules can be entered with the #load directive.
In your case, you want to do the following:
#load "file-name";;
This is going to load in memory a bytecode object file (.cmo file) or library file (.cma file) produced by the batch compiler ocamlc.
Thus you should do the following:
#load "big_int.cmo";;
If the object file for big_int does not exist yet, you should compile big_int.ml first.
Please let me know if you have any questions!
You should probably add the "nums" library to the command-line, as in:
ocamljava nums.cmja source.ml
Also note that the implementation of "nums" in OCaml-Java has been only
lightly tested, and may contain bugs. If you encounter a bug, it would
be nice to report it at https://github.com/xclerc/ocamljava.
I have a C++ project in Ubuntu 12.04. To run the project the make file requires the following files:
1-All the .cpp files
2-All the .h files
3-Three shared libraries.
The project is fully functionall and performs according to the specifications. All the required .cpp files and .h files are available. The problem is that there is no main() function in any of the source files and the program entry point resides in one of the three shared libraries. My job is to find out the program execution pipeline and without having any main file I am not able to do that. I can't run the project in any IDE (i.e: eclipse) because there is no main function available.
Question: Can you please tell me how to find the program entry point?
P.S: I will be glad to provide any kind of information or material you may need to solve my problem.
Edit: The CMakeLists.txt file available here.
Edit 2: The build.sh file available here.
To find enty point look into each shared object with:
nm $library | egrep "T main$"
Library with main() will output something like
090d8ab0 T main
Very usefull way to visualize execution tree is to run:
valgrind --tool=callgrind ./my_executable -arg -arg ....
(you can abort execution early with Ctrl+C)
This will output callgrind.<pid> file. To visualize it run kcachegrind callgrind.<pid>.
You will need valgrind:
sudo apt-get install valgrind
and kcachegrind
sudo apt-get install kcachegrind
Build it with the debug option -g and step into the program with a debugger like gdb (or cgdb or ddd). You'll need any appropriate debug libraries libraries though.
Short of that, play with the code a bit. Try putting printf or cout statements that print internal variables in any functions that look important, and see what the program status is and how frequently they get called. If main is hidden in a library, there's probably another function somewhere that behaves like main for the purposes of the API provided by whatever library has the real main.
What's the API documentation for your libraries? (is this a school project?). It sounds odd to have a hidden main and not say anything about it.
In case you use a build system (CMake, SCons, ...) it is highly possible that the build system is also generating some files, and one of them might be containing the main() method. We use this methodology when we generate the main function in order to instantiate classes for libraries that were specifically selected in CMake-gui.
And again, it is possible that the build system deletes the generated files due to some obscure policy the original developers thought of but didn't tell you. So search through your build system files, see what is actually happening there.
Edit
So, after seeing you CMakeLists.txt:
check ${DIR_EXT}/covis/src/ci.cpp where DIR_EXT is SET( DIR_EXT "../ext/" CACHE PATH "Folder holding external libraries" )
See what's in there and let us know :)
Edit2
After seeing build.sh (execute steps in order):
1.
change
`cmake -D COMPILE_BINARY=ON ..`
to
`cmake -D COMPILE_BINARY=ON -DCMAKE_BUILD_TYPE=Debug ..`
and add the same -DCMAKE_BUILD_TYPE=Debug to the other cmake command too.
This will build your library and executable in debug mode.
2.
Now, in one of the c++ source files you have access to and you are sure will be called (the earlier the function will be calle the better), add:
asm("int $0x03");
This will create a breakpoint in your application.
(If you do not want to use this, see below).
3.
Build your application.
4.
Run it via a debugger in terminal:
gdb ./myapplication <ENTER>
(this will give you a gdb prompt)
(if you did not add the asm breakpoint from above, type in the gdb prompt: break filename.cpp:linenumber or break methodname to add a gdb breakpoint).
run <ENTER>
Now your application should stop in your function when it is executed.
You are still in the gdb prompt, so type:
bt <ENTER>
This will print out the backtrace of your application. Somewhere you should see a main function, together with filename and linenumber.
However, that setnames.sh looks interesting, see if it does not do anything funny :)
I have a working C-extension for Racket. In the Racket CLI and the interactions window of DrRacket it works like a charm. However, I can't get it to work in the definitions window of DrRacket, which would be really useful as that is the interface for my students to develop their programs.
The problem seems to be that definitions in the extension are not 'seen' (or registered or something). The module is loaded (or at least found) but DrRacket complains that it doesn't have execute permission for it, which I don't understand.
In the C code I declared the extension to be a module and I tried both inclusion methods:
(load-extension "racket_extension.so")
and
(require "racket_extension.rkt") ; which requires you put it in a folder relative to the current working folder as follows:
"compiled/native/x86_64-linux/3m/racket_extension_rkt.so"
Neither method works. The first case gives no error, but the definitions of the external are not registered ("undefined").
In the second case DrRacket gives an error:
forbidden (execute) access to ....compiled/native/x86_64-linux/3m/racket_extension_rkt.so
but why?
Does anyone have ideas how I can get this to work? What am I missing?
Thanks!
Marc
How are you compiling and linking your extension? Are you using the raco ctool or gcc? Are you executing DrRacket within the same directory as your compiled directory? The way I usually test my extensions is to execute: drracket my_ext_test.rkt in the same directory as my compiled directory. That has been an issue for me in the past. Also, if it says the action is forbidden, did you try changing the permissions of your .so? Maybe it's something as simple as that. I'd start with the simple example Writing Racket Extensions and make sure that you can get the hello world program to work in the definitions window. I personally have never had the problem you have mentioned, but I am also running on Linux.