Visual Studio test project not finding main project - c++

I created an empty C++ project in Visual Studio and added some code. Then following Microsoft's instructions I created a new Google Test project, selected "Add to solution" with my first project, and then in the next screen I selected the first project as the project under test.
I can get the main project to run, and I can get a test to run if it doesn't use my code. But I can't use my code in the tests.
Here is the current code that's trying to make its way to the test. You can also see in the explorer that the main project is indeed referenced in the test project.
But that is basically all I've done. I haven't played with any other settings anywhere at all. So don't assume I did something, or know something. Pretty n00by in these situations.
Thanks.
The error:
With regards to this being marked as a duplicate: while the question you've linked to does appear to make it clear that I have some sort of linker problem, there is so much information there -- over a dozen common causes -- that it doesn't actually help me answer my question, or at least not much more than telling me to, say, "read these 10 chapters of this C++ textbook". I would appreciate a response that points as close to "exactly" what I'm doing wrong as reasonably possible.

Related

Why doesn't my visual studio build properly?

Okey, I am REALLY having problems with the Visual Studio 2012, and looked all over for a solution, with no result.
So the problem is this... Usually the play button, starts building and debugging in the end running the program. And each time a source file is updated, it should do that again. Well, for me it does not. Every time I write something new in a file, I need to REBUILD the program and then hit play, when before, just hitting the F5 button would do the trick.
The thing is, I have checked, all probable causes that were diagnosed over the internet, so no it's not related to the settings in visual studio, and no, it's not a timestamp issue.
The oddest thing though, is that sometimes, some of the files inside the project look excluded( they have a tiny red circle on them and I have to select and reinclude them). I do not understand why that happens, they were not implemented by me, they are just some "dependency" files on which other classes that I am ussing are built.
Furthermore, the problem of not updating the program. At the moment I have 2 classes. If I write code inside one of them, F5 will work properly and run with the expected modified result. On the other class though, nothing will happen. F5 will find no errors, but it will run without any modification, altough there was code added in one of the classes.
This is really driving me crazy, and I really need a conclusive answer. Why are the dependencies file being involuntarely excluded? Why does visual Build correctly changes from one file but not from another?
You made your visual studio to do it (i.e to launch code with errors).
By default when there is an error you get this popup:
Now if you tick the checkbox - VS will not bother asking you again;
even when errors occur - it will just execute last executable that it has.
To revert this change - go to: Tools > Options > Project & Solutions > Build & Run:
Change this setting to *Prompt to Launch and you are done.

Why a local .NET assembly appears broken in the reference list (almost) each time I build?

I'm porting a C++ .NET solution to MSVS 2012. I have a particular problem with an assembly built localy. In the "Common Properties" section, in the reference list, the assembly was added ("Add New Reference" by browsing). But often (not always), the link seems to be broken (with a vertical red bar on the small icon at left beside the assembly name) and the project won't compile.
I remove the reference then re-add it (the same one!) and it build. I would appreciate any hint about how to fix this problem because we have a lot of projects in the solution.
You have encountered this problem?
Feel free to ask for more info...
Thanks.
Are you adding an assembly which is built by that project or a different one?
If so then the problem is that it might not be there or might be occupied (held open exclusively by another process like VS2010).
If it is in the same project dont add it by browsing add it from the projects tab.
If not then try to copy the assembly to a different location and then point to it.
In general pointing to different assemblies which are in another project is a very bad idea.
A common reason for this is a referenced assembly that the added assembly needs. And your project has a .NET framework target that doesn't include that assembly. The IDE gets screwy when that happens. Everything looks normal, IntelliSense works for example. Until you compile and the discrepancy is discovered. There is a warning about it in the Error List window but it is easily missed by the usual raft of errors that excluded assembly generates.
System.Web is a common one that isn't available, for example. Change the Framework Target setting from the Client profile to the full version to fix the problem and try again.
Here is what solved my problem:
When adding a reference (at least in VS2012), you have 4 choices at your left:
Assemblies <- GOOD!
COM
Solution
Browse <- BAD
By reflex, I chose Browse because I wanted to browse for the DLL in my folders. I found it (the DLL) then I wrongly beleived that it was correct.
What I had to do was to choose Assemblies. Then I could select Browse at the bottom of the dialog to browse my folders.
At current time I don't know what the first Browse is useful for. Anyway, I hope my mistake will help someone!
And many thanks to those who gave me some hints!

Visual C++ Build / Debugging Issue

