module Hello
{
config const message: string = "Hello, world!";
proc main()
{
writeln( message );
}
}
The program compiles fine with no errors, but my attempt to run gives the following errors.
./hello2-module.chpl: line 1: module: command not found
./hello2-module.chpl: line 4: syntax error near unexpected token `('
./hello2-module.chpl: line 4: ` proc main()'
Something is not right.
You don't indicate how you are trying to run the generated executable, but from the output you show, it appears that you might be trying to run the Chapel source file (e.g., ./hello2-module.chpl) rather than the compiler-generated executable (e.g., ./Hello with a recent version of Chapel or ./a.out with an older one).
Related
I upgraded my ocaml to 4.03.0.
Then, some wrapper libraries failed to build raising "No implemntations provided" Error.
I prepare a small example to explain my situation.
I write a C code in hello_stubs.c
#include<stdio.h>
#include<caml/mlvalues.h>
CAMLprim value caml_print_hello(value unit)
{
printf("Hello\n");
return Val_unit;
}
Next, I prepare the interface file for ocaml, in hello.mli.
external print_hello : unit -> unit = "caml_print_hello"
Then, I code a main program in main.ml
Hello.print_hello();;
To compile these programs, I executed the following commands.
ocamlc -c hello.mli
ocamlc -c hello_stubs.c
ocamlopt -o main main.ml hello_stubs.o
Then, unfortunately, the last command failed with the following error message.
File "_none_", line 1:
Warning 58: no cmx file was found in path for module Hello, and its interface was not compiled with -opaque
File "main.ml", line 1:
Error: No implementations provided for the following modules:
Hello referenced from main.cmx
According to the message,
I've tried ocamlc -opaque hello.mli, but it didn't solve the problem.
I also confirmed that the commands above work fine for ocaml 4.02.3.
Do you know how to compile this example with ocaml 4.03.0?
The fix is easy: create hello.ml of the same contents of hello.mli and compile it and link for main.
I guess this is due to the following change of 4.03.0:
PR#4166, PR#6956: force linking when calling external C primitives
(Jacques Garrigue, reports by Markus Mottl and Christophe Troestler)
The related section of the reference manual should be updated. See http://caml.inria.fr/mantis/view.php?id=7371
I am trying to compile code using gcc and run the executable, but it is throwing error:
gcc somefile.c -o somefile
compilation goes through successfully. But, when I try to execute it:
$sh somefile
It results in: Syntax error: "(" unexpected. Among the output files, I dont see somefile.o, but instead, I see somefile.c~
The contents of the file:
#include <stdio.h>
int main(int argc, char *argv[])
{
printf("hi");
}
Context: I am new to programming in linux, and wanted to start out with simple programs. I am running ubuntu 64 bit on a virtual machine, with gcc, g++, etc installed. After that I created a sample file as mentioned above ("somefile.c"), and tried the steps mentioned above, but could not execute. My goal is to compile and execute a sample C or Cpp code on ubuntu using gcc or g++. Please help.
your somefile is executable binary, it's not shell script. you should execute it by:
$./somefile
To execute file you just have to do
$./somefile
sh is used when you've to execute a shell script
I just moved over to a new MacBook Air (10.8) and a 64-bit project that compiled before gives me Shell Script Invocation Error: /bin/sh failed with exit code 2
It looks like XCode 4.6 is failing on one of the intermediate files, saying unexpected EOF while looking for matching '"' in a file ending in .sh:
/Users/billferster/Library/Developer/Xcode/DerivedData/MovingPicture-hcmztqjnatzylkburxulgmdynyqg/Build/Intermediates/MovingPicture.build/Debug/MovingPicture.build/Script-E004D330137B9E5B00FDC604.sh: line 6: unexpected EOF while looking for matching `"'
/Users/billferster/Library/Developer/Xcode/DerivedData/MovingPicture-hcmztqjnatzylkburxulgmdynyqg/Build/Intermediates/MovingPicture.build/Debug/MovingPicture.build/Script-E004D330137B9E5B00FDC604.sh: line 7: syntax error: unexpected end of file
Command /bin/sh failed with exit code 2
Any ideas how to fix this?
Thank
Bill
it was was it said it was. A missing "
Here is the code I have- not sure why I am getting this error message:
$ ./main.cpp "hello" "is"
./main.cpp: line 4: syntax error near unexpected token `('
./main.cpp: line 4: `int main(int argc, char *argv[]){'
It compiles fine in g++, but when I run it, I get the above error. Any idea why? Here is my complete code..
#include <iostream>
#include <fstream>
int main(int argc, char *argv[]){
for(int i = 0; i < argc; i++){
std::cout << argc << " : " << argv[i] << '\n';
}
if (argc != 2){
std::cout << "\nUSAGE: 2 command line arguments please." << std::endl;
std::cout << "\n (1) Input file with raw event scores.\n (2) Output file to write into.";
}
// open the font file for reading
std::string in_file = argv[1];
std::ifstream istr(in_file.c_str());
if (!istr) {
std::cerr << "ERROR: Cannot open input file " << in_file << std::endl;
}
return 0;
}
You have to run the compiled program, not the source code:
$ g++ -o main main.cpp
$ ./main "hello" "is"
3 : ./main
3 : hello
3 : is
USAGE: 2 command line arguments please.
(1) Input file with raw event scores.
(2) Output file to write into.ERROR: Cannot open input file hello
Your example is trying to execute C++ code as a shell script, which isn't going to work. As you can see from the output of my test run of your program here, you still have some bugs to work out.
As both the other answers say, you're running it as a shell script, implicitly using /bin/sh.
The first two lines starting with # are treated by the shell as comments. The third line is blank, and does nothing. The fourth line is interpreted as a command int, but parentheses are special to the shell, and are not being use correctly here. There probably isn't an int command in your $PATH, but the shell doesn't get a chance to report that because it chokes on the syntax error.
None of these details are particularly important; the problem is that you're executing the program incorrectly. But it might be interesting to see why those specific error messages are printed.
And it appears that you've done something like chmod +x main.cpp; otherwise the shell would have refused to try to execute it in the first place. Making a C++ source file executable isn't going to cause any real harm (as long as it's readable and writable), but it's not at all useful, and as you've seen it delayed the detection of your error. If you do chmod -x main.cpp, and then try ./main.cpp again, you'll get a "Permission denied" error instead.
As Carl's answer says, you need to execute the executable file generated by the compiler, not the C++ source file. That's why there's a compiler. The compiler (well, actually the linker) will automatically do the equivalent of chmod +x on the executable file it generates.
The file command will tell you what kind of file something is, which affects what you can do with it. For example, using your code on my system, after running g++ main.cpp -o main:
$ file main.cpp
main.cpp: ASCII C program text
$ file main
main: ELF 32-bit LSB executable, Intel 80386, version 1 (SYSV), dynamically linked (uses shared libs), for GNU/Linux 2.6.24, BuildID[sha1]=0xacee0dfd9ded7aacefd679947e106b500c2cf75b, not stripped
$
(The file command should have recognized main.cpp as C++ rather than as C, but sometimes it guesses wrong.)
"ELF" is the executable format used by my system; the file contains executable machine code plus some other information. The pre-installed commands on the system use the same format.
The details may differ on your system -- and will differ substantially on non-Unix-like systems such as MS Windows. For example, on Windows executable files are normally named with a .exe extension.
The compiler, by default, creates an executable called "a.out", so you want to do:
$ a.out "hello" "is"
Typing "./main.cpp" is trying to execute the C++ source file, probably as a shell script
I am new to Linux Ubuntu 11.10 and have basic C++exposure.
I installed the g++ by
sudo apt-get install build-essential
and created a directory cpp in my home directory. I then wrote a program hello.cpp in my cpp directory
#include <iostream>
using namespace std;
int main() {
cout << "Hello !" ; return 0;
}
and compiled using
g++ -W hello.cpp -o hello
The program compiles without any errors/warnings. When I try to execute the file
./hello.cpp
I get error messages:
line 3: using: command not found
line 6: syntax error near unexpected token `('
line 6: `int main() {'
I tried looking at a lot of posts but could not resolve this. I have MS VisualStudio on Windows, but I would rather learn C++ on Ubuntu. Thanks in advance.
I think that the problem is that you're trying to execute the .cpp source file rather than the generated executable. Try running ./hello instead of ./hello.cpp, since hello is the actual executable. The errors you're currently getting are caused by the shell interpreter choking on C++ syntax, since it's trying to run it as a shell script.
Hope this helps!