im trying to use CMake for the first time to compile a c++ file.
test.cpp :
#include <iostream>
int main(){
std::cout << "Hello World" << std::endl;
return 0;
}
CMakeLists.txt :
cmake_minimum_required(VERSION 3.0)
set(CMAKE_BUILD_TYPE Debug)
set(CMAKE_CXX_FLAGS "${CMAKE_CXX_FLAGS} -std=c++17")
project(Void)
add_executable(
output
tests/test.cpp
)
i made the Makefile (Compiler : GNU) successfully, but when using the make command to compile, i get these errors
output :
Consolidate compiler generated dependencies of target output
[ 50%] Linking CXX executable output
C:/msys64/mingw64/bin/../lib/gcc/x86_64-w64-mingw32/10.3.0/../../../../x86_64-w64-mingw32/bin/ld.exe: CMakeFiles/output.dir/tests/test.cpp.obj:C:/Users/admin/Desktop/SharedWork/C++/Void/tests/test.cpp:5: undefined reference to std::basic_ostream<char, std::char_traits<char> >& std::operator<< <std::char_traits<char> >(std::basic_ostream<char, std::char_traits<char> >&, char const*)'
C:/msys64/mingw64/bin/../lib/gcc/x86_64-w64-mingw32/10.3.0/../../../../x86_64-w64-mingw32/bin/ld.exe: CMakeFiles/output.dir/tests/test.cpp.obj: in function main':
C:/Users/admin/Desktop/SharedWork/C++/Void/tests/test.cpp:5: undefined reference to std::ostream::operator<<(std::ostream& (*)(std::ostream&))'
C:/msys64/mingw64/bin/../lib/gcc/x86_64-w64-mingw32/10.3.0/../../../../x86_64-w64-mingw32/bin/ld.exe: CMakeFiles/output.dir/tests/test.cpp.obj:C:/msys64/mingw64/include/c++/10.3.0/iostream:74: undefined reference to std::ios_base::Init::~Init()'
C:/msys64/mingw64/bin/../lib/gcc/x86_64-w64-mingw32/10.3.0/../../../../x86_64-w64-mingw32/bin/ld.exe: CMakeFiles/output.dir/tests/test.cpp.obj:C:/msys64/mingw64/include/c++/10.3.0/iostream:74: undefined reference to std::ios_base::Init::Init()'
C:/msys64/mingw64/bin/../lib/gcc/x86_64-w64-mingw32/10.3.0/../../../../x86_64-w64-mingw32/bin/ld.exe: CMakeFiles/output.dir/tests/test.cpp.obj:test.cpp:(.rdata$.refptr._ZSt4endlIcSt11char_traitsIcEERSt13basic_ostreamIT_T0_ES6_[.refptr._ZSt4endlIcSt11char_traitsIcEERSt13basic_ostreamIT_T0_ES6_]+0x0): undefined reference to std::basic_ostream<char, std::char_traits<char> >& std::endl<char, std::char_traits<char> >(std::basic_ostream<char, std::char_traits<char> >&)'
C:/msys64/mingw64/bin/../lib/gcc/x86_64-w64-mingw32/10.3.0/../../../../x86_64-w64-mingw32/bin/ld.exe: CMakeFiles/output.dir/tests/test.cpp.obj:test.cpp:(.rdata$.refptr._ZSt4cout[.refptr._ZSt4cout]+0x0): undefined reference to std::cout'
collect2.exe: error: ld returned 1 exit status
make[2]: *** [CMakeFiles/output.dir/build.make:97 : output] Erreur 1
make[1]: *** [CMakeFiles/Makefile2:83 : CMakeFiles/output.dir/all] Erreur 2
make: *** [Makefile:91 : all] Erreur 2