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).
Related
Given the file tree:
DLL1
└───source
├───File1.h
└───SameHeader.h
DLL2
└───source
├───File2.h
└───SameHeader.h
File1 includes SameHeader.h, which is fine.
File2 includes File1 which won't compile, because the #include "SameHeader.h" now points to the DLL2/source/SameHeader.h. Is there a way to ensure File1 uses the file which in the same dll?
Sure - you can put the file SameHeader.h in a separate folder (not the same as the source files) and then specify that folder in your list of include paths to search (in the project options, or in the compiler command switches).
You will, of course, need to delete the file SameHeader.h from each of the source project directories, or that will be used in preference to the one in the separate folder.
So, using your "file tree" diagram, I would suggest this:
DLL1
└───source
├───File1.h
DLL2
└───source
├───File2.h
Include
└───SameHeader.h
You could then add ../Include to your compiler's include file search path. How to do this depends on your compiler and/or environment, but it will be something along the lines of a /I"..\_Include" switch in MSVC or (probably) -I"../_Include" with clang. This is what I do in multi-project solutions, for all header files that will be used by more than one project.
However, if you actually need two (different) SameHeader.h files, then you should perhaps specify the full path name (or, at least, a qualified path) in the #include "SameHeader.h" line in File1 - something like: #include "../../DLL1/source/SameHeader.h" (depending on the exact layout of your files & folders).
I'm very new in Arduino, so maybe my question will be stupid but I have to ask it!
I made a mqtt client for my nodeMcu chip, and I have this error
/Users/mikevorisis/Downloads/pubsubclient-master/examples/mqtt_esp8266/mqtt_esp8266.ino:27:26:
fatal error: PubSubClient.h: No such file or directory #include
I downloaded the original project from github and I tried to compile the example it has in examples/mqtt_esp8266 but again I have the same problem.
I also tried to put the PubSubClient.h in the same folder but again I have the same problem.
Any ideas?
Thanks in advance.
The file you have downloaded and included in your project is probably not actually a header file. You probably copied the contents of it from github and pasted it into a text document which you saved as a text file with the extension ".h".
It now has the extension "filename.h.txt". The name and extension need to be only "filename.h". Use save as, and select "all files" when saving, and name it "filename.h". Be sure to retype the filename, or it can be auto-filled with the already existing "filename.h.txt" (even if you don's see it!).
If the file now has the right extension, put it in the same folder as your source code file. You can see which directory your source file is in by going to "save as" in your IDE.
A problem you might run into after this is missing definitions. You see, when you use libraries in the form of header files, each header file must usually (in this case, yes) be accompanied by a .cpp file (not necessarily with the same name). The reason for this is that the header file contains declarations, and the cpp file the definitions for said declarations. In other words, the header file is an overview of the facilities available in the library, and the cpp file actually implements the guts of it.
Edit: The example you are trying to run also has #include <ESP8266WiFi.h>, a file that is not available in the github repository that you referred to. I assume that this is a library for a WiFi module or such that you can get elsewhere (manufacturer, other git's or maybe it comes with the Arduino IDE?). In other words, you also need to add its header and (probably) .cpp file to your source directory.
Anyone know of any sources for a LLVMHeaderGuardCheck like clang-tidy check that formats the expected include guards based on configurable information like the include path(s) given on the command line?
More details...
The LLVMHeaderGuardCheck header guard check expects header file include guard macro names that are all uppercase letters of the path after include/ with the / replaced by _ and a suffix like .h or .hpp replaced with _H. That works as a fine header guard check so long as your header files are all under a common root that has include/ in its path.
What I'm looking instead for is a check which works based on the path given in a -I$path command line argument. So if given an include file path like -I/usr/local/xyz an include file named /usr/local/xyz/common/foo.h needs to have include guard of XYZ_COMMON_FOO_H.
I wrote some code to work for the meantime but my commit only uses the path as an option from the .clang-tidy configuration file. While this suffices, it's not as flexible as a solution that can also use the command line info.
So I'm wondering what else is out there as open source checks for clang-tidy for header file include guard naming checks as I haven't had any luck finding anything via the web searching I've done to-date.
I have a MFC control that has an idl file "Test.idl" where I define some enum.
However, if I want to use this enum in the MFC control, I have to include the auto generated header "Testidl.h" that is created by midl.
Ok, but I have a periodic problem. If the autogenerated file "Testidl.h" is not existing, I cannot include that file, thus, cannot compile my control and, thus, cannot create the autogenerated file.
The problem is (I guess), hat the MIDL step is done AFTER C++ build.
Am I correct and can I solve this behaviour somehow?
As long as the IDL file is included in the project's Source Files list the MIDL step should be done first and generate the associated .h file.
how to include certain header files by default so that i don't have to type them in every programs:
In dev c++ and code::blocks
Make a global header file that in turn includes whatever files you need in every project, and then you only have to include that single file.
However I would recommend against it, unless all your different project are very similar. Different projects have different needs and also need different header files.
You could issue a compiler directive in your project file or make script to do "per project" includes, but in general I would avoid that.
Source code should be as clear as possible to any reader just by its content. Whenever I have source code that dramatically changes its semantics, eg. by headers that are unknown to me, this can be quite confusing.
On top of that, if you "inject" those headers for certain compilation units that don't need them, that will negatively impact compile time.
As a substitution, what about introducing a common.h/hpp header that includes those certain header files? You can then include your common header in all files that need them and change this common set of headers for all depending files at once. It also opens the door to use precompiled header files, which may be worth a look for you.
From GCC documentation (AFAIK GCC is default compiler used by the development environment you are citing)
-include file
Process file as if #include "file" appeared as the first line of the primary source file. However, the first directory searched for
file is the preprocessor's working directory instead of the directory
containing the main source file. If not found there, it is searched
for in the remainder of the #include "..." search chain as normal.
If multiple -include options are given, the files are included in the order they appear on the command line.
-imacros file
Exactly like -include, except that any output produced by scanning file is thrown away. Macros it defines remain defined. This allows you
to acquire all the macros from a header without also processing its
declarations.
All files specified by -imacros are processed before all files specified by -include.
But it is usually a bad idea to use these.
Dev c++ works with MingW compiler, which is gcc compiler for Windows. Gcc supports precompiled headers, so you can try that. Precompiled headers are header files that you want compiled and added to every object file in a project. Try searching for that in Google for some information.
Code::blocks supports them too, when used with gcc, even better, so there it may even be easier.
If your editor of choice supports macros, make one that adds your preferred set of include files. Once made, all you have to do is invoke your macro to save yourself the repetitive typing and you're golden.
Hope this helps.