error string: no such file or directory...

Discussion in 'Mac Programming' started by NSDuo, Nov 26, 2008.

  1. NSDuo macrumors newbie

    Joined:
    Jan 16, 2008
    #1
    I'm trying to make a simple obj loader to practice with 3D, and I thought I'd use std::string to handle text. However when I tell the compiler to #include <string> it gives me "error string: no such file or directory", weird as it only does it for this one specific project. The first place I looked was Google, and I got one result relevent to my situation and it didn't give a solution to my problem. Here is my code:

    Code:
    #include "global.h"
    #include <string>   <------------------ the line giving me trouble, wherever I put it in the project
    
    
    typedef struct vertex
    {
    	float x, y, z;
    } vert;
    
    typedef struct face
    {
    	vert points[4];
    } face;
    
    typedef struct object
    {
    	int noOfVerts;
    	int noOfFaces;
    	face *faces;
    } obj;
    
    obj *edlObj(std::string file);   <----- this line gives me "syntax error before :"
    void render(obj object);
    
     
  2. gnasher729 macrumors P6

    gnasher729

    Joined:
    Nov 25, 2005
    #2
    What is the file name of your program?
     
  3. NSDuo thread starter macrumors newbie

    Joined:
    Jan 16, 2008
    #3
    I don't exactly understand what you mean by the filename of my program. Do you mean:

    my actual program? wormhole demo.app, wormhole demo.xcodeproj
    the program its happening in? xcode
    the file the error occurs in? edldata.h

    if I'm wrong please tell me
     
  4. ChrisA macrumors G4

    Joined:
    Jan 5, 2006
    Location:
    Redondo Beach, California
  5. NSDuo thread starter macrumors newbie

    Joined:
    Jan 16, 2008
    #5
    No, std::string is a C++ class and part of the standard code library. I tried including <vector> and <list> and xcode says they are missing too.
     
  6. gnasher729 macrumors P6

    gnasher729

    Joined:
    Nov 25, 2005
    #6
    If the source file is called main.c, then XCode invokes the C compiler. And the C compiler won't find <string>, and it won't like the C++ syntax. If the source file is called main.cpp, the XCode invokes the C++ compiler which shouldn't give an error. If the source file is called main.m, then XCode invokes the Objective-C compiler; again, that won't like <string>.

    Just a hint: You are starting to learn programming, and you are running into a problem. It is very, very unlikely that the problem is with XCode. It is much more likely that something that you are doing is not what you think you are doing. Like your insistence that this is a C++ program: You think it is C++. But what does the compiler think?

    Add these lines:

    #ifdef __cplusplus
    #error Compiling C++
    #else
    #error Not compiling C++
    #endif

    and check what error you get.
     
  7. ctaylo21 macrumors newbie

    Joined:
    Feb 10, 2009
    #7
    I had the same problem, and after I read the earlier comment I checked and sure enough i was using #include <string> in my main.c file. Oops. Switch to main.cpp and it works fine.
     

Share This Page