Using separate files in C++


#1

I have a very simple program which I want to separate into different files and Atom gives me the following wrror message

C:\Users\Tyskland\AppData\Local\Temp\ccO5xkY3.o:Main.cpp:(.text+0xc): undefined reference to `hello()’
collect2.exe: error: ld returned 1 exit status.

The program files are:

Main.cpp
#include “Output.h”
int main(){
hello();
return 0;
}
Output.cpp
#include “Output.h”
using namespace std;
void hello(){
cout << “Hello world!” << endl;
}

Output.h
#include
void hello();

How come this simple program is not executed in Atom?


#2

Atom isn’t giving you anything. Atom has no ability to run code. You are using a package to invoke the compiler g++ and the compiler is giving you an error. Based on the path that the compiler returns (C:\Users\Tyskland\AppData\Local\Temp\ccO5xkY3.o:Main.cpp), I’m gathering that the package is creating a temporary file with the contents of main.cpp.

What package are you using and what steps are you following to run your code?


#3

I’m using the gpp-compiler 3.0.7. I’m just running the compiler on Main.cpp with the short command that comes with the compiler.


#4

Open the gpp-compiler settings (Settings -> Packages -> gpp-compiler) and tell me if the setting Compile to Temporary Directory is checked. If so, please uncheck it and try again.


#5

Uncheking it did not solve the problem.


#6

Then you will probably have to ask the package author for more expert help. Unfortunately, it’s an old package that hasn’t been updated in a while, so maybe a better option would be to find a different package. I like process-palette for automating command line instructions.


#7

This post was flagged by the community and is temporarily hidden.