I'm having a weird problem with Visual Studio. Whenever I change my code and build, even though I get the notification that the built was successful (and if any, it also shows errors in code and doesn't build) the executable is actually the previous build. This is getting really annoying and frustrating.
If I put a breakpoint on the new lines, the breakpoint gets disabled and it says
The breakpoint will not currently be hit. No executable code is
associated with this line. Possible causes include: preprocessor
directive or compiler/linker optimization
If I put a breakpoint on old lines of code, it stops processing but shows me this message
The source is different from when the module was built. Would you like
the debugger to use it anyway?
I never had this problem before and the source code in on my laptop's hard drive. It saves right away. The only way to get around this to Clean the entire solution manually every time, instead of basically pressing F5.
Thanks everyone for their suggestions. My mistake was that I defined the classes inside .cpp files, this somehow caused the linker to do weird (caching probably) stuff and link the old objects. I renamed the file to .h and everything's working as expected.
Perhaps your code is not built, or is built in a way you don't expect.
You might check by inserting a #error foobar preprocessor directive somewhere. If no error shows when building, you know you are in trouble!
But I never used Visual Studio (I'm only using Linux) so I cannot help more.
It might be that you have set main project some other project and building that.
make your project that you want to work on as "Main Project " by set main project available in menu bar.
I think you are using source files from another project (ex: if you are using a dll say, my.dll (which was built using some source files say, mycpp.cpp ); in your current project).
When you debugged into the file (mycpp.cpp), maybe you modified it.
Hence you need to rebuild the dll (my.dll) first in the project in which you created my.dll .
Or
Maybe you have opened a instance of mycpp.cpp in a window & debugging in another window.
you should rebuild the dll.
If you are not using files from another project, then I cant guess the cause...but still I would recommend using rebuild rather than clean & build.
please clarify your Question a bit.
#David expecting a reply from you...
I was looking for an answer to this issue since I was also stuck with it. A colleague of mine just gave me a solution that works. Yes, it seems really stupid, but it did the trick for me.
Our solution has many projects. He told me to select the project that I wish to break into and set it as the startup project (right-click on the project name and pick "Set as startup project"). I was desperate, so I tried. To my amazement, it works.
Since I have this window opened, I thought I'd share it in case someone else is stuck with the problem.
I faced the same problem. But reason was not as yours.
Then I just restarted the visual studio and it ran as expected.

Using .dlls in my projects

Hello,
Specs: VS 2010 C++ professional edition.
I have a project with some statistical functions that I want to test.
So I wrote a simple test console application which I added to the solution of the project with functions that I want to test.
Here is the detailed layout of my project:
Project BASE, contains classes with functions that are used in my statistical application called ROC. And then there is roc_test, simple console application that I want to use for testing of some functions in ROC application. Now, ROC is linked to BASE and roc_test has ROC as referenced project. My problem is that when I try to compile my test project roc_test, the compiler throws an error saying that my roc_test project is missing a .dll file that belongs to project BASE. roc_test however, is not directly linked to BASE. I don't understand why it throws such a message and how I can fix it. For the sake of clarity let me try to show the relationship in a different way.
roc_test function calls rocfit(..) function, which is part of ROC.h. ROC.h using functions that are written in DoubleMatrix.h, which is part of a BASE project.
I hope I am being clear.
P.S. There is no point in showing the code as the problem is not in the code but in the linker settings.
Thanks for any help.
EDIT: My question is how do i get rid of the error? Do I also need to link my test project to the BASE? It's just doesn't make sense that I have to do it. It should be enough to link it to ROC. Am I right?
If it's not included in the same directory as the console app (or in the path), then you'll need to include BASE as the runtime can't resolve the dependancy on BASE by ROC.
Edit: Simply referencing ROC isn't enough; although there may be some build option that builds ROC and BASE and then links them into a single DLL; that could be worth investigating.
Also, instead of using a Console application, you might find it better in the long run at using unit tests.
This msdn article explains how to use vs2010 test projects with C++:
http://msdn.microsoft.com/en-us/library/ms243171.aspx

VS2010SP1: Project always out of date when debugging

I experienced this problem in VS2010 before, and solved it looking at this SO question. However, now that I upgraded my VS to SP1, it appeared again. I tried to solve it the same way, enabling C++ projects logging and using DebugView. But I can't get to see any output in DebugView, no matter what I do. I also tried raising the Build output verbosity (Tools->Options->Projects and Solutions->Build And Run), but couldn't find any clue.
As in the original problem, the projects reported as out of date are always unmanaged C++ projects. The solution has C#, VB.NET, C++/CLI and C++ projects. What I'm trying to run is a VB.NET exe which uses some C++ projects through C++/CLI wrappers.
Any hint on how to troubleshoot this?
UPDATE: Solved it with a clean checkout. However, it's a shame that there is no longer a way to troubleshoot this kind of errors...
Is it possible you were testing with the date in the future and saved a source file in the future? While clean/rebuild all should fix this, VS seems to go batty and stay there until I resave the file in the present.
Another last-ditch thing that sometimes solves these problems that works 'like a reboot' if you have just the source-code in version control: Check everything in, close VS and anything using files in your project, move all your project folders to a backup folder, and do a force-get latest version of each. Sometimes 'clean project' doesn't cut it.
If that doesn't work and you can't find a missing .h ... You can always fire up Process Monitor, set a filter, and dig in there.
Admittely all just stabs in the dark. Hope one hits the burgler! ;-)
After a compiler upgrade you should do a rebuild-all, if you haven't done that already.
For native C++ projects you can get "project out of date", but still nothing to build, if you have some include files in your project that doesn't actually exits. Like if you have deleted some unused .h files, but they are still part of the project.