I made a small test project in C++ and in CLion IDE:
main.cpp
#include "testclass.h"
int main() {
testclass *test = new testclass();
test->foo();
return 0;
}
testclass.cpp
#include <iostream>
#include "testclass.h"
using namespace std;
void testclass::foo(){
cout << "Hello, World!" << endl;
}
testclass.h
class testclass {
public:
void foo();
};
CMakeLists.txt
cmake_minimum_required(VERSION 3.9)
project(untitled1)
set(CMAKE_CXX_STANDARD 11)
add_executable(untitled1 main.cpp)
The CMakeList.txt is created by the IDE automatically and I haven't changed it. When I try to run this simple program I get the following errors:
CMakeFiles/untitled1.dir/main.cpp.o: In function `main':
/home/irene/CLionProjects/untitled1/main.cpp:7: undefined
reference to `testclass::foo()'
collect2: error: ld returned 1 exit status
Can someone help me understand what am I doing wrong?