Template class error in xcode - c++

I understand this has been asked million times but still I just couldn't found the solution.
I am using OSX 10.8, boost 1.50, xcode 4.5.1.
I installed boost using macports.
created an empty xcode project. My main.cpp contains the following code
#include "boost/container/deque.hpp"
int main(int argc, char *argv[])
{
boost::container::deque d(12, 5.5f);
return 0;
}
updated 'header search path' to point to '/opt/local/include'
updated 'library search path' to point to '/opt/local/lib'
tried changing 'c++ language dialect', 'c++ standard library' and other settings with no success at all.
when I build the project, I get error related to semantic issue in allocator_traits.hpp and deque.hpp and I have no idea why. I am afraid as I start using more boost libraries more errors will pop up.
deque.hpp (line 482 and 483)
base specifier must be a class name (ptr_alloc_t and allocator_type)
what else do I need to do to configure boost. why using boost is so complicated?

boost::container::deque is a template class and you must specify which type do you use. In your case this is float:
boost::container::deque<float> d(12, 5.5f);
You can read more about templates here

Related

libclang not finding headers in <> brackets on Mac with Xcode

Edit:
This program compiles. It's only when run does it fail to find iostream. I'm using the libclang.dylib that is bundled with Xcode.
I've written a small tool to begin working with libclang. I'm trying to parse TranslationUnits. The following program is saved in the file tool.cpp. Once compiled and run, it tries to parse tool.cpp as a TU. It's failing to get a clean run with default headers as it cannot find iostream on my Mac. After several attempts to supply arguments that point to the file, it still doesn't work. Any ideas?
#include "tool.h"
#include <iostream>
int main(int argc, char* argv[]) {
CXIndex index = clang_createIndex(0,0);
const char *args[] = {
"-I/usr/include",
"-I/usr/local/include",
"-I.",
"-I/Applications/Xcode.app/Contents/Developer/Platforms/MacOSX.platform/Developer/SDKs/MacOSX.sdk/usr/include",
//Should be here
"-I/Applications/Xcode.app/Contents/Developer/Platforms/MacOSX.platform/Developer/SDKs/MacOSX.sdk/usr/include/c++/4.2.1"
}
;
Output:
tool.cpp 6:10: 'iostream' file not found
I've got the same issue. I am trying to add CPP to iOS Objective-C. It's not working. I found that this is about next "pain" from Apple because they do not use standard C++ library anymore. I've tried everything that mentioned on this site but haven't found any solution:

CImg Compilation Error: t_normal not in global namespace

I'm currently working on a class assignment that requires the use of the CImg library. To be clear, the assignment is not linking the library into the program; The class is using it access the pixel data for later use in the heart of the assignment.
I'm working in Xcode (OS X 10.10). CImg (2.2.2) is installed from homebrew, and I've managed to navigate the weird way Xcode deals with search paths (added the header to the section), and have successfully-ish included CImg.
my full code is as below.
#include <iostream>
#define cimg_display 0 //I don't need X11 at all
#include "CImg.h"
using namespace cimg_library;
int main(int argc, const char * argv[]) {
// insert code here...
std::cout << "Hello, World!\n";
return 0;
}
However, I get 17 Compile-time errors from CImg.h, which are very unusual, and all of the form:
"No member named 't_normal' in the global namespace; did you mean simply 't_normal'?"
Thinking I might have received a bad download, I have attempted to redownload CImg, with no luck. I have also gotten to this same point with non-homebrew versions of CImg.
To verify the download, I also compiled the examples from the command line and they ran perfectly.
Is there a problem with CImg that I'm not aware of, a problem with Xcode that I'm not aware of, or is there something fundamental that I'm missing (definitely an option, my C-style programming is a little rusty) ?
halp pls.
Your code runs fine if you do this:
Create a new Xcode project, with:
type = "Command Line Tool"
language = "C++"
Then go to "Build Settings" and add the path to the directory containing CImg.h to your "User Header Search Paths"

C++ URDL Compile Errors with Xcode 6.1 / LLVM 6.0

I want to include the C++ Libary called URDL. I am developing a program on Xcode with Clang Compiler using Boost 1.56.
As a Sample Project I used this code here and include the Boost Libaries- and Include-Paths in the settings of my Xcode Project.
#include <iostream>
#define URDL_HEADER_ONLY 1
#include <boost/array.hpp>
#include <urdl/http.hpp>
#include <urdl/istream.hpp>
int main(int argc, const char * argv[])
{
urdl::istream is;
return 0;
}
Then I compile I get the following Errors:
in http.ipp from URDL
/Users/maximilian/XcodeProjects/Libaries/urdl-0.1/include/urdl/impl/http.ipp:25:23: Exception specification of overriding function is more lax than base version
and in handler_invole_helpers.hpp from URDL
/usr/local/Cellar/boost/1.56.0/include/boost/asio/detail/handler_invoke_helpers.hpp:37:3: Call to 'asio_handler_invoke' is ambiguous
My suggestion is that URDL is not compatible with this Version of Boost (1.56).
Thanks in Advance
lux_
PS: I must use URDL or at least boost::asio (which URDL is based on, but URDL makes my work much simpler) because it is a homework for an university course.
Problem Solved ! :) Download the URDL Version from Github instead of the Website think-async.com as I did before.

Netbeans C++ Application won't build [duplicate]

This question already has an answer here:
How to add a library include path for NetBeans and gcc on Windows?
(1 answer)
Closed 8 years ago.
I recently installed the MiniGW compiler so that I can start learning C++. But when I go to create a new project and have it include main, I get two error messages from the start(after the project has been created) Cannot Find Include File <cstdlib> and Unable to resolve identifier std and when I try and 'Clean and Build' the project, the clean is successful and the build is not. I have done a google search and ran across this post Netbeans 7.2 shows "Unable to resolve identifier" , although build is successful , but I'm not sure my problem is exactly the same since my project won't build (or maybe it is, I don't know), and I'm also not sure I understand the accepted answer. Can this be multiple problems or just one? I want to get this fixed so I can learn!
/*
* File: main.cpp
* Author: Zf
*
* Created on December 16, 2014, 1:50 PM
*/
#include <cstdlib>
using namespace std;
/*
*
*/
int main(int argc, char** argv) {
return 0;
}
Edit: Lines 7 and 8 are where the error messages are.
Have you Tool Collection set properly ?
for example
<cstdlib> is found in C:\minGW\lib\gcc\mingw32\4.8.1\include\c++
Sounds like you need to tell the compiler where to find cstdlib. See this: How to add a library include path for NetBeans and gcc on Windows?
Cstdlib contains C functions, they are not wrapped in a namespace. Remove the using namespace std; line

Linking Qt in CodeLite

I'm not sure why this is, but 99% of the problems I have with programming in C++ have to do with the gcc linker.
I want to link the Qt library to a project in CodeLite. This is the code I have so far:
#include <QApplication>
int main(int argc, char *argv[])
{
return 0;
}
When I compile, I get the error
/Users/andrew/Dev/C++/COSC 102/elitecod/main.cpp:1:24: error: QApplication: No such file or directory
I have Qt installed (with Homebrew, Mac OS X Lion) in /usr/local/include. Why is this happening, and how can I fix this problem?
The error indicates it can't find the file QApplication. You need to add the Qt 'include' directory to the list of places the compiler should look for it and other header files.
A brief google seems to indicate you may have other problems with Qt, you might want to keep this link handy.