What library to include for std::vector in Tizen? - c++

I want to use an std::vector for an app that I'm creating with Tizen and I can't find the right library to include to make my std::vector be recognized...
I have a syntax error...
Is there an equivalent to std::vector specific to Tizen? I searched the web but I didn't find anything...
I tried #include <vector> Tizen doesn't recognize it, that's what my problem is because in "normal" C++ it works fine. Only I'm using Tizen with Tizen IDE (Eclipse plug-in) and it doesn't recognize the library so I'm wondering which library I need to include instead (I got a fatal error: file not found when I use the include I mentioned).
I can't post images so here's a transcript of the error message:
type name requires a specifier or qualifier
syntax error
expected expression"
All of which regarding this line:
std::vector<int> vect;
OK, I found my answer. It seems Tizen is using C and not C++... I didn't see it because some libraries I sometimes use when I code in C++ were included like they should. Anyway I'm just gonna have to find the C equivalent of vector now and my problem will be solved.

https://developer.tizen.org/dev-guide/2.2.0/
The Tizen C++ application supports C++ based on the Standard C++ ANSI ISO 14882 2003, which includes the Standard Template Library (STL). This helps developers migrate the pre-existing standard library based applications to the Tizen platform with minimum effort.
More specifically, Tizen supports complete set of libstdc++v3 comprising of standard C++ functions specified in the Standard C++ ANSI ISO 14882 2003 and the entire Standard Template Library (http://www.sgi.com/tech/stl/).
These methods can be used by including the relevant header file in a standard manner, for example, "#include <stdio>".
Support for standard C++ library extended to complete set of libstdc++v3 modules, namespaces and classes.
For more information, refer to this Web site.
Remarks:
The locale based feature is not supported in Tizen.
So #include <vector> should work fine.
Since you say that you can't include any C++ headers, I suspect the problem is that the compiler is compiling your code as C instead of C++. Affirm that your file has the .cpp extension, and view the file's properties in the project to confirm that the IDE is treating the file as C++. (I don't know where that setting is, I don't have Eclipse). This link says to delete your project and create a C++ project instead of a C project, then re-import your files. This link says you can set the "File Type", but also implies it doesn't quite work.

You say: I searched the web but I didn't find anything...
Google "std::vector" The first hit is
http://en.cppreference.com/w/cpp/container/vector
which says:
Defined in header <vector>
So the answer is: Learn to use Google.

I think the wrong answer was accepted...the clue is in the tags used by the OP.
The compiler used by Tizen studio determines whether a source file or header file is C or C++ based on the file extension. So if your header file is .h and you include < vector > then the compiler will complain since there is no C equivalent library for vector.
If you rename you header to .hpp, or your source to .cpp, and recompile then it will compile without error.

Related

How do I use the rope from C++ STL in Xcode

Apologies if I'm asking a silly newbie question. I'm new to C++ (familiar with C and objective C) and wanted to use the rope from the standard template library. Is this included with the libraries that Xcode uses? I have tried #include <vector> and the same for map successfully and also ext/hash_map. However rope does not seem to be available. Do I just have to download the source and include it in my project?
Unfortunately "Rope" is not part of the C++ standard!
C++ Overview: http://www.cplusplus.com/reference/
From the link you posted:
This distribution of the STL consists entirely of header files: there is no need to link to any library files.
This means the steps to use it are:
download the source code for SGI's STL implementation
add them to your include path
include files as necessary in your code
compile
That said, the link you posted is not the C++ standard library. It is an implementation of STL, (the precursor to the C++ standard library) with a few (non-standard) additions. In particular, the rope implementation you found is a non-standard adition.

Where is the standard library?

I have searched Google but haven't found quite a direct answer to my queries.
I have been reading C++ Primer and I'm still quite new to the language, but despite how good the book is it discusses the use of the standard library but doesn't really describe where it is or where it comes from (it hasn't yet anyway). So, where is the standard library? Where are the header files that let me access it? When I downloaded CodeBlocks, did the STL come with it? Or does it automatically come with my OS?
Somewhat related, but what exactly is MinGW that came with Cobeblocks? Here it says
MinGW is a C/C++ compiler suite which allows you to create Windows executables without dependency on such DLLs
So at the most basic level is it just a collection of "things" needed to let me make C++ programs?
Apologies for the quite basic question.
"When I downloaded CodeBlocks, did the STL come with it?"
Despite it's not called the STL, but the C++ standard library, it comes with your c++ compiler implementation (and optionally packaged with the CodeBlocks IDE).
You have to differentiate IDE and compiler toolchain. CodeBlocks (the Integrated Development Environment) can be configured to use a number of different compiler toolchains (e.g. Clang or MSVC).
"Or does it automatically come with my OS?"
No, usually not. Especially not for Windows OS
"So, where is the standard library? Where are the header files that let me access it?"
They come with the compiler toolchain you're currently using for your CodeBlocks project.
Supposed this is the MinGW GCC toolchain and it's installed in the default directory, you'll find the libraries under a directory like (that's what I have)
C:\MinGW\lib\gcc\mingw32\4.8.1
and the header files at
C:\MinGW\lib\gcc\mingw32\4.8.1\include\c++
"So at the most basic level is it just a collection of "things" needed to let me make C++ programs?"
It's the Minimalist GNU toolchain for Windows. It usually comes along with the GCC (GNU C/C++ compiler toolchain), plus the MSYS minimalist GNU tools environment (including GNU make, shell, etc.).
When you have installed a C++ implementation you'll have something which implements everything necessary to use C++ source files and turn them into something running. How that is done exactly depends on the specific C++ implementation. Most often, there is a compiler which processes individual source file and translates them into object files which are then combined by a linker to produce an actual running program. That is by no means required and, e.g., cling directly interprets C++ code without compiling.
All this is just to clarify that there is no one way how C++ is implemented although the majority of contemporary C++ implementations follow the approach of compiler/linker and provide libraries as a collection of files with declarations and library files providing implementations of these declarations.
Where the C++ standard library is located and where its declarations are to be found entirely depends on the C++ implementations. Oddly, all C++ implementations I have encountered so far except cling do use a compiler and all these compilers support a -E option (although it is spelled /E for MSVC++) which preprocesses a C++ file. The typically quite large output shows locations of included files pointing at the location of the declarations. That is, something like this executed on a command line yields a file with the information about the locations:
compiler -E input.cpp > input.ii
How the compiler compiler is actually named entirely depends on the C++ implementation and is something like g++, clang++, etc. The file input.cpp is supposed to contain a suitable include directive for one of the standard C++ library headers, e.g.
#include <iostream>
Searching in the output input.ii should reveal the location of this header. Of course, it is possible that the declarations are made available by the compiler without actually including a file but just making declarations visible. There used to be a compiler like this (TenDRA) but I'm not aware of any contemporary compiler doing this (with modules being considered for standardization these may come back in the future, though).
Where the actual library file with the objects implementing the various declarations is located is an entirely different question and locating these tends to be a bit more involved.
The C++ implementation is probably installed somehow when installing CodeBlocks. I think it is just one package. On systems with a package management system like dpkg on some Linuxes it would be quite reasonable to just have the IDE have a dependency on the compiler (e.g., gcc for CodeBlocks) and have the compiler have a dependency on the standard C++ library (libstdc++ for gcc) and have the package management system sort out how things are installed.
There are several implementations of the C++ standard library. Some of the more popular ones are libstdc++, which comes packaged with GCC, libc++, which can be used with Clang, or Visual Studio's implementation by Microsoft. They use a licensed version of Dinkumware's implementation. MinGW contains a port of GCC. CodeBlocks, an IDE, allows you to choose a setup which comes packaged with a version of MinGW, or one without. Either way, you can still set up the IDE to use a different compiler if you choose. Part of the standard library implementation will also be header files, not just binaries, because a lot of it is template code (which can only be implemented in header files.)
I recommend you read the documentation for the respective technologies because they contain a lot of information, more than a tutorial or book would:
libstdc++ faq
MinGW faq
MSDN

About C++ Libraries

When I install an IDE like VB for example, it has C++ libraries.
The question is, how to know the contents of a library (methods or manipulators) the way I am intended to do.
Where should a beginner find the contents formally? I found them in Wikipedia, but I want to know the original source (if we suppose that no internet connection is available).
MSDN would be a good source. And C++ Reference too.
You can donwload the current image of cppreference.com wiki at this address. It is updated daily.
Simple question here, when i install an IDE like vb for example, it has c++ libraries.
What libraries are you referring to?
where should a beginner find the contents formally?
Libraries that are meant for public consumption are described in their respective documentation. Where that documentation is found differs greatly. Most documentations for big public libraries are found online, on the official websites of these libraries, though.
Since the question explicitly mentioned C++, the C++ standard libraries are described at cplusplus.com. There is another large collection of C++ libraries, called Boost which is described on their homepage.
The libraries that ship with VB (which VB, though? VB.NET or VB6?) are Microsoft’s, and are therefore described on their developer network homepage, msdn.microsoft.com. An offline copy of this documentation is installed with Visual Studio; however, the software used to navigate it is barely usable (especially when accessed via Visual Studio).
The original source are the header files (.h files). In these files you will find the functions declarations and class definitions. In some cases, like template code, you will also see the implementationl. In others, the implementation will be precompiled into a .dll or .lib file and you can't see it. But all available things are in the header file. To use its contents you must #include the header file and link against the implementation. For standard library, the linking is done for you by the IDE
Everything that comes with Visual Studio and its subset installations is documented on MSDN. Do you have more specific questions re the C++ libraries? Do you need info on Win32, C runtime (CRT), C++ standard library?
Every lib usually has a coupled header (.h) file that describes the signatures of methods and types available with that library. The library is linked (or dynamically loaded and linked) with the executable while the header is used during compilation to the purpose of static checking the source.
You should just look for an include folder and check its contents.
The contents of a library is contained in the headers which ship with your IDE.
The .h files contain just the function declarations. The source containing the definitions is already compiled, so when you include a header, the linker looks for the function definitions in the libraries that you have linked. Most of the libraries are open source, some of them are just specifications that anyone can implement for example OpenGL, and the standard library is a specification, too. The same goes for the C++ language. Then programmers use the specifications to write implementations (GCC, VC++).
Here you can download the source code of STL C++ https://www.sgi.com/tech/stl/download.html

Where can I see the code used in C++ standard libraries?

When I compile a program with #include
where can I see the contents of that file, and also since that file contains declarations, where can I see the actual code used in those functions?
Is it open to everyone or is it not available to the public?
The actual code is in the platform-specific standard libraries that come with your compiler, you can see it by looking at the standard library implementation source.
Here's the documentation (and source) for libstdc++ by GNU (it comes with gcc): http://gcc.gnu.org/onlinedocs/libstdc++/latest-doxygen/index.html.
Download the source from one of these mirrors: http://gcc.gnu.org/mirrors.html
Generally the #included file is readable, but the library it implements is generally not readable. The include files on a mac are in /usr/include/c++.
The library code depends on the compiler. For Gnu C++ used in linux and Mac you can definitely see the code. You might have to download it. It is available at http://gcc.gnu.org/libstdc++/
I don't think Windows C++ library code is available.
It depends on what toolchain you are using, not every vendor is making his implementation public. You can have a look at the GNU C library for starters: http://www.gnu.org/software/libc/
Dinkumware, the company behind the C++ standard template library that is used in Visual Studio for example, is offering a commercial product, thus the code is not available to everyone - it really depends on your license. Some versions of Visual Studio indeed ship with the source code of the runtime included.
As for the STL, there is also STLport, an open source STL implementation.
Your best bet will indeed be the projects that gcc/g++ depend on.
The C++ standard itself is just this: a standard. The implementation of which is done by many vendors. STLport and GNU libstdc++ are both open source and can be looked at as a whole. Visual Studio ships with Dinkumware C++ standard library. It is closed source.
Nevertheless, you can always see the source of the headers by opening the include directory of your C++ standard lib. The files are named just like you include them. Much of it is implemented in headers anyway. But are pretty much unreadable to the untrained eye.
But when it comes to using the C++ library don't depend on the exact source code of it, but rather on what the C++ standard says. Don't program to an implementation, but rather to the standard.
Run this command from your command line:
find /usr -name iostream
That will tell you the directory you want.
If you use something like Visual Studio, you can put a break point and then start line-by-line stepping through your code and it will open the included files as you go along. Quickest way into a file in my opinion. Otherwise you can find the code somewhere on your PC ... on mine its in C:\Program Files (x86)\Microsoft Visual Studio 10.0\VC\crt\src\ostream for example, replacing ostream with iostream, sstream, etc (note that those are file names without extensions) but also if you look at the directory you'll see a lot of .h and .c files
All system headers ship with your compiler. On Linux systems, these can normally be found under /usr/include . On other platforms, the will normally live where you installed the compiler.
Commercial libraries do not normally ship source code. On linux, these can normally be found in the source pacakges.

How to view source code of header file in C++?

similar to iostream.h ,conio.h , ...
The standard library is generally all templates. You can just open up the desired header and see how it's implemented†. Note it's not <iostream.h>, it's <iostream>; the C++ standard library does not have .h extensions. C libraries like <string.h> can be included as <cstring> (though that generally just includes string.h)
That said, the run-time library (stuff like the C library, not-template-stuff) is compiled. You can search around your compiler install directory to find the source-code to the run-time library.
Why? If just to look, there you go. But it's a terrible way to try to learn, as the code may have non-standard extensions specific to the compiler, and most implementations are just generally ugly to read.
If you have a specific question about the inner-workings of a function, feel free to start a new question and ask how it works.
† I should mention that you may, on the off chance, have a compiler that supports export. This would mean it's entirely possible they have templated code also compiled; this is highly unlikely though. Just should be mentioned for completeness.
From a comment you added, it looks like you're looking for the source to the implementations of functions that aren't templates (or aren't in the header file for whatever reason). The more traditional runtime library support is typically separately compiled and in a library file that gets linked in to your program.
The majority of compilers provide the source code for the library (though it's not guaranteed to be available), but the source files might be installed anywhere on your system.
For the Microsoft compilers I have installed, I can find the source for the runtime in a directory under the Visual Studio installed location named something like:
vc\crt\src // VS2008
vc7\crt\src // VS2003
vc98\crt\src // VC6
If you're using some other compiler, poke around the installation directory (and make sure that you had asked that runtime sources to be installed when you installed your compiler tools).
As mentioned, it is implementation specific but there is an easy way to view contents of header files.
Compile your code with just preprocessing enabled for gcc and g++ it is -E option.
This replaces the contents of header files by their actual content and you can see them.
On linux, you can find some of them in /usr/include
These files merely contain declarations and macro definitions.The actual implementation source files can be obtained from the library provider e.g the source code of standard C++ Library(libstdc++) is obtainable here.
According to the C++ language specification, implementors do not have to put standard headers into physical files. Implementors are allowed to have the headers hard coded in the translator's executable.
Thus, you may not be able to view the contents of standard header files.