Xcode and Objective-C++ can't find <cstdio> - c++

I'm writing Cocoa code that uses some classes defined in a C++ library. I give the filename the extension .mm, and things are usually fine.
But not always. Sometimes Xcode 4 disappoints me with: "Lexical or Preprocessor issue: 'cstdio' not found". I can't figure out how to make Xcode find it. Nor can I figure out why it works sometimes, but not others. What do you think?
Edit: Noise. My filename extension was not .mm, but rather .m. :( There is not, and there never was, a problem. See below.

It still should be able to find <stdio.h> just fine.
Edit: The .mm file should work fine all the time. Make sure in your build settings that Compile Source As is set to According to File Type

Related

Trying to compile Qt/C++ code in Code Blocks

I am new with QT, so I am not sure how this works. Im trying to compile some C++ code that includes QT code for graphics. I am using the GNU compiler in Code blocks, but whenever I compile it, It gives this error:
fatal error: QGraphicsRectItem: No such file or directory
So how do I fix this? Is there a different compiler I need?
My include statement is:
#include <QGraphicsRectItem>
It is hard to tell from the info you provided. There are several problems that yield this error, not configured the files correctly, there is no such header file, ..., etc. The error is clear though.
Qt is a big library that is why we need qmake to take care of configuring the files, so theoretically speaking, you can generate Makefile and copy-paste the related data to your code-blocks project. As far as I know, qmake supports Visual Studio and Xcode projects but not sure if there is a tool for code-blocks.

force to compile a specific file as Objective-C/file type, but the entire project as Objective-C++

I'm adding some features to a project that already exist. It works as expected.
Then I added few files from an open library to that project.
Now, Xcode fails to compile the whole project.
Investigating why, I found out that the problem is the "Compile source as" flag, it is set by default to "Objective-C++".
Switching that flag to other value makes Xcode to complain. Hundreds of errors in any case.
I have the idea the previous dev did this to avoid renaming .c, .cpp, .m to .mm. He is not here anymore. So, hard to say.
Any idea how to solve this?
I see few options:
Either I rename the files as necessary. Which means hundreds of
files renamed. Or
I force Xcode to compile a specific file as
Objective-C/file type, but the entire project as Objective-C++ Or
I create a small project, and then produce a shared library.
I would like to continue with option 2. Is it possible? and how?
Any other idea?
Thanks
I went thru the easiest way: forcing Xcode to compile a specific file as Objective-C, but the entire project as Objective-C++.
Added the compiler flag -x objective-c to each file in Build Phases> 'Compile source as'

eclipse and boost unit_test_framework failing syntax check using c++

i have the following Problem.
I started to use the boost library version 1.40, for unit testing.
Since some other people working on the project and not all of them are using eclipse, the program has to be compilable with a makefile. So we used cmake to generate one.
The good thing is, the test is building and working perfectly fine.
But the problem is, when using eclipse (created a c++ makefile project), it complains about several syntax errors (in the sourcecode view).
Something like:
BOOST_AUTO_TEST_CASE( my_test )
{ some code }
will be detected as a syntax error by eclipse. It is really annoying having all these error messages in the IDE. Since after the first line nearly every line in the some code block is marked as having syntax errors as well.
So here is what i tried already:
I added `/usr/include/boost/` to the GNU C++ path options. (properties->C/C++ General->Path and Symbols->Path). This works normally for other external libs that are included by FindPkgConfig in the cmake file. So that the auto completion in eclipse can find the correct classes and function names.
Same way included `/usr/include/boost/test/` directly.
Adding `/usr/lib/libboost_unit_test_framework.so.1.40.0` to the Libraries list.
Adding `/usr/lib` to the Library Paths.
So anyone has a hint how to teach eclipse that the syntax of the boost Macros is correct??
Update:
I forgot:
System is Linux and Eclipse Version is 3.6.1, CDT Version is:
Version: 1.0.0.201009141542
Build id: 201009141542
I don't have a solution but maybe a hint.
I had a similar setup and it worked perfectly until...
the only relevant change I remember is that I changed the name of a test suite.
So (probably) after that, the syntax highlighting went crazy.
I tried indexing and refreshing but it didn't help.
I can't even see the macro expansion because the syntax error prevents it from popping up.
My guess is — still — some indexing issue, because it worked before and I didn't change any include paths. It compiles without problems, but it's urinating these yellow syntax error markers all over the document, which is really, really annoying.
However, it's probably not a path issue because it worked for me before.
I just did this myself using Eclipse Helios, and it does indeed work for me...
Shouldnt you add /usr/include and not /usr/include/boost, since boost is part of the include path used in your program?
For example <boost/unit_test.hpp> is simply <unit_test.hpp> if you include the boost folder aswell..
This is what I have added under GNU c++ include directories:
/usr/local/include //this is where I store the boost folder
/usr/include/c++/4.5.2 //This was needed since not even <map>, <vector> etc would resolve in eclipse.
Intellisense and autocompletion for C++ are pretty much impossible to get right in all cases. If the many macros used in Boost.Test confuse Eclipse, then perhaps you should find a cleaner unit test library. I can recommend Catch, which has a cleaner and friendlier syntax, is header-only so it's much easier to set up, and doesn't rely on macros. It is under active development by another SO user.
I had this problem as well (but on a Mac system). Once I added the boost path to GNU C++ path options, I restarted my operating system and Eclipse doesn't tag BOOST_AUTO_TEST_SUITE as an error any more.

Code::Blocks cannot find vector header

EDIT: I have solved this problem, with Tomalak's help. It appears that I mistakenly uninstalled libstdc++6-4.4-dev_4.4.3 when I was making space to install code::blocks into, thus removing the STL headers. Code::Blocks now works perfectly fine.
Hey everyone, I'm back yet again to bug you.
I have recently installed Code::Blocks in order to follow along with a SDL tutorial, mainly to make it easier with the file creation process (i.e. not having to deal with makefiles for the time being)
I have been compiling/running the examples (so far) just fine, but I've now hit a snag.
On the tutorial for entities, the header file includes <vector> - yet code::blocks is stating it cannot find said header file. It's a .h header file, but it's recognizing it as C++ (I think, judging from the project options) - all my headers are .h, all my sources are .cpp...
I have searched Google for a solution, and many people state that this error occurs when they try to use in a .c file by mistake. This is not the case, unless Code::Blocks is recognizing my .h as a C-header.
In case you're wondering, I am running Lucid Puppy Linux 5.2 (aka LuPu), a Ubuntu derivative. (Installed Code::Blocks from the Ubuntu repositories)
In advance, thank you very much for the help.
As it turns out, it was not a Code::Blocks issue - I had mistakenly un-installed the libstdc++6-4.4-dev_4.4.3 package.
So, if any of you all get this same problem make sure the libstdc++ development files are installed! LOL

Code::Blocks not being able to find standard library headers?

I recently switched from Bloodshed to Code::Blocks. I wrote a simple input/output program to get a feel for it, and when I tried to compile it I got errors for all of the headers I had included, saying that there was no such directory.
I took a look at the file and saw that the file was saved as a C file rather than a C++ file, how do I change this? (I know this is why because the C++ files I transferred over from Bloodshed work fine.)
As #nagul said in the comments, saving the file as <file>.cpp instead of <file> fixed the no such directory error when compiling.