g++: 'vector' file not found - c++

I'm trying to compile a cpp file using llvm-g++-4.2 on Mac OSX 10.8.
Yes, I know those are old, but I'm trying to develop a plugin for a software that only supports plugins developed in that old environment, sadly.
Anyway, when I try to compile my .cpp file it gives me the error:
'vector' file not found
After it tried to include it (#include <vector>).
I checked in my local include folder (/usr/include) and the vector header file is really not there.
What should I do?

The CAPlayThrough example I was looking at compiled just fine, but the project I had created did not.
To tell the compiler to look for the C++ include file, the top level file AppDelegate.m in my case had to be renamed to AppDelegate.mm. This is telling the compiler to treat the source as a C++ file with all the appropriate includes.

Related

Problem using libxml2 with VS Code under Windows (g++)

I'm not new to programming, but pretty new to C++. I successfully loaded some other 3rd party libraries like curl or sqlite, but I'm having a problem with libxml2 (Platform Windows; IDE VS Code; Compiler g++). I downloaded the binary from zlatkovic.com (x86_x64 if it matters).
After including one or two header files and typing a few lines I wanted to see what the result would be and I tried to compile my code. I added the libxml2-2.dll in my vs code task file under the '-g' flag of the compiler, just like I did it with the others. But this time I received the following message:
"path/to/src/libxml/xmlreader.h:16:10: fatal error: libxml/xmlversion.h: No such file or directory"
Like you can see in the message, the header files are in the "libxml" directory and I also checked they exist.
I guess it's something really basic I'm missing out here, but help would be really appreciated, thanks!
I finally got it. I needed the '-I' flag to the directory with the header files. Thanks everyone!

force to compile a specific file as Objective-C/file type, but the entire project as Objective-C++

I'm adding some features to a project that already exist. It works as expected.
Then I added few files from an open library to that project.
Now, Xcode fails to compile the whole project.
Investigating why, I found out that the problem is the "Compile source as" flag, it is set by default to "Objective-C++".
Switching that flag to other value makes Xcode to complain. Hundreds of errors in any case.
I have the idea the previous dev did this to avoid renaming .c, .cpp, .m to .mm. He is not here anymore. So, hard to say.
Any idea how to solve this?
I see few options:
Either I rename the files as necessary. Which means hundreds of
files renamed. Or
I force Xcode to compile a specific file as
Objective-C/file type, but the entire project as Objective-C++ Or
I create a small project, and then produce a shared library.
I would like to continue with option 2. Is it possible? and how?
Any other idea?
Thanks
I went thru the easiest way: forcing Xcode to compile a specific file as Objective-C, but the entire project as Objective-C++.
Added the compiler flag -x objective-c to each file in Build Phases> 'Compile source as'

C++ Compiler cannot find files without absolute path in Steinberg VST SDK files

I'm trying to compile a simple program that's already been written included in the Steinberg VST SDK.
The issue I'm having is my compiler can't find the file unless it has an absolute path. For some reason, the code is written in such a way that my compiler can't find where the file needed it.
For example:
In the file vstcomponentbase.h, located in C:\Users\180945\Documents\Programs\vstsdk352_25_09_2012_build_16\VST3 SDK\public.sdk\source\vst\
There is this line:
#include "pluginterfaces/base/ipluginbase.h"
ipluginbase.h is located in C:\Users\180945\Documents\Programs\vstsdk352_25_09_2012_build_16\VST3 SDK\plugininterfaces\base
Unless I change the line to
#include "C:\Users\180945\Documents\Programs\vstsdk352_25_09_2012_build_16\VST3 SDK\pluginterfaces\base\ipluginbase.h"
it won't work.
I'm using NetBeans as my IDE. I'd like for the files to automatically find where the files are supposed to be. It should work, as I'm using Steinberg's VST SDK, which has demonstrations and other bits of code that are supposed to work as given. There would be too many things to edit in something that should already work.
How would the compiler know where you have hidden those include files :) ? You need to add "C:\Users\180945\Documents\Programs\vstsdk352_25_09_2012_build_16\VST3 SDK" to the search path for include files in your compiler options. For gcc, the relevant option is -I, but many IDEs have a way of setting the include path in the project settings. Consult your IDE's manual.

How to write C++ code that works between IDE?

I am new to C++ from a C#.NET and Visual Studio background (and some Objective-C / XCode).
I want to write cross-platform (Windows, OS X, Linux) application with C++. I started with TextMate on my Mac and Notepad on my Windows, and compile the code using g++ on command line/terminal to build the executables on its platform.
I got confused when I started using IDE (namely VC++, XCode, and Eclipse). I tried all three and created projects before pasting my code in it. If I start editing in one IDE, I do not know how to get the eventual piece of code to compile on different platform.
For example, if I have a class file - foo.cpp. In Eclipse, it would generate foo.cpp (within it a foo.h, foo::foo()) and a separate foo.h header file (within it a FOO_H_ file etc). In Xcode, it generates a folder Foo constains main.cpp and foo.l) - that's it. Why the difference?
I though C++ code is just C++ code which produce platform specific executables if compiled on that platform. (e.g. compile on Mac, it becomes a Mac executables; if compiled on Windows, it becomes a Windows executables).
It seems, once I started using IDE, my C++ code automatically become unportable, due to all these auto generated files that I have no understanding about. I try reading documentation on XCode, Eclipse, and Visual Studio at the same time, and it confuses me even further. I just want to write C++...
I am also following Stroustrup's classic text to pick up C++ and in the book, nothing like header or source of .h or _H_ files were mentioned, as of why all these files were generated.
Besides using Notepad/Textmate + G++ compiler, how can I write pure, portable C++ program in an IDE that can be cross-platform, or is it even possible?
The default (=most commonly used) file structure for a c++ class called Foo consists of a header file called foo.h which will contain the class definition of Foo, and a foo.cpp which contains the definition of the methods of Foo.
Often all the header files are put into a seperate folder called include.
So the general approach to have the same file/folder structure, which can be used for more than one IDE is:
create the folder structure manually (e.g. include, src and make folders inside your project folder MyProject, the project files for IDEs would go into make, .h files into include, and .cpp files into src)
create the .h and .cpp files for your classes manually using the explorer/finder/...
use "add existing file" or something equivalent to add those files to the project file of your IDE.
as Rup pointed out, for Visual Studio, one should use the "empty project" preset, or it will add some header files you dont want
Why not use 1 IDE for all? Eclipse is cross platform IDE
Use CMake or other meta-buildsystem
Use Boost and Qt to abstract away as much of the platform as possble.
CMake lets you generate project files for most IDE:s that mean when switching between platforms and IDE:s you just tell CMake to generate new project-files for that IDE you use on that platform.
Easiest to get platform-idependent code on windows, linux and mac is to use QtCreator as IDE, it also has a lot of good tutorials. http://qt.nokia.com/downloads

Code::Blocks not being able to find standard library headers?

I recently switched from Bloodshed to Code::Blocks. I wrote a simple input/output program to get a feel for it, and when I tried to compile it I got errors for all of the headers I had included, saying that there was no such directory.
I took a look at the file and saw that the file was saved as a C file rather than a C++ file, how do I change this? (I know this is why because the C++ files I transferred over from Bloodshed work fine.)
As #nagul said in the comments, saving the file as <file>.cpp instead of <file> fixed the no such directory error when compiling.