2

I'm having trouble getting xcode to find a particular header file, namely cstring.

My project compiled properly until I added a new library. The library, oscpack, consists of .h and .cpp files. I copied these into my project. Some of these files include cstring. Now when I try to compile I get this error:

Lexical or Preprocessor Issue
(...)/xcode4/osc/OscOutboundPacketStream.h:40:10: 'cstring' file not found

I'm new to C++ and I'm still a bit mystified regarding header file locations. Does anyone know where to find cstring on my system, and how I should tell xcode to look for it there?

EDIT

I ran sudo find . -name "*cstring*"and located the header file. It's here:

/Applications/Xcode.app/Contents/Developer/Platforms/MacOSX.platform/Developer/SDKs/MacOSX10.8.sdk/usr/include/c++/4.2.1/cstring

Now how do I tell XCode to search there?

EDIT 2

I tried adding $(SDKROOT)/usr/include/c++/4.2.1 to my Header Search Paths. I entered a world of pain. Dozens of compiler errors were thrown, starting with these.

/Applications/Xcode.app/Contents/Developer/Platforms/MacOSX.platform/Developer/SDKs/MacOSX10.8.sdk/usr/include/c++/4.2.1/bits/c++config.h
/Applications/Xcode.app/Contents/Developer/Platforms/MacOSX.platform/Developer/SDKs/MacOSX10.8.sdk/usr/include/c++/4.2.1/bits/c++config.h:153:1: Unknown type name 'namespace'
/Applications/Xcode.app/Contents/Developer/Platforms/MacOSX.platform/Developer/SDKs/MacOSX10.8.sdk/usr/include/c++/4.2.1/bits/c++config.h:153:1: Expected ';' after top level declarator
dB'
  • 7,838
  • 15
  • 58
  • 101
  • cstring is going to be in a system header location that the compiler knows to search already. It's probably even in the same directory as `` or ``. So the problem is not a simple matter of adding the proper search path for the compiler; There's something deeper wrong either with your build environment or with the oscpack library. – bames53 Oct 13 '13 at 17:09
  • hm. ok. I can compile oscpack from the command line using `make`, so I think the problem is with my build environment. Do you have any ideas re: how to troubleshoot? – dB' Oct 13 '13 at 17:23
  • 1
    See if a clean project will build `#include ` _\n_ `int main() {}`, take a look at the full build commands used and compare. I can't really offer anything more detailed than that. – bames53 Oct 13 '13 at 17:51
  • Ok, thanks. I'll try this out and report back. – dB' Oct 13 '13 at 18:26
  • @bames53 I've noticed that `#include ` works fine in a new project based on the Command Line Tool template, but it doesn't work if the project's based on the Cocoa Application template. I'm updating the question title to reflect the fact that this problem seems to be specific to Cocoa projects and not to XCode projects in general. – dB' Oct 13 '13 at 20:09
  • I'm still trying to suss out the differences in Build Settings between the two. – dB' Oct 13 '13 at 20:11
  • `` is a C++ header. Is the problem that you're building the file that includes it as C or Objective-C and not as C++ or Objective-C++? oscpack describes itself as a C++ library, so you'll need to be using C++ anywhere you include its headers. – bames53 Oct 14 '13 at 00:39
  • That's it. The file that included had a .m suffix. Renaming it to .mm fixed the preprocessor error. If you put than in an answer I'll gladly accept it. The project still doesn't compile, but I think that's due to some other problems that are unrelated. Thanks! – dB' Oct 14 '13 at 01:18

1 Answers1

3

<cstring> is a C++ header. Is the problem that you're building the file that includes it as C or Objective-C and not as C++ or Objective-C++?

oscpack describes itself as a C++ library, so you'll need to be using C++ anywhere you include its headers.

bames53
  • 86,085
  • 15
  • 179
  • 244
  • 1
    Thanks, this was exactly the problem. The file that included had a .m suffix; renaming it to .mm fixed the preprocessor error. – dB' Oct 14 '13 at 01:31