Closed. This question is not reproducible or was caused by typos. It is not currently accepting answers.
This question was caused by a typo or a problem that can no longer be reproduced. While similar questions may be on-topic here, this one was resolved in a way less likely to help future readers.
Closed 4 years ago.
Improve this question
I'm running a .cpp file and trying to print out to the screen for debugging purposes, however my message does not appear. I'm running my program from the Linux Terminal using the following command:
g++ -m32 -static genConfig.cpp -o genConfig
All that my .cpp file should do at this point is cout to the terminal as show below. However the output doesn't appear.
#include <string>
using namespace std;
int main(int argc, char ** argv) {
cout<<"HEYYYA";
}
The command g++ -m32 -static genConfig.cpp -o genConfig does not run the application, it compiles (and links) it. In order to run the generated binary, you need to execute ./genConfig.
Also, you need #include <iostream> and actually #include <string> is not needed (at least not for this specific portion of code).
Related
Closed. This question is not reproducible or was caused by typos. It is not currently accepting answers.
This question was caused by a typo or a problem that can no longer be reproduced. While similar questions may be on-topic here, this one was resolved in a way less likely to help future readers.
Closed 5 days ago.
Improve this question
Compiling with
g++ detect_version.cpp -o detect_version.exe
and running the following program:
int main()
{
std::cout << "Version is: " << __cplusplus;
return 0;
}
Gives me: "Version is: 201703" which is C++17 that should contain <view_string>
However if write
#include <view_string>
It gives me:
detect_version.cpp:3:10: fatal error: view_string: No such file or directory
3 | #include <view_string>
| ^~~~~~~~~~~~~
compilation terminated.
Under MSYS2 MinGW libstdc++ should be mingw-w64-x86_64-gcc-libs and from that I do have the latest version:
$ pacman -Q | grep mingw-w64-x86_64-gcc-libs
mingw-w64-x86_64-gcc-libs 12.2.0-10
What could be the problem?
Closed. This question is not reproducible or was caused by typos. It is not currently accepting answers.
This question was caused by a typo or a problem that can no longer be reproduced. While similar questions may be on-topic here, this one was resolved in a way less likely to help future readers.
Closed 4 years ago.
Improve this question
I've just written the following into the console:
g++ -o main.cpp main
and my main.cpp is gone.
Did I just lose my 3 hours of work?
Yes, you did. The -o flag specifies the output file (main.cpp in your case since that's the file name immediately following it):
g++ -o main.cpp main
\_________/ \__/
\ \_This is the input file.
\_____This specifies the output file.
In other words, you have told the compiler to try and compile what would normally be your executable, and write the results to your source file (overwriting it). A more suitable command would have been:
g++ -o main main.cpp
This is one of those educating moments that developers experience from time to time (including old hacks like me), the sort of thing that should convince you to do regular commits to git (or other source control system), or compile code with a build system rather than possibly complex command lines.
Closed. This question is not reproducible or was caused by typos. It is not currently accepting answers.
This question was caused by a typo or a problem that can no longer be reproduced. While similar questions may be on-topic here, this one was resolved in a way less likely to help future readers.
Closed 4 years ago.
Improve this question
I can't get integer from user, when i try cin >> n; (where n is int variable)
it gives some strange error. Other inputs like character, double float works fine.
I was using DevC++, but now I also tried it on command line gcc, the error is still there :
undefined reference to 'std::cin'
undefined reference to `std::istream::operator>>(int&)'
...
#include<iostream>
using namespace std;
int main()
{
int n;
cin >> n;
}
it works fine if I change n to a float type or double type variable.
Tried on Bloodshed DevC++,
MinGw gcc
Try with g++ :
g++ program.cpp -o a.out
Or with gcc (If you add the c++ runtime library) :
gcc program.cpp -o a.out -lstdc++
Closed. This question is not reproducible or was caused by typos. It is not currently accepting answers.
This question was caused by a typo or a problem that can no longer be reproduced. While similar questions may be on-topic here, this one was resolved in a way less likely to help future readers.
Closed 6 years ago.
Improve this question
I have the following test.cpp file :
#include <unistd>
int main()
{
return 0;
}
I just want to compile this but I still have the following :
$ g++ test.cpp
test.cpp:1:18: fatal error: unistd: No such file or directory
#include <unistd>
^
compilation terminated.
I found unistd.h at /usr/include/unistd.h. and my $LD_LIBRARY_PATH environment variable was empty so I set it at /usr/include (with export LD_LIBRARY_PATH=/usr/include) but the problem remains.
What could I do?
The name of the header is unistd.h, not unistd. And LD_LIBRARY_PATH is used to locate shared libraries, not header files.
Closed. This question is not reproducible or was caused by typos. It is not currently accepting answers.
This question was caused by a typo or a problem that can no longer be reproduced. While similar questions may be on-topic here, this one was resolved in a way less likely to help future readers.
Closed 8 years ago.
Improve this question
it keeps telling me
gcc hello.cpp -o hello
gcc: error: hello.cpp: No such file or directory
gcc: fatal error: no input files
compilation terminated.
please anyone help
The source file needs to be in the same path you invoke gcc or you can put the full path in there
gcc /home/username/Desktop/hello.cpp
or you can do cd /home/username/Desktop then invoke gcc from that given path.
set your current directory where the .cpp file is