C++ cannot open source file "time.h" - c++

I am trying to use clocks to measure the time of the running program in Visual Studio 2015 (x64) with C++ on Windows in Debug x64 mode.
I get errors in these lines:
#include <time.h>
#include <sys/timeb.h>
The errors messages say:
cannot open source file "time.h"
cannot open source file "sys/timeb.h"
What path do I have to add to include directories in order to fix this error?

You could try #include <ctime>
Refer to this: http://www.cplusplus.com/reference/ctime/
time.h is used is C not C++.

read this it explain that your method is POSIX, so your path to the sys/time.h must be set well
but there are 2 others way for : how to get time in milliseconds with cpp
https://www.delftstack.com/howto/cpp/how-to-get-time-in-milliseconds-cpp/

Related

New to C++ and would like to know how to play an audio file using VS code 2019

I've looked online for how to play a audio file on C++ and looked at videos but most of them say to change the 'linker' to winmm library. The problem I have is finding where to change the properties in VSCode 2019. Also, when I try to use #Include it would show an error. Example:
#Include "stdafx.h"
#Include <Windows.h>
#Include <playsoundapi.h>
int main()
{
PlaySound(TEXT("C:\Users\User\Desktop\Sound\Blop.wav"), NULL, SND_FILENAME);
return 0;
}
My goal is to just play an audio file using C++ from VSCode.
Error -: cannot open source file "stdafx.h"´ ´cannot open source file "Windows.h"´ ´#include errors detected. Please update your includePath. Squiggles are disabled for this translation unit (C:\Users\User\Desktop\Sound\Audio.cpp).´ ´cannot open source file "playsoundapi.h"
It is not #Include. It should be correct as #include
I already was a problem seem like you. So, by my experience, I think "#Include "stdafx.h" is the problem, you can't use "stdafx.h" in VS 2019 (Microsoft Visual Studio Comunity 2019), "stdafx.h" work very well in VS 2017 (Microsoft Visual Studio Comunity 2017), but "stdafx.h" was replaced by #include "pch.h"in VS 2019, in other words, you should use #include "pch.h" and not "stdafx.h". And more, you have to include the winmm.lib in linker/imput/aditional dependencies, so if you follow this link you can see how to include winmm.lib (https://www.youtube.com/watch?v=9WeDQHi6sJs). So, to VS 2019 you can use this code below, I use this code in VS 2019 and it works very well for me. The song that you would like to play should have to stay in the right directory, the name of the file that stays my .cpp code is teste_0027 (C:\Users\Rodrigo\source\repos\teste_0027\Debug), the file has to stay in .wav format, and more, when you will create the c++ project in VS 2019 you should create the project as model "Aplicativo de Console CLR" in my language (Portuguese-Brazil), in your language it should sound like "Console App CLR"...
#include "pch.h"
#include <iostream>
#include <windows.h>
#include <MMSystem.h>
using namespace System;
using namespace std;
int main()
{
bool played = PlaySound(TEXT("ALAN-WALKER-Faded-Different-World-feat-Julia.wav"), NULL, SND_SYNC);
cout << " Sucess or not " << played << endl;
system("pause");
return 0;
}

Can't compile dll from C++ project - Visual Studio

I'm trying to play a RTSP stream in Unity 5.
For that I found a RTSP-plugin for Unity on Github that I want to try, but unfortunatelly it comes with no Readme or installation guide whatsoever.
So far I found out that I'm dealing with a C++ Visual Studio project that needs to be compiled into a DLL in order to add it to Unity. But when I try to build the project I get the following Error for the header file "ffmpegenv.h":
Error C1083 Cannot open include file: 'libavutil\opt.h': No such file or directory - (Screenshot)
Here's the code from the header file
#pragma once
//=============================
// Includes
//-----------------------------
// FFMPEG is writen in C so we need to use extern "C"
//-----------------------------
extern "C" {
//#define INT64_C(x) (x ## LL)
//#define UINT64_C(x) (x ## ULL)
#include <libavutil\opt.h>
#include <libavutil/mathematics.h>
#include <libavformat/avformat.h>
#include <libswscale/swscale.h>
#include <libswresample/swresample.h>
#include <libavutil/imgutils.h>
#include <libavcodec/avcodec.h>
}
I'm aware that the header includes source code from the FFmpeg libraries which doesn't come with the plugin I'm trying to compile. So I downloaded the FFmpeg source code from their GitHub page and copied all the code files (with its original folder structure) inside the plugin's project folder.
However when I then try to compile the plugin, it still doesn't find the #includes an shows the same error as mentioned above.
How I can I get the plugin to compile? What am I missing?
Thanks in advance
P.S.: I'm using Visual Studio Community 2017 with C++ support and Win 10 SDK as well as Win 8.1 SDK.

C++ project build, but IDE shows error

