So I have created a simple function to get the current date and time. It works fine when I am testing it in Visual Studio on my Windows machine.
These are the directories included in order for my date time function to work:
#include <ctime>
#include <cstring>
#include <cstdlib>
Adding these to the top of my c++ program in Visual Studio will work fine, but when I try to compile it using GCC on my VPS server, I get this error
main.c:12:17: error: ctime: No such file or directory
main.c:13:19: error: cstring: No such file or directory
main.c:14:19: error: cstdlib: No such file or directory
Here is how I compile my C++ program on my VPS server using GCC:
gcc main.c -o bin/main `mysql_config --cflags --libs` -std=c99 -lpthread;
gcc
is not the compiler for c++. you need to use g++
.
See a live example here.
You will also need to review your flags and -std
type. You are trying to compile a c++ file as c.
gcc is a C compiler. To compile C++ code you need to use g++.
Your source file should also have a .cpp or .cxx extension.
Your code is of C++; however, there are 2 mistakes out of your code that are leading to these errrors:
Firstly, your file with the code should be named with a .cpp
or .cxx
extension at the end of it. Right now, it is main.c
, and .c
is an extension for a file of C code, not C++. So, you should change your file name to main.cpp
.
Secondly, put simply, gcc is a compiler meant for C code. Your code, once again, is C++. Therefore, use g++ in your command, not gcc.
If you love us? You can donate to us via Paypal or buy me a coffee so we can maintain and grow! Thank you!
Donate Us With