Execute .sh file in ubuntu on windows - c++

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...

Related

VS code c++ debugger setup using GDB does not work

So here's my problem. I have downloaded mingw g++ by using msys according to the official vs code website
Here are my files:
Now, when I try to build I get this error:
> Executing task: g++ -std=c++14 -g -o myfile.exe myfile.cpp <
cc1plus.exe: fatal error: myfile.cpp: No such file or directory
compilation terminated.
The terminal process "C:\Windows\System32\WindowsPowerShell\v1.0\powershell.exe -Command g++ -std=c++14 -g -o myfile.exe myfile.cpp" terminated with exit code: 1.
And if I do have a .exe file:
edit: I also started getting errors with
#include <iostream>
I would make this a comment if I could. What is the name of the file where you have written #include <iostream>?* I think if you change the name of that file to "myfile.cpp", you might stop getting that error. You will probably get a different error saying that "main() cannot be found" or something like that, but that's an improvement from your current spot.
*I see it's O3.cpp. Try changing that to myfile.cpp.

Preprocessor error: cblas.h: No such file or directory

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

Error message while compiling a program

I’m a newbie to C++ and Linux. There is this code I’m playing with that requires me to install the HElib (Homomorphic encryption library and other libraries - GMP, NTL) which I did. I want to compile the code (main.cpp) that has a header file (FHE.h) in HElib. My problem is how can I link FHE.h (in HElib folder) and main.cpp (in another folder) together so that I can compile them. I have tried some commands
g++ -I/Home/HElib/src/FHE.h main.cpp -o main
Error message
main.cpp:1:17: fatal error: FHE.h: No such file or directory
compilation terminated.
Another command line
g++ -I/Home/HElib/Src/FHE.h -I/Home/SimpleFHESum-master/SimpleFHESum-master/main.cpp -o main]
Error Message
g++: fatal error: no input files
compilation terminated.
What's wrong and how can I fix this?
The -I flag adds the following directory to the include path of the compiler. This enables you to write e.g. #include "FHE.h" even though that file is not located in the same folder as the source file you're trying to compile.
Have you tried just removing the 'FHE.h' part from your -I directive?
g++ -I/Home/HElib/src ...

Failing to compile GTest with Cygwin

I'm new to C++, I am trying to compile gtest with Cygwin. I have installed the GNU g++ compiler which works fine. I ran the following command on Cygwin:
g++ -I /cygdrive/c/devel/cpp/gtest/include -I /cygdrive/c/devel/cpp/gtest -pthread -c /cygdrive/c/devel/cpp/gtest/googletest/src/gtest-all.cc
/cygdrive/c/devel/cpp/gtest/googletest/src/gtest-all.cc:39:25: fatal error: gtest/gtest.h: No such file or directory
compilation terminated.
All the files seem to be in place, however the error does not go, any ideas why?
It looks like you have provided space between -I and path.
There should not be any space between -I and corresponding path.
It should be like
g++ -I/cygdrive/c/devel/cpp/gtest/include -I/cygdrive/c/devel/cpp/gtes..
Check it.

How to apply C++ preprocessor to a C++ header file on Ubuntu

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.