1
cd "/home/furkan/Desktop/denemee/" && g++ Untitled-1.cpp -o Untitled-1 && "/home/furkan/Desktop/denemee/"Untitled-1
/usr/lib/gcc/x86_64-linux-gnu/7/../../../x86_64-linux-gnu/Scrt1.o: In function `_start':
(.text+0x20): undefined reference to `main'
collect2: error: ld returned 1 exit status

it gives such an error. what should I do?

code:

#include<iostream>

using namespace std;

int main()
{
    cout << "hello world" << endl;
    return 0; 
}
3
  • It appears the Visual Studio Code IDE isn't used in your shell commands (Are you running these commands from an integrated terminal in the IDE?). You should remove the VS Code tag and give additional info on your operating system, version of g++, etc. The code in itself works.
    – PhilDenfer
    Commented Oct 23, 2019 at 14:35
  • My guess is that the gcc compiler (g++) doesn't find a main function in your file, maybe because the file is incorrect, line endings, etc. Can you try this: echo "int main(){return 42;}" | g++ -x c++ -o runme - && ./runme ? If the program is compiled, it will run and return the exit code 42, that you can check right after ./runme by using the command echo $?.
    – PhilDenfer
    Commented Oct 23, 2019 at 14:47
  • Welcome to the site, by the way. You should be aware that Super User is a Stack Exchange site dedicated to questions about computer software or computer hardware. Stack Overflow, on the other hand, can help you with coding, algorithm, or language problems.
    – PhilDenfer
    Commented Oct 23, 2019 at 14:52

1 Answer 1

-1

Try saving your code, vscode tends to leave the work to your hand, thus making you run gcc on an empty file which leads to main() undefined.

Try 'cd' to your code base's path and 'cat' your file out to see.

You must log in to answer this question.

Not the answer you're looking for? Browse other questions tagged .