samedi 29 octobre 2022

exe file from c++ code does not work when compiled from cmd [duplicate]

I'm writing a c++ project in Clion I have 3 files: main.cpp FileOperations.h FileOperations.cpp

#include <iostream>
#include <string>
#include <sstream>
#include "FileOperations.h"

using namespace std;

int main() {


    cout << "hello" << endl;

    /*string inputFileName;

    cin >> inputFileName;

    vector<string> inputs = FileOperations::readFromFile(inputFileName);


    for (const string& line:inputs) {

        cout << line << endl;

    }*/


}

This is my main func. Right now it is only supposed to print hello to the screen. When I compile from command line with different ways, it behaves differently. And it works on Clion automated run

g++ main.cpp FileOperations.cpp -o myProgram
./myProgram 

It does not give any output when I do so as above in Clion, also when I do it a with windows terminal, exe file is broken

There must be a problem with linking but why ?

And FileOperations.o file is created so there are no compiler errors? Why do I have a problem with exe file even though I have no errors?

(g++ main.cpp -o myProgram works)

Aucun commentaire:

Enregistrer un commentaire