eclipse - how to treat file extension as C-file - eclipse-cdt

How do I force Eclipse to treat a file-type as a C/C++ file so it'll index them?
My makefiles create .pp files for pre-processor output and I want to view those as C/C++ files.

You can define a mapping from the .pp extension to the C++ Source File file type in Preferences | C/C++ | File Types.

Related

Xcode, Objective-C Project: not compiling C++ file

I have C++ file header (interface.hpp) in my Objective-C project.
When I use it I get a compiler error on the line: #include <map>
map file not found
and it's the same for #include <string>
string file not found
It seems to me that, despite the file extension hpp, Xcode is compiling it as C header, rather than C++ header.
Any suggestion?
The extension of the header is irrelevant. What is important is the extension of the file that includes that header. If you want to include a C++ header in Objective-C code, you need to change the extension of the Objective-C file to .mm. This indicates that the file is an Objective-C++ source file (a different language, in fact, so be careful that you know what you're doing). Headers that are included in a .mm file will be parsed as Objective-C++, and so then your C++ constructs should work.
You have to change the file extension to .mm in order to use it.
If changing the extension to .mm is not working try adding -l"c++" to Other Linker Flags in build settings.

Object file location of Visual Studio C++ project

In our project, the directory structure of our source code files are linked with our namespaces. E.g., a class Util which belongs to the namespace MyNamespace_A would be implemented in the file
.../MyNamespace_A/Util.cpp
Now, the namespace 'OtherNamespace::SubNamespace' should also have a Util class. It should be implemented in the file
.../OtherNamespace/SubNamespace/Util.cpp
Without specifying an explicit object file (Properties of the .cpp file -> C/C++ -> Output Files -> Object File Name) this will lead to problems because two object files will have the same name and by default, they are stored in the same directory (which is '$(IntDir)').
Is there an automatic mechanism which lets me specify that the directory structure of the output files shall be the same as the structure of the source code directories?
Can I solve the problem in a different way than specifying the object file name for each of my source code files?
Right-click on project and go to...
Properties -> C/C++ -> Output Files -> Output File Name
Then enter...
$(IntDir)/%(RelativeDir)/
This will place every .obj file into a subfolder as in the source files.

Change IDL generated header file

I'm working on a legacy c++ COM project that I'm moving over to Visual Studio 2010. In the IDL file for this project, I have to reference an ODL file from another c++ project. My problem is that the other project generates its header file as $(filename)_h.h. When my IDL file generates its header file, it generates the ODL filename as $filename.h, and it can't reference the correct file.
In other words, in my IDL file ("MyIDLFile.idl") I have a statement like
import "MyODLFile.odl"
which in the generated file ("MyIDLFile.h") becomes
include "MyODLFile.h"
when I need it to generate
include "MyODLFile_h.h"
How do I specify the file name I want the IDL to generate in an import statement?
I'm not sure what you mean about the import statement, but what you're looking for might be found under the project's Properties. Goto the properties window (Alt-F7) and under "Configuration Properties/MIDL/Output", you'll have the opportunity to declare the Header File which you want it to create. Since your project is legacy, it may be easier to just remove the "_h" from the header file name (e.g. $(ProjectName).h instead of $(ProjectName)_h.h). See http://support.microsoft.com/kb/321274 for a lil more info.
This is a common problem to solve when dealing with IDL files. The good thing is that there are a few ways to solve this problem:
The use MIDL compiler's options to change the generated output
Layer your component such that conflicting files are compiled in different paths. You can also control how the generated files are published. Then, code that needs to include it can control where the files are included from.
Your ultimate solution may use a little of #1 and #2.
The MIDL compiler has several options to modify the names of output files, or excluding output files.
Directly specifying names:
-OUTPUT FILE NAMES-
/cstub filename Specify client stub file name
/dlldata filename Specify dlldata file name
/h filename Specify header file name
/header filename Specify header file name
/iid filename Specify interface UUID file name
/proxy filename Specify proxy file name
/sstub filename Specify server stub file name
/tlb filename Specify type library file name
Skipping output files:
-OUTPUT FILE GENERATION-
/client none Do not generate client files
/server none Generate no server files
/notlb Don't generate the tlb file
I personally have used the /prefix option to avoid name collisions of headers in the past.
/no_default_epv Do not generate a default entry-point vector
/prefix client str Add "str" prefix to client-side entry points
/prefix server str Add "str" prefix to server-side manager routines
/prefix switch str Add "str" prefix to switch routine prototypes
/prefix all str Add "str" prefix to all routines
This is an example of that:
/prefix client HIDE_
The interface with method foo would be renamed to HIDE_foo in the header.
The other strategy that works is related to how you layer your directories, build order, and publish files, and use include paths, and order the actual includes. I am only used to using sources with dir files, and build.exe, so I can't give any advice how that works with VS.
This seems to be a common problem, I haven't been able to find any good solution but one workaround is to append a '_i" to your idl files, e.g. EquipmentConstants_i.idl
Microsoft does reference a /header compile switch but I haven't been able to get that to work (midl /header switch).

Compiling a project (VS 2008) with the /p argument (preprocess to a file) doesn't compile

I have a project in C++ that I would like to view the preprocessor output to see what some #defines and macros would look like. I tried the /p switch to turn on the preprocess to a file option to the compiler (it turns off full compilation and only runs the preprocessor) but my project now refuses to compile and shows a long list of errors starting with:
"Cannot open include file: 'stdafx.h': No such file or directory".
The project compiles fine without the /p argument, of course. Any suggestions?
If you run cl.exe on its own then you would need to supply all the same parameters as the IDE does when building, otherwise it can't find all the include paths and preprocessor macros. However, there is another way to do this. In the project file, select the .cpp file you want, and choose Properties > C++ > Preprocessor > Generate preprocessor file. Then compile the .cpp file.
This will generate the preprocessed file (file.i I think) in the output directory. It's a shame there isn't an easier way of just selecting a file and hitting 'preprocess' but this could probably be done quite easily with a VisualStudio macro. Don't forget to set the option back afterwards.
Are all the other options (like /I) still the same when you compile with /p? It sounds like it's not picking up your header files. Alternately because it's trying to pre-process all the includes it's no longer generating the stdafx.h precompiled header - you could try just including all the needed headers directly instead of that.

Make Eclipse treat .h file as C++?

All of our C++ headers use a .h extension. Eclipse thinks these are C headers and flags them with lots of syntax errors on things like classes and namespaces.
I've tried to change the file type association from:
Preferences > C/C++ > File types
but it's "locked".
Interestingly, "*.h" is associated with both C and C++ headers, but it seems to be using C. How can I get Eclipse to treat .h files as C++?
Try creating a new project and specify your source area as the location. However, be sure you select C++ project (I usually use the makefile option). This is all you should have to do in order to make the parser recognize C++ syntax.