Error: cannot open source file "GL/glew.h"
I have the following code :
//Include GLEW
#include <GL/glew.h>
//Include GLFW
#include <GLFW/glfw3.h>
//Include the standard C++ headers
#include <stdio.h>
#include <stdlib.h>
//Define an error callback
static void error_callback(int error, const char* description)
{
...
I took from there: http://www.41post.com/5178/programming/opengl-configuring-glfw-and-glew-in-visual-cplusplus-express#part4
In order to have a somewhat portable solution, before I even started Visual Studio 2013 I created two System Environment Variable in windows.
GLEW=C:\Install\Development\C++\Framework\glew-1.10.0-win32\glew-1.10.0
GLFW=C:\Install\Development\C++\Framework\glfw-3.0.4.bin.WIN32\glfw-3.0.4.bin.WIN32
So in my project I could for instance write a additional include folder as: %GLEW%\include
As I said, it builds fine and runs fine as well.
Yet, not having intellisense behave properly is really annoying.
How to fix it?
My syntax was actually wrong, you cant use global environment variable in VS using %<name>% but you have to use $(%<name>).
Wherever I wrote %GLEW%\include I should have $(GLEW)\include.
It's working fine now.
Though I'm completely clueless why it built.
This post: https://stackoverflow.com/a/11543754/910813 got me to remind that.

Boost build error with websocketpp and MySQL on Windows

I am trying to build a C++ app that uses both websocketpp and MySQL. I have encountered 2 build problems using VS 2010 C++ Express.
1) A problem with the boost libraries. It produces many errors like this:
1>c:\program files (x86)\boost\boost_1_50\boost\thread\win32\thread_data.hpp(210): error C2146: syntax error : missing ')' before identifier 'rel_time'
Here's the relevant snippet from thread_data.hpp starting with line 210:
inline BOOST_SYMBOL_VISIBLE void sleep(TimeDuration const& rel_time)
{
interruptible_wait(detail::pin_to_zero(rel_time.total_milliseconds()));
}
2) A conflict with the word VERSION which is documented here and I believe is independent.
To make a clear and simple example of the boost build problems, I'm using the websocketpp example: echo_server.cpp to which I added these includes:
#include "stdafx.h"
Boost lib includes recommended by "Building a program with websocketpp" on the websocketpp site.
#include <boost/regex.hpp>
#include <boost/random.hpp>
#include <boost/system/api_config.hpp>
#include <boost/system/config.hpp>
#include <boost/system/error_code.hpp>
#include <boost/system/system_error.hpp>
#include <boost/system/windows_error.hpp>
and the MySQL header includes. Adding these 2 boostincludes triggers the build errors. If I comment out these 2 includes, it builds without errors:
#include <my_global.h>
#include <mysql.h>
Any suggestions on how to deal with the boost problems?
I don't think this is the same build problem as this one, "Trying to build websocket++ with MinGW: last few linker errors — what could it be?"
Concerning the first error, check if there are any macros interfering with the code. Right-click and go to definition or #define the macro yourself at the beginning of the file and see where it gets redefined. In really hard cases, look at the preprocessor output via a compiler flag.
Concerning the rest, you don't provide any versions for Boost and MySQL. Then, there is my_global.h (or is that part of MySQL?) and stdafx.h, which are both under your control but you don't show them here. Also, try to reduce the issue to the smallest possible piece of code. In short, provide a reproducible example.

C++ Problems with #include <anyfile.h> when trying to compile a gstreamer app

I didn't find anything like this when I searched for it. I'm trying to make a simple gstreamer app based on code I found in another stack overflow thread. Whenever I try to compile it by going to the directory with command prompt and entering cl cppgstreamer.cc. Initially, the only include was #include <gstreamermm.h>, which gives me
cppgstreamer.cc(1) : fatal error C1083: Cannot open include file: 'gstreamermm.h
': No such file or directory
Even when I put cppgstreamer.cc into the same directory as gstreamermm.h. I then tried changing the include to
#include "C:\Users\MY_NAME\Documents\gstreamer c++\gstreamermm-0.10.10.2\gstreamer\gstreamermm.h"
with MY_NAME being replaced by my name.
This seems to work, but then it tries to do the includes in the gstreamermm.h, and they are in #include <file.h> form, so I get another fatal error C1083,except this time with init.h, or when I changed that, error.h. And they have dependencies. Is there a way that I can get my compiler to like the #include <file.h> syntax? I really don't want to go through the file and change every #include <file.h> to #include "file.h".
Sorry if this is a dumb question. I'm new to C++, although I've worked with C in the past.
I am using Microsoft Visual C++ Express 2010. Any help would be appreciated. Thanks!
You need to add the directory containing gstreamermm.h to include path. I don't have visual c++ here to check, but it's in somewhere in project properties under C/C++ .