I have a code in Visual studio that I want to implement in Arduino. But there is a problem. Many libraries usable in Visual Studio aren't usable in Arduino IDE. How can I use them in my Arduino code. To be precise, the libraries I want to use are
#include <iostream>
#include <iomanip>
#include <queue>
#include <string>
#include <math.h>
#include <ctime>
respectively.
Okay so I know I have <iostream> available in Arduino. <math.h> is also available I think along with <string> library.
The main problem is to how to use #include <queue> and its functions such as priority_queue() and other fucntions of iostream like .pop()?
Arduino behind the scenes is using the avr-gcc compiler, which provides support for many of the features of the C++ language. It does not, however, include an implementation of libstdc++, which means that a lot of the libraries and features you are used to having with other development environments are just not there. A big reason for this is that it is just not practical to implement some of that functionality on a small microcontroller.
There are several libraries available that implement simplified versions of some of the functions and data structures you are wanting to use. You can find a list (but not necessarily a complete one) of these libraries here:
http://playground.arduino.cc/Main/LibraryList
For example QueueList might be a good alternative to <queue>.
Whatever you find, you are likely to have to refactor your code to use them. When you run into problems implementing those libraries and changes, I would recommend heading over to https://arduino.stackexchange.com/ to get more arduino specific answers.
It is detailed over here:
https://www.arduino.cc/en/Hacking/BuildProcess
The include path includes the sketch's directory, the target directory
(/hardware/core//) and the avr include directory
(/hardware/tools/avr/avr/include/), as well as any library
directories (in /hardware/libraries/) which contain a header
file which is included by the main sketch file.
And these are the libraries supported by avr-gcc (the compiler that Arduino uses)
http://www.nongnu.org/avr-libc/user-manual/modules.html
Related
While setting up the Eigen library, I tried:
#include <eigen/Eigen/Dense>
Which results in the error:
eigen/Eigen/Dense: No such file or directory
However,
#include "eigen/Eigen/Dense"
succeeds.
Why is this? Based on previous questions asked, I suspect this is because #include <> searches in the system directory and #include "" searches locally. If this is true, how would one put the Eigen folder in the system directory?
You will need to follow the instructions that are specific for your operating system. You did not describe your operating system and compiler, and this is something for which no standard instructions apply for every operating system used in the world today. It varies by operating system and compiler.
Alternatively, all C++ compilers have a configuration setting that adds an additional directory to the list the compiler looks when searching for #include <path> header files. gcc, and many other Linux compilers use the -I option. This can be specified manually, or in a Makefile.
MS-Windows compilers have a specific settings too. This Stackoverflow question provides instructions for several versions of the Visual Studio IDE.
I've created a Windows x64 program using standard headers and DirectX (see below). I was kinda expecting no additional runtime libs would be required for the users. But i got the feedback from some that the vcruntime140_1.dll was missing. It's an easy fix, but how do I ensure that users don't need to download additional runtime libs besides DirectX?
#include <Windows.h>
#include <d2d1.h>
#include <dwrite.h>
#include <wincodec.h>
#include <TlHelp32.h>
#include <iostream>
#include <chrono>
#include <string>
#include <cstring>
#include <tchar.h>
#include <vector>
Running programs under Windows10 developed in Visual C++ require the associated runtime redistributables: https://support.microsoft.com/en-us/help/2977003/the-latest-supported-visual-c-downloads.
Microsoft has decided to include the universal C Runtime (CRT) libraries with the standard Windows 10 installation and these are kept up to date via the general Windows update mechanism. The Visual C++ redistributables rely on these UCRT but require a separate installation. Installing the Visual C++ runtime libraries will also verify the latest UCRT are installed in case the user hasn't updated Windows regularly. More details are found on MSDN.
Another option would be include the libraries in the executable using static linking. The program will become larger and care should be taken they are included multiple times. Also any fixes by Microsoft to the dll's will require a rebuild of the program.
Dev-C++ cannot find the I/O stream header files. I tried it with both #include <iostream> and #include <iostream.h> but I get the following errors.
[Error] iostream.h: No such file or directory
[Error] iostream: No such file or directory
What can I check in the Dev-C++ settings to make sure it's properly configured to build programs that use the C++ Standard Library?
#include <iostream>
You've got a double 's' in your code as far as I can see and that may be causing a problem. If including "iostream" header file won't work as well it means that your Dev-C++ (sic!) is probably not linked with MinGW properly.
As the others said, consider using f.e. Code::Blocks instead Dev-C++.
If you didn't download the Dev C++ that includes MinGW then you don't have the standard libraries. If you do have the standard libraries you will need to make sure to set it up by pointing it to the location of the source on your system.
If you still need the standard libraries, you can go to "Downloads" section of this page and go to the first link which includes MinGW.
But your best bet is to send Dev C++ off to die in a fire. The incredibly powerful Visual Studio 2015 is out and the Community version is free: https://www.visualstudio.com/downloads/download-visual-studio-vs There's really no excuse for using anything else on Windows.
I've set the linker to additional dependencies opengl32.lib;glu32.lib;sfml-main-d.lib;
When I run it, I get loads of errors about APIEntry or something in one of the OpenGL files. SFML is also set up fine.
Here is my code:
#include <iostream>
//#include <Windows.h>
#include <gl/gl.h>
#include <gl/glu.h>
using namespace std;
void main()
{
}
It works fine if I include Windows.h, but I really don't want to make it windows-specific (Since the only reason I switched to C++ from C# is for cross platform and I'm not too fussed on Java)
If you're going to use OpenGL, then you should employ a proper OpenGL Loading Library to get your function pointers. These libraries have headers that will include whatever platform-specific stuff is needed to make the header work, using appropriate #defines and so forth.
If you're starting out you're probably not interested in the lower level stuff as setting up your own OpenGL context and such. I would recommend you take a look at GLFW at http://www.glfw.org/ - it is what I prefer for OpenGL. It is open source and cross platform for both Windows, linux and MAC.
Good luck!
I have a Microsoft Visual C++ 6.0 Project and converted it successfully with MS VS Professional 2010 Trial. No conversion problems occured. However, when building the converted project it tells me, that "iostream.h" cannot be found.
I am aware of the new and standardized "iostream" and the "using namespace std" fix.
But I need to use the old iostream.h. Is there a way to accomplish that? The reason is, that this project relies on an old static lib using the old iostream.h.
Any suggestions?
If you have source code relying on iostream.h, change it.
If you have source code that you absolutely cannot change, write iostream.h yourself:
#include <iostream>
using namespace std;
A static library cannot possibly rely on a header file. A header file is included by source code or other header files, the static library consists of object code. The library's header files can depend on iostream.h, though.
The library itself can depend on the C++ standard library.
I assume that there have been incompatible changes to Microsoft's standard library since MSVC 6.0, so if you do not have source code or a newer version of your static library, then you are probably out of luck.
Are you using precompiled headers? If so, then you'll have to include iostream.h within the stdafx.hfile or remove the precompiled headers. Anyway, there seems no reason using the deprecated iostream.h instead of iostream, so maybe you should change the parts of the code that need the old version (if so).
Replace
#include <iostream.h>
with
using namespace std;
#include <iostream>