Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

How do you std::vector in XCode + C++? [closed]

For various reasons (and I assure you they are valid, so no "use Cocoa" talk please), I must work with XCode, C++, OpenGL, OpenCL (with a little GLUT on the side) to rebuild a few graphics demos on Mac (coming from XP + Visual Studio 2005 development). The project was built as a Command Line Tool using "c++ stdc++".

My Program.h file connects my shader objects together, compiles, links, and otherwise prepares them for use as OpenGL shader programs. Contained within this file are the following relevant lines of code:

#include <vector>
using std::vector;

and within the private section of the class:

vector<int> shaderHandles;

and when adding shader handles:

shaderHandles.push_back(shaderHandle);

and finally, when using the pushed shader handles:

for (int s = 0; s < (int) shaderHandles.size(); s++)
{
    glAttachShader(handle, shaderHandles[s]);
}

In all my experience and research, there's nothing wrong with these lines within C++. However, when compiling (whether debug or release, so it's not related to the _GLIBCXX_DEBUG problem), the following 4 errors are generated:

/Developer/SDKs/MacOSX10.6.sdk/usr/include/c++/4.2.1/bits/stl_bvector.h:916: error: 'size' is not a member of 'std'
/Developer/SDKs/MacOSX10.6.sdk/usr/include/c++/4.2.1/bits/stl_bvector.h:961: error: 'size' is not a member of 'std'
/Developer/SDKs/MacOSX10.6.sdk/usr/include/c++/4.2.1/bits/vector.tcc:350: error: '__old_size' is not a member of 'std'
/Developer/SDKs/MacOSX10.6.sdk/usr/include/c++/4.2.1/bits/vector.tcc:453: error: '__old_size' is not a member of 'std'

Also, the file that links to stl_bvector.h and vector.tcc is:

/Developer/SDKs/MacOSX10.6.sdk/usr/include/c++/4.2.1/vector

Thus far, numerous Google searches have turned up nothing. All this code works flawlessly on Windows. Worse, if I replace the above code with the list equivalents:

#include <list>
using std::list;

and,

list<int> shaderHandles;

and,

for (list<int>::iterator s = shaderHandles.begin(); s != shaderHandles.end(); s++)
{
    glAttachShader(handle, *s);
}

The program works as expected.

But one can't blame this ENTIRELY on the vector implementation, because the following program:

#include <iostream>
#include <vector>
using std::vector;

int main (int argc, char * const argv[])
{
    vector<int> test;

    test.push_back(1);
    test.push_back(2);
    test.push_back(3);

    test.clear();
    return 0;
}

Works with no problems.

I'll be happy to provide more information as necessary.

Please don't tell me I should use Cocoa/Objective-C; it's not really an option right now. And while yes, I can use lists to accomplish this functionality, other parts of my demo are not so easy to rework.

like image 964
Dwight Avatar asked Oct 26 '22 00:10

Dwight


1 Answers

I'm SO sorry everyone. Mere minutes after posting this, I decided to go on with what I could, saving this issue for later. I found a similar problem occurring with fstream. With this new information available, a Google search brought up this topic, and ultimately the solution.

I had defined my own min and max macros in my completely unrelated vector math files. The solution was to remove my macros and put std:: in front of the min and max calls.

like image 198
Dwight Avatar answered Nov 14 '22 04:11

Dwight