I am using the gfortran to compile a big program with a dozen of modules. Whenever there is an error in the code the program generates an error message with the line number where the error has happened and full path of the module that the line belongs to. For example:
At line 1775 of file C:\temp\test.f90 (Unit = 200, file=' ')
Fortran Run time error: File '*' does not exist
My question is how do you stop the program from listing the full path of the offending module and rather make it only report the module name where the error has happened.
gfortran embeds the path that was used to access the source file during the compilation phase. E.g. if you compile with the full path to the file you will get the full path in the debug output. If you compile with the relative path you will get the relative path in the output:
~/tests[520]$ gfortran -o test.x test.f90
~/tests[521]$ test.x
At line 3 of file test.f90 (unit = 200, file = '')
Fortran runtime error: File '' does not exist
~/tests[522]$ gfortran -o test.x ./test.f90
~/tests[523]$ test.x
At line 3 of file ./test.f90 (unit = 200, file = '')
Fortran runtime error: File '' does not exist
~/tests[524]$ gfortran -o test.x ~/tests/test.f90
~/tests[525]$ test.x
At line 3 of file /home/username/tests/test.f90 (unit = 200, file = '')
Fortran runtime error: File '' does not exist
Change your compilation commands to only access the source using relative paths.
Related
I am trying to see the output of a preprocessed .cpp file using the g++ compiler. I am doing this in the Windows command prompt. I type in g++ -E file.cpp in the command line but I get the error: cblas.h: No such file or directory
How do I go about fixing this problem?
You can install lapack from here
I'm writing some code for an assignment for a CS class at my university. This program is supposed to read in a .DAT file from the command line, assign the values in the file to an array, and then take that array and compute its average. The only issue I have is that I keep getting this error when I try to compile my code:
/usr/bin/ld:seven.dat: file format not recognized; treating as linker script
/usr/bin/ld:seven.dat:1: syntax error
collect2: error: ld returned 1 exit status
I've tried looking around on Google/StackOverflow a bit, but my programming knowledge is too limited to really understand what's going on, so I have no idea where my errors are. I'm compiling the program with this command:
g++ lab5.1.cpp seven.dat -Wall -o myprog
I can post some/all of the code if needed also.
The problem is that you are trying to compile the .dat file as part of the build process when creating your myprog executable. That is wrong. Build the executable first, then pass the .dat file to your program when you run it, eg:
g++ lab5.1.cpp -Wall -o myprog
myprog seven.dat
Inside your code, you will receive the seven.dat filename in your main() function's argv[] parameter. You can then open the .dat file and read its content as needed.
I have created a file, 1.sh, as
c++ -c file1.cpp
c++ file1.o -o file1
And I tried to execute it on bash Ubuntu on windows. It tells me
: No such file or directory
c++: fatal error: no input files
compilation terminated.
However, if I execute
c++ -c file1.cpp
c++ file1.o -o file1
directly, the file (file1.cpp) can be complied normally.
My question is, what is the reason .sh file does not work and how to fix it?
Actually, I would like to write this as comment but there is not this formatting available. (I will delete this answer when it becomes obsolete.)
I just tried this (with g++ on cygwin's bash):
$ g++ -c nothing.cc
g++: error: nothing.cc: No such file or directory
g++: fatal error: no input files
compilation terminated.
$
Of course, where is no file nothing.cc in my current working directory...
So, it might be that my guess (C++ is running in the wrong working directory when started from shell script) might be reasonable...
As I already suggested: insert a
echo "$PWD"
at the beginning of your shell script to be sure.
Update:
Out of curiosity, I tried this also (cygwin, bash again):
$ c++ -c nothing.cc
c++: error: nothing.cc: No such file or directory
c++: fatal error: no input files
compilation terminated.
$
Now, it looks very similar to the OP.
The only fact that's puzzling me: The error message of the OP looks like whether the compiler didn't get any input:
$ c++
c++: fatal error: no input files
compilation terminated.
$
but I believe that's not the case because in the OP it starts with
: No such file or directory.
Thus, it rather looks like there is missing some text...
I tried to apply preprocessor to a C++ header file with Macros using the below command.
$ g++ -E heap.h
And I wasn't able to get the preprocessed header file, because preprocessing was finished with the below error.
...
...
# 9 "heap.h" 2
heap.h:10:28: fatal error: src/allocation.h: No such file or directory
To tell g++ about the directories that includes header file included in heap.h, I typed the below command, but it showed the same error.
$ g++ -E heap.h -I .
...
...
heap.h:10:28: fatal error: src/allocation.h: No such file or directory
Can you leave the solution of this problem if you have an experience that you solve this problem?
The steps:
You may need to change to the directory from where your build system invokes the command if the command does not use absolute paths.
Copy the compiler command line from your make/cmake/etc. output.
Add -E switch.
Add/change -o parameter to <source>.i.
Using fork() and execlp(), I'm trying to compile a cpp file to a .so. I'm running a copied g++-4.8 executable that's in my project's directory tree. When run from the terminal, everything goes smoothly and I end up with a working dynamic library, but when I make a child process and use execlp to do the same thing, I get an error:
g++-4.8: error: ###: No such file or directory
This is repeated 6 times with a few characters in the "filename" changed around a bit. To compare, this is what I write in the terminal:
$ g++/bin/g++-4.8 -fPIC -shared bob.cpp -o bob.so
...and this is the code that generates the error:
if (fork() == 0) {
execlp("g++/bin/g++-4.8", "g++/bin/g++-4.8", "-fPIC", "-shared", "bob.cpp", "-o", "-bob.so");
}
bob.cpp is in the working directory of the parent process, and the terminal code is executed from that same directory.
### is a typical sequence from the header of a binary (ELF) file. You forgot to NULL terminate your argument list to execlp(), so it read garbage and tried to pass it to g++.