Managed C++ - ignored Header file - header-files

So I’ve got a HEADER(.h) and a SOURCE(.cpp) file in a Managed C++ VS2010 solution.
My solution builds successfully even though I added garbage to the header.
public:
someConstructor(); // assume the syntax is good here
asdf // garbage
Why I did this
My original problem was that I couldn't update my CPP file to add a new constructor. When I added a new constructor to my CPP file, my solution failed to build due to a non-existent overridden member function, i.e. my new constructor. I added garbage to the HEADER file to make sure that VS2010 was actually reading my HEADER file. Obviously it was not.
How can I make sure that VS2010 looks at my HEADER file? It seems to be looking at another HEADER file...
Thanks

If you select the file(s) in question and open up the properties window (View->Properties Window) you can see if your project is looking at the correct file or not. Additionally, if the file is not being included in the build (even though it's in the solution), you can set Include in Project to true.
Note that I'm assuming you're using MSBuild. If you're using some other build system, there may be a different procedure for ensuring the build is using the correct header file.

Related

Visual C++ build produces an empty .obj while manual compile succeeds

I have a Visual C++ Professional 2019 Version 16.11.8 solution with 4 projects, one of them a GoogleTest project, others are libraries. It worked long just fine, but today it started complaining about 4 missing methods in a class. Those are in a separate .cpp file.
During build, it compiles this file, but the result is only 70 kB (should be 500kB) with no methods in it (examined with objdump). Unresolved references. When I compile the specific file using Ctrl-F7, then issue the build, everything is OK.
I've tried clean all, rebuild all, restart computer, delete all the Debug directories together with .vs, but nothing.
I haven't customized anything on that ,cpp file, at least not on purpose.
What can I do? Thanks in advance.
The cause was some misplaced header and source files. Header in source directory or the opposite way, I don't remember. Making order healed the project. Apparently I wans't careful enough during adding new files.
Make sure, that
Each header file gets in the project include directory.
Each header file is added via the new header template, and gets .h suffix.
Each source file gets in the project src directory.
Each source file is added via the new cpp file template, and gets .cpp suffix.

No such file or directory in Arduino Project

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.

How can I use enum written in idl in same project (MFC Control)

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.

changing extension to .mm can't find the header anymore

I am working on a Iphone Application. I need to use C++ code inside MainViewController class. For that I renamed the MainViewController.m to MainViewController.mm in order to accept C++ code.
However after doing that it looks like it lost the link with the MainViewController.h file. I can no longer synthesize properties declared in the .h file and can no longer create action in the header file. It can't find the .mm file. and if I try to "Jump to definition" it says Symbol not found
How can I fix that. Thank you for any help
Close and reopen the Xcode project
if that fails, Build and remove any errors which may have been introduced as a result of changing the type to compile as.
if that fails, Clean All and rebuild.
if that fails, got to the Organizer, choose "Projects" > *YOUR_PROJECT* and Delete its Derived Data.

About stdafx.h missing in my compiler(mingw32 on windows)

I just have a quick question. I've noticed that I don't have stdafx.h in my compiler(mingw32 on windows)
Am I supposed to have it? Or maybe is there a way to get around it?
Thanks for reading
EDIT: ok here is my current build log once I took out ALL of the includes of stdafx.h
http://pastebin.com/bczLr8xY
Read this wikipedia article. The paragraph I linked and the paragraph below it (mingw32 uses GCC).
http://en.wikipedia.org/wiki/Precompiled_header#stdafx.h
Since stdafx.h contains the most common headers I would remove every instance of #include stdafx.h and try to compile. If you get compile errors that a certain function is missing, add the appropriate header. Rinse and repeat.
No. Stdafx.h is created with MSVC++. It usually contains most common headers files. And Stdafx.h is included in every .cpp file in the beginning. It's precompiled header (if you've chosen so in the settings) created by MSVC++.
To all:
Using the pre compiled header file stdafx.h in the visual C++ always creates one or the other problem n case u have created a "Windows Console App" from Visual C++.
The Solution to it is that, just create "Empty Project", rather than the pre-compiled windows console application. After creating the Empty project, create the source File. Write the business logic and add all the required resource and header files. Keep the external dependency files in the same directory in which your source code is: e.g., C:\Users\John\Documents\Visual Studio 2010\Projects\xyz.cpp\xyz.cpp.
Finally add the source file to the global scope, that is add it to the "Empty Project" created already. It can be done by Clicking "File" on Visual Studio prompt and select the option of adding the source file to the project.
Thanks and Regards:
Rouf Khan