Error when I compile C++ project using class function


Dear all,

I got an issue when compiling C++ project using class function. My project has 3 files including main.cpp, PML_1D.h and PML_1D.cpp.

I ran on the file main.cpp and received the following errors. I don’t know why I got these errors while I added #include “PML_1D.h” in the file main.cpp.

/tmp/ccNZOi2K.o: In function main': main.cpp:(.text+0x17): undefined reference toPML_1D::PML_1D()'
main.cpp:(.text+0x26): undefined reference to PML_1D::initialize()' main.cpp:(.text+0x35): undefined reference toPML_1D::execute()'
main.cpp:(.text+0x44): undefined reference to PML_1D::finalize()' main.cpp:(.text+0x62): undefined reference toPML_1D::~PML_1D()'
main.cpp:(.text+0x78): undefined reference to `PML_1D::~PML_1D()'
collect2: error: ld returned 1 exit status

Could anyone help me please? Thank you in advance.
Hoang An


Is there anyone who can help me?


It’s hard to help because it depend 100% on the source code, and not on atom. A beginner programmer forum is probably the right place to get help with that.

I added #include “PML_1D.h” in the file main.cpp.

Did you added it to PML_1D.cpp too ?

If yes, I’ll point to this stackoverflow answer that list possible causes


Thank you for your reply.

Yes. I added it to PML_1D.cpp. I ran my project on Netbeans and Eclipse, it works well. I don’t know why it doesn’t work on atom. Thank you for your suggestion on stackoverflow.

Hoang An


I think I had the same problem. You could test if you compile this and exchange your compiler in your settings by this. In my case the class.cpp files were not included in the arguments

int main(int argc, char* argv[])
  std::ofstream outF("arguments.txt");

  outF << "printing arguments:" << endl;

  for(int i = 0; i < (int)argc; i++)
    outF << "arg[" << i << "]: " << argv[i] << endl;

  outF << "end" << endl;

For reference + workaround: Gpp-compiler won't compile when using more than 1 file